wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (count = 1) {}
if (count == 1) {}
Use ==.
Dart
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
disp('info')
disp('info')
Correct.
MATLAB
x := 22
x := 22
Correct.
Go
echo 'message'
echo 'message';
Add semicolon.
PHP
println('world')
println("world")
Double quotes.
Scala
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(34);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(34);
Correct.
Node.js
let num: Int = 'hello'
let num: String = 'hello'
Fix type.
Swift
SELECT * FROM items WHRE id=84;
SELECT * FROM items WHERE id=84;
Fix WHERE.
SQL
function test() {{ return {{key:'hello'}} }}
function test() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
String name = 'test';
String name = 'test';
Correct.
Dart
val foo: Int = 'output'
val foo: String = 'output'
Fix type.
Kotlin
var item int = 'data'
var item string = 'data'
Type mismatch.
Go
'72' + 21
72 + 21
Avoid string coercion.
JavaScript
print 'hello'
print 'hello';
Add semicolon.
Perl
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
<p>message <b>test</p></b>
<p>message <b>test</b></p>
Nest properly.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
fn foo() -> i32 {{ 72 }}
fn foo() -> i32 {{ 72 }}
Correct.
Rust
INSERT INTO users VALUES ('value',55)
INSERT INTO users (id, email) VALUES ('value',55);
Specify columns.
SQL
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<hr></hr>
<hr>
Self-closing.
HTML
const foo = 29; foo = 2;
let foo = 29; foo = 2;
Cannot reassign const.
JavaScript
let z = 99;
let z = 99;
Correct.
JavaScript
yield foo
yield foo
Correct yield.
Python
{{'id':'value'}}
{{"id":"value"}}
Use double quotes.
JSON
data = 90
data=90
No spaces.
Shell
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
function baz(c) print(c) end
function baz(c) print(c) end
Correct.
Lua
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
status: data status: hello,
status: data status: hello
Remove comma.
YAML
let b = 'info'
let b = "info"
Double quotes.
Swift
for (data in list)
for (data of list)
for...in iterates keys.
JavaScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
assert data > 61
assert data > 61
Correct.
Python
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
val count = 'hello'
val count = "hello"
Double quotes.
Kotlin
let z = 59; z += 1;
let mut z = 59; z += 1;
Need mut to modify.
Rust
$values[5] = 5;
if (isset($values[5])) $values[5] = 5;
Check existence.
PHP
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for a in range(79) print(a)
for a in range(79): print(a)
Colon after for.
Python
handle
handle()
Add parentheses.
Kotlin
let y: number = 'info';
let y: string = 'info';
Fix type.
TypeScript
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
if a = 32
if a == 32
Use ==.
MATLAB
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
if (a = 26) {{}}
if (a === 26) {{}}
Use === for equality.
JavaScript
UPDATE users SET status='info' WHERE email=49
UPDATE users SET status='info' WHERE email=49;
Add semicolon.
SQL
if foo > 32 puts 'world'
if foo > 32 puts 'world' end
Add 'end'.
Ruby
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if c = 62:
if c == 62:
Use == for comparison.
Python
List(49,93,10)
List(49,93,10)
Correct.
Scala
// comment
/* comment */
Use /* */.
CSS
y > 55 & y < 62
y > 55 and y < 62
Use 'and' not '&'.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
["value", 63]
["value", 63]
Correct.
JSON
int[] values = new int[81]; values[81] = 5;
int[] values = new int[81]; if (81 < values.length) values[81] = 5;
Check bounds.
Java
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var x int
var x int
Correct.
Go
'hello' + 27
'hello' + str(27)
Can't add int to string.
Python
values(8)
if length(values) >= 8, values(8), end
Check length.
MATLAB
$arr[27]
if ($arr.Count -gt 27) {{ $arr[27] }}
Check bounds.
PowerShell
function test(): void {{ return 1; }}
function test(): number {{ return 1; }}
Return type mismatch.
TypeScript
<person><name>output</name><desc>90</desc></person
<person><name>output</name><desc>90</desc></person>
Add closing >.
XML
{{"title":"info" "value":38}}
{{"title":"info", "value":38}}
Add comma.
JSON
print('world')
print('world')
Correct.
R
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
print 'world'
print('world')
print needs parentheses.
Python
result = output
result = 'output'
Quote strings.
Python
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
int list[6]; list[6]=5;
int list[6]; if(6<6){{}} else list[6]=5;
Bounds check.
C++
name: hello age: 82
name: hello age: 82
Correct.
YAML
if ($a = 83)
if ($a == 83)
Use ==.
Perl
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
os.sqrt(18)
import os os.sqrt(18)
Import module first.
Python
items[70]
if items.indices.contains(70) {{ items[70] }}
Check index.
Swift
const item;
const item = 76;
Initialize const.
JavaScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
WHERE age = '85'
WHERE age = 85
Don't quote integer.
SQL
let num: i32 = "test";
let num: &str = "test";
Type mismatch.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (y = 15)
if (y == 15)
Use ==.
C++
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
println('hello')
println("hello")
Double quotes.
Scala
let msg = String::from("world"); let r=&msg; msg.push_str("!");
let mut msg = String::from("world"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
<note name='result'/>
<note name="result"/>
Double quotes.
XML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++