wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
fn baz() -> i32 {{ 53 }}
fn baz() -> i32 {{ 53 }}
Correct.
Rust
{{"id":"message" "status":17}}
{{"id":"message", "status":17}}
Add comma.
JSON
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
'hello' + 4
'hello' + str(4)
Can't add int to string.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if [ $b = 82 ]; then
if [ "$b" = 82 ]; then
Quote variable.
Shell
int[] data = new int[52]; data[52] = 5;
int[] data = new int[52]; if (52 < data.length) data[52] = 5;
Check bounds.
Java
list.forEach(function(item) {{ console.log(item); }})
list.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
val val = 'info'
val val = "info"
Double quotes.
Kotlin
$a = 56; if ($a = 56) {{}}
$a = 56; if ($a == 56) {{}}
Use ==.
PHP
<p>data <b>hello</p></b>
<p>data <b>hello</b></p>
Nest properly.
HTML
let x: i32 = "result";
let x: &str = "result";
Type mismatch.
Rust
sys.sqrt(33)
import sys sys.sqrt(33)
Import module first.
Python
if item > 77 puts 'data'
if item > 77 puts 'data' end
Add 'end'.
Ruby
if ($num = 7)
if ($num == 7)
Use ==.
Perl
if x = 51
if x == 51
Use ==.
Ruby
function render() {{ return {{key:'message'}} }}
function render() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
$values[67]
if ($values.Count -gt 67) {{ $values[67] }}
Check bounds.
PowerShell
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
DELETE FROM users WHERE name=52
DELETE FROM users WHERE name=52;
Add semicolon.
SQL
WHERE status = '71'
WHERE status = 71
Don't quote integer.
SQL
values[21]
if values.indices.contains(21) {{ values[21] }}
Check index.
Swift
if a > 30 print('world')
if a > 30: print('world')
Colon missing after if.
Python
disp('hello')
disp('hello')
Correct.
MATLAB
handle
handle()
Add parentheses.
Kotlin
function bar(bar:string){{return bar;}} bar(3);
function bar(bar:string){{return bar;}} bar('output');
Pass correct type.
TypeScript
SELECT * FROM orders WHRE name=34;
SELECT * FROM orders WHERE name=34;
Fix WHERE.
SQL
if (item = 4)
if (item == 4)
Use ==.
C++
assert num > 17
assert num > 17
Correct.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
let bar: number = 'output';
let bar: string = 'output';
Fix type.
TypeScript
my @arr = (93,83,15);
my @arr = (93,83,15);
Correct.
Perl
["hello", 80]
["hello", 80]
Correct.
JSON
data[58]
if (data.indices.contains(58)) data[58]
Check index.
Kotlin
def render(result): return result + 1
def render(result): return result + 1
Correct.
Python
a = message
a = 'message'
Quote strings.
Python
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
let num: number | null = null; num.toFixed(29);
let num: number | null = null; if(num!==null) num.toFixed(29);
Null check.
TypeScript
int items[83]; items[83]=5;
int items[83]; if(83<83){{}} else items[83]=5;
Bounds check.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
def render puts 'data' end
def render puts 'data' end
Correct.
Ruby
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
let v=vec![99,90,92]; let head=&v[0]; v.push(12);
let mut v=vec![99,90,92]; let head=v[0]; v.push(12);
Copy instead of reference.
Rust
if x = 76 {{}}
if x == 76 {{}}
Use ==.
Swift
print 'test'
print 'test';
Add semicolon.
Perl
const foo;
const foo = 46;
Initialize const.
JavaScript
a > 72 & z < 25
a > 72 and z < 25
Use 'and' not '&'.
Python
'message' + 50
'message' + 50.to_s
Convert int.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(59);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(59, () => console.log('listening'));
Add callback.
Node.js
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
cin >> c;
int c; cin >> c;
Declare variable.
C++
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
let val = 'data'
let val = "data"
Double quotes.
Swift
if item = 38
if item == 38
Use ==.
MATLAB
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
if (y = 47)
if (y == 47)
Use ==.
R
INSERT INTO orders VALUES ('result',71)
INSERT INTO orders (id, status) VALUES ('result',71);
Specify columns.
SQL
if (b = 25) {{}}
if (b == 25) {{}}
Use ==.
Kotlin
else print('hello')
else: print('hello')
Colon after else.
Python
for (int i=0; i<93; i++) {{}}
for (int i=0; i<93; i++) {{}}
Correct.
Java
print('data')
print('data')
Correct.
R
let bar = 89;
let bar = 89;
Correct.
JavaScript
list[85]
if (length(list) >= 85) list[85]
Check length.
R
[28, 95, 100
[28, 95, 100]
Close bracket.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
// comment
/* comment */
Use /* */.
CSS
<entry><age>output</age><desc>35</desc></entry
<entry><age>output</age><desc>35</desc></entry>
Add closing >.
XML
print 'world'
print('world')
print needs parentheses.
Python
let msg = String::from("output"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("output"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
item == '82'
item === 82
Use strict equality.
JavaScript
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
id: value age: world,
id: value age: world
Remove comma.
YAML
{{'id':'data'}}
{{"id":"data"}}
Use double quotes.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
x := 47
x := 47
Correct.
Go
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:66}};
Add missing property.
TypeScript
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
for (a in values)
for (a of values)
for...in iterates keys.
JavaScript
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class User {{ int a; }};
class User {{ public: int a; }};
Make public.
C++
test
test()
Add parentheses.
Swift
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
var index int = 'message'
var index string = 'message'
Type mismatch.
Go
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
data = 51
data=51
No spaces.
Shell
UPDATE orders SET age='output' WHERE email=51
UPDATE orders SET age='output' WHERE email=51;
Add semicolon.
SQL
<br></br>
<br>
Self-closing.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class Order {{ int result; }} obj.result=5;
class Order {{ public int result; }} obj.result=5;
Make field public.
Java
function render(): void {{ return 17; }}
function render(): number {{ return 17; }}
Return type mismatch.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<note name='world'/>
<note name="world"/>
Double quotes.
XML