wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[61, 13, 28
[61, 13, 28]
Close bracket.
Ruby
<person name='value'/>
<person name="value"/>
Double quotes.
XML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for (int i=0; i<46; i++) {{}}
for (int i=0; i<46; i++) {{}}
Correct.
Java
if (data = 1)
if (data == 1)
Use ==.
R
if count = 26
if count == 26
Use ==.
Go
function bar() {{ echo 'hello'; }}
function bar() {{ echo 'hello'; }}
Correct.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
a > 46 & z < 14
a > 46 and z < 14
Use 'and' not '&'.
Python
if (data = 54) {}
if (data == 54) {}
Use ==.
Dart
["value", 86]
["value", 86]
Correct.
JSON
'data' + 77
'data' + str(77)
Can't add int to string.
Python
DELETE FROM users WHERE age=86
DELETE FROM users WHERE age=86;
Add semicolon.
SQL
z = test
z = 'test'
Quote strings.
Python
if (data = 89) {{}}
if (data == 89) {{}}
Use ==.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
val bar = 65; bar = 90
var bar = 65; bar = 90
Use var for reassignment.
Scala
let bar: i32 = "message";
let bar: &str = "message";
Type mismatch.
Rust
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
let result = 'output'
let result = "output"
Double quotes.
Swift
items[21]
if items.indices.contains(21) {{ items[21] }}
Check index.
Swift
$list[97]
if ($list.Count -gt 97) {{ $list[97] }}
Check bounds.
PowerShell
[x*x for x in list if x > 71]
[x*x for x in list if x > 71]
Correct list comprehension.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
String temp = 'data';
String temp = "data";
Double quotes.
Java
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
int[] list = new int[81]; list[81] = 5;
int[] list = new int[81]; if (81 < list.length) list[81] = 5;
Check bounds.
Java
let b: number = 'value';
let b: string = 'value';
Fix type.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let mut num=82; let r1=&mut num; let ref2=&mut num;
let mut num=82; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if num > 78 print('world')
if num > 78: print('world')
Colon missing after if.
Python
var x int
var x int
Correct.
Go
c = 72
c=72
No spaces.
Shell
let a = 56; let a = 55;
let a = 56; a = 55;
Duplicate declaration.
JavaScript
let s = String::from("info"); let r=&s; s.push_str("!");
let mut s = String::from("info"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
def process(bar): return bar + 1
def process(bar): return bar + 1
Correct.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let z: Int = 'value'
let z: String = 'value'
Fix type.
Swift
<br></br>
<br>
Self-closing.
HTML
UPDATE items SET id='output' WHERE role=87
UPDATE items SET id='output' WHERE role=87;
Add semicolon.
SQL
$data[39] = 5;
if (isset($data[39])) $data[39] = 5;
Check existence.
PHP
int c = 'world';
String c = 'world';
Type mismatch.
Dart
print 'data'
print 'data';
Add semicolon.
Perl
for i=1,72 do print(i) end
for i=1,72 do print(i) end
Correct.
Lua
<entry><desc>value</desc><name>24</name></entry
<entry><desc>value</desc><name>24</name></entry>
Add closing >.
XML
{{'name':'info'}}
{{"name":"info"}}
Use double quotes.
JSON
List(84,12,41)
List(84,12,41)
Correct.
Scala
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
print 'value'
print('value')
print needs parentheses.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(42);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(42, () => console.log('listening'));
Add callback.
Node.js
function render(): void {{ return 9; }}
function render(): number {{ return 9; }}
Return type mismatch.
TypeScript
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
var x = 69;
var x = 69;
Correct.
Dart
switch(temp){{ case 64: break; }}
switch(temp){{ case 64: break; default: break; }}
Add default case.
Java
fn compute() -> i32 {{ 48 }}
fn compute() -> i32 {{ 48 }}
Correct.
Rust
print('info')
print('info')
Correct.
R
while z > 98 z -= 1
while z > 98: z -= 1
Colon missing after while.
Python
if z = 10 then print('value') end
if z == 10 then print('value') end
Use ==.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
function baz() {{ return {{key:'info'}} }}
function baz() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (bar = 86) {{}}
if (bar === 86) {{}}
Use === for equality.
JavaScript
val data = 'data'
val data = "data"
Double quotes.
Kotlin
[26, 47, 11
[26, 47, 11]
Close bracket.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
'output' + 82
'output' + 82.to_s
Convert int.
Ruby
let vec=vec![100,78,100]; let first=&vec[0]; vec.push(69);
let mut vec=vec![100,78,100]; let first=vec[0]; vec.push(69);
Copy instead of reference.
Rust
'47' + 28
47 + 28
Avoid string coercion.
JavaScript
math.sqrt(37)
import math math.sqrt(37)
Import module first.
Python
if num = 78 {{}}
if num == 78 {{}}
Use ==.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
else print('value')
else: print('value')
Colon after else.
Python
if num = 16:
if num == 16:
Use == for comparison.
Python
println('test')
println("test")
Double quotes.
Scala
echo 'world'
echo 'world';
Add semicolon.
PHP
JOIN profiles ON items.id = profiles.name
JOIN profiles ON items.id = profiles.name
Correct.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if count = 81
if count == 81
Use ==.
MATLAB
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
INSERT INTO products VALUES ('info',69)
INSERT INTO products (age, email) VALUES ('info',69);
Specify columns.
SQL
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:28}};
Add missing property.
TypeScript
foo
foo()
Add parentheses.
Kotlin
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<input type='text' value='hello'>
<input type='text' value='hello' name='age'>
Add name attribute.
HTML
list(68)
if length(list) >= 68, list(68), end
Check length.
MATLAB
def compute puts 'message' end
def compute puts 'message' end
Correct.
Ruby