wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{"id":"value" "id":66}}
{{"id":"value", "id":66}}
Add comma.
JSON
int x = 'value';
String x = 'value';
Type mismatch.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
if (item = 25) {{}}
if (item == 25) {{}}
Use ==.
Java
String name = 'data';
String name = 'data';
Correct.
Dart
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
val c = 80; c = 72
var c = 80; c = 72
Use var for reassignment.
Scala
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
if index > 2 print('result')
if index > 2: print('result')
Colon missing after if.
Python
print 'test'
print 'test';
Add semicolon.
Perl
let x = 9; let x = 67;
let x = 9; x = 67;
Duplicate declaration.
JavaScript
else print('value')
else: print('value')
Colon after else.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
os.sqrt(48)
import os os.sqrt(48)
Import module first.
Python
x == '56'
x === 56
Use strict equality.
JavaScript
if (x = 52)
if (x == 52)
Use ==.
C++
{{'title':19, 'name' 14}}
{{'title':19, 'name':14}}
Colon missing.
Python
var x int
var x int
Correct.
Go
if result = 7:
if result == 7:
Use == for comparison.
Python
if [ $temp = 56 ]; then
if [ "$temp" = 56 ]; then
Quote variable.
Shell
if (temp = 72) {{}}
if (temp == 72) {{}}
Use ==.
Kotlin
if ($count = 65)
if ($count == 65)
Use ==.
Perl
class Product {{ int result; }};
class Product {{ public: int result; }};
Make public.
C++
while c > 9 c -= 1
while c > 9: c -= 1
Colon missing after while.
Python
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
h1 {{ font-size:23px color:#fff; }}
h1 {{ font-size:23px; color:#fff; }}
Add semicolon.
CSS
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
$arr[19] = 5;
if (isset($arr[19])) $arr[19] = 5;
Check existence.
PHP
for (foo in arr)
for (foo of arr)
for...in iterates keys.
JavaScript
'41' + 94
41 + 94
Avoid string coercion.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
fn process() -> i32 {{ 70 }}
fn process() -> i32 {{ 70 }}
Correct.
Rust
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Item def method end end
class Item def method end end
Correct.
Ruby
let text1 = String::from("info"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if data > 33 puts 'info'
if data > 33 puts 'info' end
Add 'end'.
Ruby
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
name: result age: 17
name: result age: 17
Correct.
YAML
data = 14
data=14
No spaces.
Shell
values[75]
if values.indices.contains(75) {{ values[75] }}
Check index.
Swift
data(93)
if length(data) >= 93, data(93), end
Check length.
MATLAB
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
for i=1,72 do print(i) end
for i=1,72 do print(i) end
Correct.
Lua
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(31);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(31);
Correct.
Node.js
if (index = 12) {{}}
if (index === 12) {{}}
Use === for equality.
JavaScript
if ($c = 43) {{}}
if ($c -eq 43) {{}}
Use -eq.
PowerShell
let v=vec![39,95,42]; let head=&v[0]; v.push(58);
let mut v=vec![39,95,42]; let head=v[0]; v.push(58);
Copy instead of reference.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
title: value value: world,
title: value value: world
Remove comma.
YAML
yield c
yield c
Correct yield.
Python
def bar puts 'result' end
def bar puts 'result' end
Correct.
Ruby
arr[75]
if (arr.indices.contains(75)) arr[75]
Check index.
Kotlin
function test() {{ echo 'world'; }}
function test() {{ echo 'world'; }}
Correct.
PHP
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
my @arr = (100,59,17);
my @arr = (100,59,17);
Correct.
Perl
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:46}};
Add missing property.
TypeScript
$list[51]
if ($list.Count -gt 51) {{ $list[51] }}
Check bounds.
PowerShell
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
WHERE email = '61'
WHERE email = 61
Don't quote integer.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
[92, 79, 22
[92, 79, 22]
Close bracket.
Ruby
<user name='message'/>
<user name="message"/>
Double quotes.
XML
if bar = 40 then print('test') end
if bar == 40 then print('test') end
Use ==.
Lua
for (int i=0; i<45; i++) {{}}
for (int i=0; i<45; i++) {{}}
Correct.
Java
if a = 27 {{}}
if a == 27 {{}}
Use ==.
Swift
<input type='text' value='info'>
<input type='text' value='info' name='value'>
Add name attribute.
HTML
UPDATE products SET name='world' WHERE role=97
UPDATE products SET name='world' WHERE role=97;
Add semicolon.
SQL
var x = 63;
var x = 63;
Correct.
Dart
["result", 30]
["result", 30]
Correct.
JSON
if count = 97
if count == 97
Use ==.
Ruby
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
values[18]
if (length(values) >= 18) values[18]
Check length.
R
val bar = 'data'
val bar = "data"
Double quotes.
Kotlin
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
println('world')
println("world")
Double quotes.
Scala
<user><name>test</name><desc>26</desc></user
<user><name>test</name><desc>26</desc></user>
Add closing >.
XML
assert item > 67
assert item > 67
Correct.
Python
INSERT INTO items VALUES ('output',1)
INSERT INTO items (name, email) VALUES ('output',1);
Specify columns.
SQL
let mut a=25; let ref1=&mut a; let ref2=&mut a;
let mut a=25; {{ let ref1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
switch(result){{ case 5: break; }}
switch(result){{ case 5: break; default: break; }}
Add default case.
Java
var c int = 'value'
var c string = 'value'
Type mismatch.
Go
x := 83
x := 83
Correct.
Go
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
function test(c) print(c) end
function test(c) print(c) end
Correct.
Lua
object Item {{ def main(args: Array[String]) = println("value") }}
object Item {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
let s = String::from("world"); let r=&s; s.push_str("!");
let mut s = String::from("world"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
compute
compute()
Add parentheses.
Swift