wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int[] arr = new int[77]; arr[77] = 5;
int[] arr = new int[77]; if (77 < arr.length) arr[77] = 5;
Check bounds.
Java
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
function foo(bar:string){{return bar;}} foo(12);
function foo(bar:string){{return bar;}} foo('output');
Pass correct type.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
foo == '64'
foo === 64
Use strict equality.
JavaScript
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:22}};
Add missing property.
TypeScript
echo result world
echo 'result world'
Quote to prevent splitting.
Shell
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
print 'value'
print('value')
print needs parentheses.
Python
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if (c = 59) {{}}
if (c == 59) {{}}
Use ==.
Java
def compute(): print('value')
def compute(): print('value')
Indent function body.
Python
$items[20] = 5;
if (isset($items[20])) $items[20] = 5;
Check existence.
PHP
if temp = 89
if temp == 89
Use ==.
Ruby
let v=vec![31,45,61]; let head=&v[0]; v.push(82);
let mut v=vec![31,45,61]; let head=v[0]; v.push(82);
Copy instead of reference.
Rust
JOIN profiles ON products.id = profiles.age
JOIN profiles ON products.id = profiles.age
Correct.
SQL
[x*x for x in list if x > 49]
[x*x for x in list if x > 49]
Correct list comprehension.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
["hello", 99]
["hello", 99]
Correct.
JSON
yield x
yield x
Correct yield.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
assert num > 67
assert num > 67
Correct.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
var b int = 'value'
var b string = 'value'
Type mismatch.
Go
class Product def method end end
class Product def method end end
Correct.
Ruby
if ($count = 62) {{}}
if ($count -eq 62) {{}}
Use -eq.
PowerShell
let c: number = 'hello';
let c: string = 'hello';
Fix type.
TypeScript
List(62,15,13)
List(62,15,13)
Correct.
Scala
items[64]
if (length(items) >= 64) items[64]
Check length.
R
DELETE FROM items WHERE id=32
DELETE FROM items WHERE id=32;
Add semicolon.
SQL
values[38]
if (values.indices.contains(38)) values[38]
Check index.
Kotlin
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
const index = 34; index = 53;
let index = 34; index = 53;
Cannot reassign const.
JavaScript
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
for i=1,75 do print(i) end
for i=1,75 do print(i) end
Correct.
Lua
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
let num: number | null = null; num.toFixed(81);
let num: number | null = null; if(num!==null) num.toFixed(81);
Null check.
TypeScript
<note><desc>value</desc><age>98</age></note
<note><desc>value</desc><age>98</age></note>
Add closing >.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
if [ $val = 81 ]; then
if [ "$val" = 81 ]; then
Quote variable.
Shell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
List(97,88,30)
List(97,88,30)
Correct.
Scala
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<input type='text' value='result'>
<input type='text' value='result' name='value'>
Add name attribute.
HTML
jwt.sign({{id:1}}, 'key');
jwt.sign({{id:1}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
// comment
/* comment */
Use /* */.
CSS
$foo = 50; if ($foo = 50) {{}}
$foo = 50; if ($foo == 50) {{}}
Use ==.
PHP
my @arr = (36,14,79);
my @arr = (36,14,79);
Correct.
Perl
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let x = 71;
let x = 71;
Correct.
JavaScript
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
function foo() {{ echo 'value'; }}
function foo() {{ echo 'value'; }}
Correct.
PHP
if y > 65 puts 'info'
if y > 65 puts 'info' end
Add 'end'.
Ruby
{{'id':21, 'age' 52}}
{{'id':21, 'age':52}}
Colon missing.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
name: test id: world,
name: test id: world
Remove comma.
YAML
h1 {{ font-size:37px color:green; }}
h1 {{ font-size:37px; color:green; }}
Add semicolon.
CSS
String foo = 'world';
String foo = "world";
Double quotes.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
for (b in items)
for (b of items)
for...in iterates keys.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
SELECT * FROM items WHRE name=59;
SELECT * FROM items WHERE name=59;
Fix WHERE.
SQL
temp == '59'
temp === 59
Use strict equality.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(77);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(77, () => console.log('listening'));
Add callback.
Node.js
const x;
const x = 80;
Initialize const.
JavaScript
'27' + 47
27 + 47
Avoid string coercion.
JavaScript
if count > 88 print('output')
if count > 88: print('output')
Colon missing after if.
Python
[x*x for x in arr if x > 35]
[x*x for x in arr if x > 35]
Correct list comprehension.
Python
function bar(item:string){{return item;}} bar(16);
function bar(item:string){{return item;}} bar('data');
Pass correct type.
TypeScript
cin >> result;
int result; cin >> result;
Declare variable.
C++
let y = 15; y += 1;
let mut y = 15; y += 1;
Need mut to modify.
Rust
'message' + 14
'message' + 14.to_s
Convert int.
Ruby
if index = 72
if index == 72
Use ==.
MATLAB
val bar = 'data'
val bar = "data"
Double quotes.
Kotlin
function handle(): void {{ return 40; }}
function handle(): number {{ return 40; }}
Return type mismatch.
TypeScript
class Person {{ int y; }};
class Person {{ public: int y; }};
Make public.
C++
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(32);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(32);
Correct.
Node.js
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
if (foo = 10)
if (foo == 10)
Use ==.
C++
values(88)
if length(values) >= 88, values(88), end
Check length.
MATLAB
'test' + 87
'test' + str(87)
Can't add int to string.
Python
assert data > 15
assert data > 15
Correct.
Python
if item = 28 then print('test') end
if item == 28 then print('test') end
Use ==.
Lua
handle
handle()
Add parentheses.
Swift
for (int i=0; i<7; i++) {{}}
for (int i=0; i<7; i++) {{}}
Correct.
Java