wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<person name='result'/>
<person name="result"/>
Double quotes.
XML
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let mut data=80; let ref1=&mut data; let r2=&mut data;
let mut data=80; {{ let ref1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
if (b = 33)
if (b == 33)
Use ==.
R
{{'id':'data'}}
{{"id":"data"}}
Use double quotes.
JSON
val item = 'result'
val item = "result"
Double quotes.
Kotlin
SELECT * FROM items WHRE email=54;
SELECT * FROM items WHERE email=54;
Fix WHERE.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if ($z = 60)
if ($z == 60)
Use ==.
Perl
const a;
const a = 70;
Initialize const.
JavaScript
$items[28]
if ($items.Count -gt 28) {{ $items[28] }}
Check bounds.
PowerShell
String name = 'info';
String name = 'info';
Correct.
Dart
class Product def method end end
class Product def method end end
Correct.
Ruby
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
local result = 72
local result = 72
Correct.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
UPDATE products SET age='output' WHERE role=67
UPDATE products SET age='output' WHERE role=67;
Add semicolon.
SQL
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$arr[70] = 5;
if (isset($arr[70])) $arr[70] = 5;
Check existence.
PHP
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
def test(bar): return bar + 1
def test(bar): return bar + 1
Correct.
Python
if b = 34
if b == 34
Use ==.
Go
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let z: number = 'result';
let z: string = 'result';
Fix type.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
def baz(): print('info')
def baz(): print('info')
Indent function body.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
cin >> val;
int val; cin >> val;
Declare variable.
C++
let y: Int = 'data'
let y: String = 'data'
Fix type.
Swift
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
var x = 94;
var x = 94;
Correct.
Dart
let msg = String::from("result"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("result"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
yield index
yield index
Correct yield.
Python
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(72);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(72);
Correct.
Node.js
var x int
var x int
Correct.
Go
int items[78]; items[78]=5;
int items[78]; if(78<78){{}} else items[78]=5;
Bounds check.
C++
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
let num = 47;
let num = 47;
Correct.
JavaScript
object Item {{ def main(args: Array[String]) = println("message") }}
object Item {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
[x*x for x in values if x > 26]
[x*x for x in values if x > 26]
Correct list comprehension.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
echo 'hello'
echo 'hello';
Add semicolon.
PHP
val num = 24; num = 75
var num = 24; num = 75
Use var for reassignment.
Scala
items[30]
if (length(items) >= 30) items[30]
Check length.
R
String val = 'output';
String val = "output";
Double quotes.
Java
status: value name: data,
status: value name: data
Remove comma.
YAML
DELETE FROM products WHERE name=21
DELETE FROM products WHERE name=21;
Add semicolon.
SQL
<br></br>
<br>
Self-closing.
HTML
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
if num = 4:
if num == 4:
Use == for comparison.
Python
'45' + 17
45 + 17
Avoid string coercion.
JavaScript
if (result = 55) {}
if (result == 55) {}
Use ==.
Dart
else print('data')
else: print('data')
Colon after else.
Python
h1 {{ font-size:12px color:#fff; }}
h1 {{ font-size:12px; color:#fff; }}
Add semicolon.
CSS
assert c > 20
assert c > 20
Correct.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
def render puts 'data' end
def render puts 'data' end
Correct.
Ruby
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
var bar int = 'test'
var bar string = 'test'
Type mismatch.
Go
[22, 82, 74
[22, 82, 74]
Close bracket.
Python
class User {{ int y; }} obj.y=5;
class User {{ public int y; }} obj.y=5;
Make field public.
Java
fn handle() -> i32 {{ 14 }}
fn handle() -> i32 {{ 14 }}
Correct.
Rust
let z: number | null = null; z.toFixed(47);
let z: number | null = null; if(z!==null) z.toFixed(47);
Null check.
TypeScript
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
if y = 58
if y == 58
Use ==.
Ruby
switch(data){{ case 12: break; }}
switch(data){{ case 12: break; default: break; }}
Add default case.
Java
if data > 21 print('test')
if data > 21: print('test')
Colon missing after if.
Python
if ($foo = 15) {{}}
if ($foo -eq 15) {{}}
Use -eq.
PowerShell
<person age=76>
<person age="76">
Quote attribute.
XML
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
int y = 'hello';
String y = 'hello';
Type mismatch.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
process
process()
Add parentheses.
Kotlin
function process() {{ return {{key:'result'}} }}
function process() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
if x > 65 puts 'output'
if x > 65 puts 'output' end
Add 'end'.
Ruby
sys.sqrt(36)
import sys sys.sqrt(36)
Import module first.
Python
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if result = 1 then print('result') end
if result == 1 then print('result') end
Use ==.
Lua
disp('test')
disp('test')
Correct.
MATLAB
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<hr></hr>
<hr>
Self-closing.
HTML