wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def baz(index): return index + 1
def baz(index): return index + 1
Correct.
Python
<user><desc>world</desc><desc>44</desc></user
<user><desc>world</desc><desc>44</desc></user>
Add closing >.
XML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
int a = 'world';
String a = 'world';
Type mismatch.
Dart
z == '92'
z === 92
Use strict equality.
JavaScript
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
for i=1,31 do print(i) end
for i=1,31 do print(i) end
Correct.
Lua
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for (z in arr)
for (z of arr)
for...in iterates keys.
JavaScript
name: world age: 34
name: world age: 34
Correct.
YAML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
while b > 9 b -= 1
while b > 9: b -= 1
Colon missing after while.
Python
if (c = 93) {{}}
if (c == 93) {{}}
Use ==.
Kotlin
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
[x*x for x in data if x > 8]
[x*x for x in data if x > 8]
Correct list comprehension.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
UPDATE products SET status='hello' WHERE status=96
UPDATE products SET status='hello' WHERE status=96;
Add semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
var result int = 'test'
var result string = 'test'
Type mismatch.
Go
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
if (val = 81)
if (val == 81)
Use ==.
R
if data > 14 puts 'info'
if data > 14 puts 'info' end
Add 'end'.
Ruby
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
String name = 'world';
String name = 'world';
Correct.
Dart
var x int
var x int
Correct.
Go
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
my @arr = (24,50,19);
my @arr = (24,50,19);
Correct.
Perl
foo
foo()
Add parentheses.
Kotlin
print 'info'
print('info')
print needs parentheses.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
for z in range(68) print(z)
for z in range(68): print(z)
Colon after for.
Python
{{'name':49, 'id' 17}}
{{'name':49, 'id':17}}
Colon missing.
Python
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
if c = 77
if c == 77
Use ==.
Ruby
print 'hello'
print 'hello';
Add semicolon.
Perl
function bar(): void {{ return 10; }}
function bar(): number {{ return 10; }}
Return type mismatch.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if c = 82
if c == 82
Use ==.
Go
function render(count:string){{return count;}} render(70);
function render(count:string){{return count;}} render('test');
Pass correct type.
TypeScript
fn compute() -> i32 {{ 94 }}
fn compute() -> i32 {{ 94 }}
Correct.
Rust
x := 87
x := 87
Correct.
Go
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
INSERT INTO orders VALUES ('output',93)
INSERT INTO orders (age, status) VALUES ('output',93);
Specify columns.
SQL
String count = 'info';
String count = "info";
Double quotes.
Java
<br></br>
<br>
Self-closing.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (x = 53) {}
if (x == 53) {}
Use ==.
Dart
[53, 78, 52
[53, 78, 52]
Close bracket.
Ruby
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
class Order {{ int val; }};
class Order {{ public: int val; }};
Make public.
C++
if (bar = 10)
if (bar == 10)
Use ==.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
DELETE FROM users WHERE id=51
DELETE FROM users WHERE id=51;
Add semicolon.
SQL
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
def compute puts 'info' end
def compute puts 'info' end
Correct.
Ruby
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
let item: i32 = "data";
let item: &str = "data";
Type mismatch.
Rust
let str = String::from("value"); let r=&str; str.push_str("!");
let mut str = String::from("value"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
h1 {{ font-size:100px color:#333; }}
h1 {{ font-size:100px; color:#333; }}
Add semicolon.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
'81' + 1
81 + 1
Avoid string coercion.
JavaScript
["value", 59]
["value", 59]
Correct.
JSON
local item = 67
local item = 67
Correct.
Lua
// comment
/* comment */
Use /* */.
CSS
if (z = 22)
if (z == 22)
Use ==.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int items[67]; items[67]=5;
int items[67]; if(67<67){{}} else items[67]=5;
Bounds check.
C++
int[] items = new int[71]; items[71] = 5;
int[] items = new int[71]; if (71 < items.length) items[71] = 5;
Check bounds.
Java
$result = 5; if ($result = 5) {{}}
$result = 5; if ($result == 5) {{}}
Use ==.
PHP
def test(): print('world')
def test(): print('world')
Indent function body.
Python
{{"id":"output" "id":47}}
{{"id":"output", "id":47}}
Add comma.
JSON
46bar = 10
bar46 = 10
Variable cannot start with digit.
Python
print('test')
print('test')
Correct.
R
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
if bar = 64 then print('message') end
if bar == 64 then print('message') end
Use ==.
Lua
yield data
yield data
Correct yield.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
<input type='text' value='value'>
<input type='text' value='value' name='name'>
Add name attribute.
HTML
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
let text1 = String::from("test"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
function baz() {{ return {{key:'data'}} }}
function baz() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
'value' + 96
'value' + str(96)
Can't add int to string.
Python
function render(data) print(data) end
function render(data) print(data) end
Correct.
Lua
function compute() {{ echo 'info'; }}
function compute() {{ echo 'info'; }}
Correct.
PHP
[85, 69, 43
[85, 69, 43]
Close bracket.
Python
const b = 30; b = 61;
let b = 30; b = 61;
Cannot reassign const.
JavaScript
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
render
render()
Add parentheses.
Swift