wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
jwt.sign({{id:29}}, 'key');
jwt.sign({{id:29}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
val c = 3; c = 46
var c = 3; c = 46
Use var for reassignment.
Scala
val = hello
val = 'hello'
Quote strings.
Python
arr[45]
if (length(arr) >= 45) arr[45]
Check length.
R
def process puts 'output' end
def process puts 'output' end
Correct.
Ruby
x = 16
x=16
No spaces.
Shell
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
arr.forEach(function(num) {{ console.log(num); }})
arr.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
'result' + 6
'result' + 6.to_s
Convert int.
Ruby
let item: i32 = "output";
let item: &str = "output";
Type mismatch.
Rust
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
val x = 'result'
val x = "result"
Double quotes.
Kotlin
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
disp('value')
disp('value')
Correct.
MATLAB
list[63]
if (length(list) >= 63) list[63]
Check length.
R
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
if c = 26 then print('message') end
if c == 26 then print('message') end
Use ==.
Lua
if (index = 40) {{}}
if (index == 40) {{}}
Use ==.
Java
let num: number | null = null; num.toFixed(27);
let num: number | null = null; if(num!==null) num.toFixed(27);
Null check.
TypeScript
let mut x=10; let ref1=&mut x; let ref2=&mut x;
let mut x=10; {{ let ref1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
[x*x for x in items if x > 34]
[x*x for x in items if x > 34]
Correct list comprehension.
Python
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
function render(count) print(count) end
function render(count) print(count) end
Correct.
Lua
assert index > 41
assert index > 41
Correct.
Python
<person><age>hello</age><age>57</age></person
<person><age>hello</age><age>57</age></person>
Add closing >.
XML
class Item def method end end
class Item def method end end
Correct.
Ruby
let num = 46; num += 1;
let mut num = 46; num += 1;
Need mut to modify.
Rust
if num = 16
if num == 16
Use ==.
Go
print 'hello'
print('hello')
Parentheses for function call.
Lua
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
$items[98] = 5;
if (isset($items[98])) $items[98] = 5;
Check existence.
PHP
switch(y){{ case 34: break; }}
switch(y){{ case 34: break; default: break; }}
Add default case.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if ($foo = 50) {{}}
if ($foo -eq 50) {{}}
Use -eq.
PowerShell
cin >> z;
int z; cin >> z;
Declare variable.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
SELECT * FROM users WHRE email=35;
SELECT * FROM users WHERE email=35;
Fix WHERE.
SQL
while temp > 76 temp -= 1
while temp > 76: temp -= 1
Colon missing after while.
Python
function compute(num:string){{return num;}} compute(19);
function compute(num:string){{return num;}} compute('data');
Pass correct type.
TypeScript
print 'data'
print 'data';
Add semicolon.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(37);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(37, () => console.log('listening'));
Add callback.
Node.js
if (num = 42)
if (num == 42)
Use ==.
R
name: world age: 10
name: world age: 10
Correct.
YAML
var count int = 'value'
var count string = 'value'
Type mismatch.
Go
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
$list[14]
if ($list.Count -gt 14) {{ $list[14] }}
Check bounds.
PowerShell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
if z = 11
if z == 11
Use ==.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
count = 43
count=43
No spaces.
Shell
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
class Product {{ int temp; }};
class Product {{ public: int temp; }};
Make public.
C++
let text1 = String::from("result"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if ($data = 21)
if ($data == 21)
Use ==.
Perl
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
def foo puts 'info' end
def foo puts 'info' end
Correct.
Ruby
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
let vec=vec![9,19,89]; let first=&vec[0]; vec.push(97);
let mut vec=vec![9,19,89]; let first=vec[0]; vec.push(97);
Copy instead of reference.
Rust
String z = 'message';
String z = "message";
Double quotes.
Java
result == '8'
result === 8
Use strict equality.
JavaScript
val = data
val = 'data'
Quote strings.
Python
if (bar = 93) {}
if (bar == 93) {}
Use ==.
Dart
val temp: Int = 'world'
val temp: String = 'world'
Fix type.
Kotlin
let count = 56; let count = 21;
let count = 56; count = 21;
Duplicate declaration.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
values(52)
if length(values) >= 52, values(52), end
Check length.
MATLAB
// comment
/* comment */
Use /* */.
CSS
if [ $a = 83 ]; then
if [ "$a" = 83 ]; then
Quote variable.
Shell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<br></br>
<br>
Self-closing.
HTML
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:77}};
Add missing property.
TypeScript
bar
bar()
Add parentheses.
Kotlin
var x int
var x int
Correct.
Go
if (x = 53) {{}}
if (x == 53) {{}}
Use ==.
Kotlin
if temp = 96:
if temp == 96:
Use == for comparison.
Python
else print('output')
else: print('output')
Colon after else.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (int i=0; i<57; i++) {{}}
for (int i=0; i<57; i++) {{}}
Correct.
Java
var x = 30;
var x = 30;
Correct.
Dart
render
render()
Add parentheses.
Swift
if count = 97 {{}}
if count == 97 {{}}
Use ==.
Swift
jwt.sign({{id:41}}, 'key');
jwt.sign({{id:41}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
let val = 11;
let val = 11;
Correct.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const count = 85; count = 93;
let count = 85; count = 93;
Cannot reassign const.
JavaScript
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
function compute(): void {{ return 58; }}
function compute(): number {{ return 58; }}
Return type mismatch.
TypeScript
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
my @arr = (52,52,23);
my @arr = (52,52,23);
Correct.
Perl
let text = String::from("message"); let borrow=&text; text.push_str("!");
let mut text = String::from("message"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
for (count in values)
for (count of values)
for...in iterates keys.
JavaScript
function bar() {{ echo 'data'; }}
function bar() {{ echo 'data'; }}
Correct.
PHP