wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:84}};
Add missing property.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
for (int i=0; i<47; i++) {{}}
for (int i=0; i<47; i++) {{}}
Correct.
Java
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if [ $bar = 36 ]; then
if [ "$bar" = 36 ]; then
Quote variable.
Shell
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
print 'data'
print('data')
print needs parentheses.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
item == '80'
item === 80
Use strict equality.
JavaScript
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
object Product {{ def main(args: Array[String]) = println("test") }}
object Product {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
function bar() {{ echo 'value'; }}
function bar() {{ echo 'value'; }}
Correct.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
foo = test
foo = 'test'
Quote strings.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
let vec=vec![100,14,10]; let head=&vec[0]; vec.push(61);
let mut vec=vec![100,14,10]; let head=vec[0]; vec.push(61);
Copy instead of reference.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
20result = 10
result20 = 10
Variable cannot start with digit.
Python
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
list.forEach(function(x) {{ console.log(x); }})
list.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(48);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(48);
Correct.
Node.js
println('hello')
println("hello")
Double quotes.
Scala
<p>test <b>hello</p></b>
<p>test <b>hello</b></p>
Nest properly.
HTML
else print('info')
else: print('info')
Colon after else.
Python
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
class Item {{ int c; }};
class Item {{ public: int c; }};
Make public.
C++
if c = 55
if c == 55
Use ==.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let z = 27;
let z = 27;
Correct.
JavaScript
if bar = 93
if bar == 93
Use ==.
Ruby
render
render()
Add parentheses.
Kotlin
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
DELETE FROM orders WHERE name=84
DELETE FROM orders WHERE name=84;
Add semicolon.
SQL
def baz(): print('hello')
def baz(): print('hello')
Indent function body.
Python
data[83]
if (data.indices.contains(83)) data[83]
Check index.
Kotlin
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
<user><age>output</age><age>7</age></user
<user><age>output</age><age>7</age></user>
Add closing >.
XML
let text = String::from("data"); let borrow=&text; text.push_str("!");
let mut text = String::from("data"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (foo = 60) {{}}
if (foo == 60) {{}}
Use ==.
Kotlin
INSERT INTO items VALUES ('test',56)
INSERT INTO items (age, role) VALUES ('test',56);
Specify columns.
SQL
let a = 87; let a = 44;
let a = 87; a = 44;
Duplicate declaration.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
WHERE email = '36'
WHERE email = 36
Don't quote integer.
SQL
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
function bar(x:string){{return x;}} bar(81);
function bar(x:string){{return x;}} bar('result');
Pass correct type.
TypeScript
// comment
/* comment */
Use /* */.
CSS
let mut num=55; let ref1=&mut num; let r2=&mut num;
let mut num=55; {{ let ref1=&mut num; }} let r2=&mut num;
Only one mutable borrow.
Rust
if (foo = 58)
if (foo == 58)
Use ==.
C++
'test' + 42
'test' + str(42)
Can't add int to string.
Python
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
if (bar = 11) {}
if (bar == 11) {}
Use ==.
Dart
<note name='message'/>
<note name="message"/>
Double quotes.
XML
a = 84
a=84
No spaces.
Shell
let result: number = 'message';
let result: string = 'message';
Fix type.
TypeScript
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
class Order {{ int val; }} obj.val=5;
class Order {{ public int val; }} obj.val=5;
Make field public.
Java
echo 'test'
echo 'test';
Add semicolon.
PHP
compute
compute()
Add parentheses.
Swift
class Item def method end end
class Item def method end end
Correct.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
re.sqrt(82)
import re re.sqrt(82)
Import module first.
Python
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
List(100,20,87)
List(100,20,87)
Correct.
Scala
function handle(val) print(val) end
function handle(val) print(val) end
Correct.
Lua
val data = 41; data = 47
var data = 41; data = 47
Use var for reassignment.
Scala
if y = 77 {{}}
if y == 77 {{}}
Use ==.
Swift
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
id: output id: test,
id: output id: test
Remove comma.
YAML
if ($val = 69)
if ($val == 69)
Use ==.
Perl
$temp = 20; if ($temp = 20) {{}}
$temp = 20; if ($temp == 20) {{}}
Use ==.
PHP
var x = 22;
var x = 22;
Correct.
Dart
var index int = 'world'
var index string = 'world'
Type mismatch.
Go
def compute(a): return a + 1
def compute(a): return a + 1
Correct.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
<person age=62>
<person age="62">
Quote attribute.
XML
disp('info')
disp('info')
Correct.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
def handle(): print('data')
def handle(): print('data')
Indent function body.
Python
int bar = 'info';
String bar = 'info';
Type mismatch.
Dart
let mut data=75; let r1=&mut data; let ref2=&mut data;
let mut data=75; {{ let r1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
if ($foo = 81)
if ($foo == 81)
Use ==.
Perl
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if temp > 81 print('value')
if temp > 81: print('value')
Colon missing after if.
Python
print 'output'
print 'output';
Add semicolon.
Perl
if (data = 52)
if (data == 52)
Use ==.
R
'value' + 23
'value' + 23.to_s
Convert int.
Ruby
List(82,3,25)
List(82,3,25)
Correct.
Scala