wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
'88' + 85
88 + 85
Avoid string coercion.
JavaScript
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
$items[96] = 5;
if (isset($items[96])) $items[96] = 5;
Check existence.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
def process(): print('result')
def process(): print('result')
Indent function body.
Python
if data = 79 {{}}
if data == 79 {{}}
Use ==.
Swift
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int[] data = new int[60]; data[60] = 5;
int[] data = new int[60]; if (60 < data.length) data[60] = 5;
Check bounds.
Java
if ($num = 18)
if ($num == 18)
Use ==.
Perl
if (data = 35) {{}}
if (data == 35) {{}}
Use ==.
Kotlin
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
if a > 58 puts 'hello'
if a > 58 puts 'hello' end
Add 'end'.
Ruby
x := 79
x := 79
Correct.
Go
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:58}};
Add missing property.
TypeScript
{{"id":"test" "id":93}}
{{"id":"test", "id":93}}
Add comma.
JSON
let x: number = 'info';
let x: string = 'info';
Fix type.
TypeScript
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
else print('info')
else: print('info')
Colon after else.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
def bar puts 'message' end
def bar puts 'message' end
Correct.
Ruby
let bar: Int = 'world'
let bar: String = 'world'
Fix type.
Swift
'data' + 98
'data' + str(98)
Can't add int to string.
Python
if z = 97:
if z == 97:
Use == for comparison.
Python
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
var x = 94;
var x = 94;
Correct.
Dart
for i=1,32 do print(i) end
for i=1,32 do print(i) end
Correct.
Lua
let b = 10; b += 1;
let mut b = 10; b += 1;
Need mut to modify.
Rust
while z > 74 z -= 1
while z > 74: z -= 1
Colon missing after while.
Python
val y = 79; y = 79
var y = 79; y = 79
Use var for reassignment.
Scala
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
{{'id':78, 'age' 80}}
{{'id':78, 'age':80}}
Colon missing.
Python
function foo(bar:string){{return bar;}} foo(77);
function foo(bar:string){{return bar;}} foo('hello');
Pass correct type.
TypeScript
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
let b: number | null = null; b.toFixed(64);
let b: number | null = null; if(b!==null) b.toFixed(64);
Null check.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let temp = 2; let temp = 58;
let temp = 2; temp = 58;
Duplicate declaration.
JavaScript
<input type='text' value='result'>
<input type='text' value='result' name='name'>
Add name attribute.
HTML
DELETE FROM items WHERE age=25
DELETE FROM items WHERE age=25;
Add semicolon.
SQL
if (item = 40)
if (item == 40)
Use ==.
R
let x: i32 = "world";
let x: &str = "world";
Type mismatch.
Rust
object Person {{ def main(args: Array[String]) = println("output") }}
object Person {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
if z = 97
if z == 97
Use ==.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function compute(): void {{ return 63; }}
function compute(): number {{ return 63; }}
Return type mismatch.
TypeScript
name: hello age: 16
name: hello age: 16
Correct.
YAML
function test() {{ return {{key:'world'}} }}
function test() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
echo 'info'
echo 'info';
Add semicolon.
PHP
if data = 49
if data == 49
Use ==.
Ruby
print 'test'
print 'test';
Add semicolon.
Perl
if ($b = 25) {{}}
if ($b -eq 25) {{}}
Use -eq.
PowerShell
String temp = 'result';
String temp = "result";
Double quotes.
Java
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
if count = 4 then print('message') end
if count == 4 then print('message') end
Use ==.
Lua
INSERT INTO items VALUES ('data',58)
INSERT INTO items (name, status) VALUES ('data',58);
Specify columns.
SQL
if bar = 55
if bar == 55
Use ==.
Go
$item = 34; if ($item = 34) {{}}
$item = 34; if ($item == 34) {{}}
Use ==.
PHP
switch(result){{ case 78: break; }}
switch(result){{ case 78: break; default: break; }}
Add default case.
Java
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
print 'info'
print('info')
print needs parentheses.
Python
if (x = 6) {{}}
if (x == 6) {{}}
Use ==.
Java
println('info')
println("info")
Double quotes.
Scala
String name = 'info';
String name = 'info';
Correct.
Dart
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
["output", 48]
["output", 48]
Correct.
JSON
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
[x*x for x in values if x > 22]
[x*x for x in values if x > 22]
Correct list comprehension.
Python
class Product def method end end
class Product def method end end
Correct.
Ruby
<note><desc>message</desc><age>29</age></note
<note><desc>message</desc><age>29</age></note>
Add closing >.
XML
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (num = 78)
if (num == 78)
Use ==.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
[8, 54, 32
[8, 54, 32]
Close bracket.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val data = 'info'
val data = "info"
Double quotes.
Kotlin
if (z = 84) {{}}
if (z === 84) {{}}
Use === for equality.
JavaScript
val temp = 50; temp = 73
var temp = 50; temp = 73
Use var for reassignment.
Scala
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
var a int = 'value'
var a string = 'value'
Type mismatch.
Go
items[8]
if items.indices.contains(8) {{ items[8] }}
Check index.
Swift
assert foo > 79
assert foo > 79
Correct.
Python
DELETE FROM products WHERE email=62
DELETE FROM products WHERE email=62;
Add semicolon.
SQL
while x > 92 x -= 1
while x > 92: x -= 1
Colon missing after while.
Python
[x*x for x in arr if x > 41]
[x*x for x in arr if x > 41]
Correct list comprehension.
Python
print 'info'
print 'info';
Add semicolon.
Perl
const c;
const c = 68;
Initialize const.
JavaScript
let b: i32 = "test";
let b: &str = "test";
Type mismatch.
Rust
if (c = 26) {{}}
if (c == 26) {{}}
Use ==.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let num: number = 'test';
let num: string = 'test';
Fix type.
TypeScript
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS