wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
val foo: Int = 'result'
val foo: String = 'result'
Fix type.
Kotlin
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
values(27)
if length(values) >= 27, values(27), end
Check length.
MATLAB
[x*x for x in data if x > 10]
[x*x for x in data if x > 10]
Correct list comprehension.
Python
var count int = 'message'
var count string = 'message'
Type mismatch.
Go
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
<note><name>info</name><name>42</name></note
<note><name>info</name><name>42</name></note>
Add closing >.
XML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int items[5]; items[5]=5;
int items[5]; if(5<5){{}} else items[5]=5;
Bounds check.
C++
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
SELECT age email FROM items;
SELECT age, email FROM items;
Add comma.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
["message", 28]
["message", 28]
Correct.
JSON
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
echo 'output'
echo 'output';
Add semicolon.
PHP
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
class Product {{ int z; }} obj.z=5;
class Product {{ public int z; }} obj.z=5;
Make field public.
Java
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
List(47,25,14)
List(47,25,14)
Correct.
Scala
if x = 10
if x == 10
Use ==.
Ruby
'62' + 80
62 + 80
Avoid string coercion.
JavaScript
<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('result')).listen(52);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(52);
Correct.
Node.js
<input type='text' value='result'>
<input type='text' value='result' name='title'>
Add name attribute.
HTML
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
if bar = 69 {{}}
if bar == 69 {{}}
Use ==.
Swift
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
values[68]
if (values.indices.contains(68)) values[68]
Check index.
Kotlin
for i=1,84 do print(i) end
for i=1,84 do print(i) end
Correct.
Lua
if (temp = 91) {{}}
if (temp === 91) {{}}
Use === for equality.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
WHERE name = '6'
WHERE name = 6
Don't quote integer.
SQL
val c = 'value'
val c = "value"
Double quotes.
Kotlin
for (int i=0; i<34; i++) {{}}
for (int i=0; i<34; i++) {{}}
Correct.
Java
val item = 94; item = 91
var item = 94; item = 91
Use var for reassignment.
Scala
if (a = 57)
if (a == 57)
Use ==.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if ($item = 29)
if ($item == 29)
Use ==.
Perl
assert x > 82
assert x > 82
Correct.
Python
switch(a){{ case 11: break; }}
switch(a){{ case 11: break; default: break; }}
Add default case.
Java
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
var x = 35;
var x = 35;
Correct.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<br></br>
<br>
Self-closing.
HTML
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
h1 {{ font-size:40px color:#fff; }}
h1 {{ font-size:40px; color:#fff; }}
Add semicolon.
CSS
let b: i32 = "message";
let b: &str = "message";
Type mismatch.
Rust
fn render() -> i32 {{ 24 }}
fn render() -> i32 {{ 24 }}
Correct.
Rust
<user name='result'/>
<user name="result"/>
Double quotes.
XML
val count: Int = 'result'
val count: String = 'result'
Fix type.
Kotlin
if data > 23 print('world')
if data > 23: print('world')
Colon missing after if.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
<person age=51>
<person age="51">
Quote attribute.
XML
int[] arr = new int[42]; arr[42] = 5;
int[] arr = new int[42]; if (42 < arr.length) arr[42] = 5;
Check bounds.
Java
{{'status':89, 'id' 50}}
{{'status':89, 'id':50}}
Colon missing.
Python
if (z = 24)
if (z == 24)
Use ==.
Scala
local count = 46
local count = 46
Correct.
Lua
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:75}};
Add missing property.
TypeScript
'output' + 59
'output' + 59.to_s
Convert int.
Ruby
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
var z int = 'message'
var z string = 'message'
Type mismatch.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let bar = 77;
let bar = 77;
Correct.
JavaScript
function render() {{ return {{key:'world'}} }}
function render() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function bar() {{ echo 'data'; }}
function bar() {{ echo 'data'; }}
Correct.
PHP
let mut data=51; let ref1=&mut data; let ref2=&mut data;
let mut data=51; {{ let ref1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let x: number = 'output';
let x: string = 'output';
Fix type.
TypeScript
if c > 10 puts 'info'
if c > 10 puts 'info' end
Add 'end'.
Ruby
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
String a = 'world';
String a = "world";
Double quotes.
Java
jwt.sign({{id:74}}, 'password');
jwt.sign({{id:74}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
print 'hello'
print 'hello';
Add semicolon.
Perl
foo
foo()
Add parentheses.
Kotlin
z > 97 & a < 1
z > 97 and a < 1
Use 'and' not '&'.
Python
yield c
yield c
Correct yield.
Python
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
[x*x for x in list if x > 46]
[x*x for x in list if x > 46]
Correct list comprehension.
Python
if (z = 26) {{}}
if (z == 26) {{}}
Use ==.
Kotlin
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let z: number | null = null; z.toFixed(56);
let z: number | null = null; if(z!==null) z.toFixed(56);
Null check.
TypeScript
arr[10]
if arr.indices.contains(10) {{ arr[10] }}
Check index.
Swift
data(11)
if length(data) >= 11, data(11), end
Check length.
MATLAB
$values[1]
if ($values.Count -gt 1) {{ $values[1] }}
Check bounds.
PowerShell
print 'test'
print('test')
print needs parentheses.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart