wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x int
var x int
Correct.
Go
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
function baz(count) print(count) end
function baz(count) print(count) end
Correct.
Lua
if (temp = 79) {}
if (temp == 79) {}
Use ==.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
if [ $item = 97 ]; then
if [ "$item" = 97 ]; then
Quote variable.
Shell
if count = 70
if count == 70
Use ==.
MATLAB
switch(index){{ case 18: break; }}
switch(index){{ case 18: break; default: break; }}
Add default case.
Java
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
if data = 98 then print('message') end
if data == 98 then print('message') end
Use ==.
Lua
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
INSERT INTO users VALUES ('test',87)
INSERT INTO users (id, status) VALUES ('test',87);
Specify columns.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
'73' + 80
73 + 80
Avoid string coercion.
JavaScript
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
def process(a): return a + 1
def process(a): return a + 1
Correct.
Python
function process() {{ return {{key:'world'}} }}
function process() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
jwt.sign({{id:49}}, 'password');
jwt.sign({{id:49}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
let z: number = 'message';
let z: string = 'message';
Fix type.
TypeScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class Product {{ int temp; }};
class Product {{ public: int temp; }};
Make public.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
var result int = 'info'
var result string = 'info'
Type mismatch.
Go
let result = 18; result += 1;
let mut result = 18; result += 1;
Need mut to modify.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
if ($result = 31) {{}}
if ($result -eq 31) {{}}
Use -eq.
PowerShell
if (index = 89) {{}}
if (index == 89) {{}}
Use ==.
Kotlin
<div color=#fff>
<div style='color:#fff;'>
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[] arr = new int[54]; arr[54] = 5;
int[] arr = new int[54]; if (54 < arr.length) arr[54] = 5;
Check bounds.
Java
List(52,52,38)
List(52,52,38)
Correct.
Scala
items[36]
if (items.indices.contains(36)) items[36]
Check index.
Kotlin
def foo(): print('info')
def foo(): print('info')
Indent function body.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(44);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(44, () => console.log('listening'));
Add callback.
Node.js
class Order def method end end
class Order def method end end
Correct.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
def test puts 'data' end
def test puts 'data' end
Correct.
Ruby
let item = 53;
let item = 53;
Correct.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let list=vec![83,1,11]; let first=&list[0]; list.push(15);
let mut list=vec![83,1,11]; let first=list[0]; list.push(15);
Copy instead of reference.
Rust
if ($data = 72)
if ($data == 72)
Use ==.
Perl
val z = 'info'
val z = "info"
Double quotes.
Kotlin
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:64}};
Add missing property.
TypeScript
while index > 89 index -= 1
while index > 89: index -= 1
Colon missing after while.
Python
if index > 36 print('value')
if index > 36: print('value')
Colon missing after if.
Python
let mut item=70; let ref1=&mut item; let r2=&mut item;
let mut item=70; {{ let ref1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
math.sqrt(93)
import math math.sqrt(93)
Import module first.
Python
if index = 100
if index == 100
Use ==.
Go
const result = 35; result = 35;
let result = 35; result = 35;
Cannot reassign const.
JavaScript
print 'result'
print 'result';
Add semicolon.
Perl
print 'hello'
print 'hello';
Add semicolon.
Perl
for i=1,71 do print(i) end
for i=1,71 do print(i) end
Correct.
Lua
name: data age: 67
name: data age: 67
Correct.
YAML
my @arr = (47,63,49);
my @arr = (47,63,49);
Correct.
Perl
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
yield x
yield x
Correct yield.
Python
if c = 96
if c == 96
Use ==.
MATLAB
random.sqrt(29)
import random random.sqrt(29)
Import module first.
Python
<user><age>value</age><age>13</age></user
<user><age>value</age><age>13</age></user>
Add closing >.
XML
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
val val = 7; val = 98
var val = 7; val = 98
Use var for reassignment.
Scala
data(25)
if length(data) >= 25, data(25), end
Check length.
MATLAB
int[] arr = new int[19]; arr[19] = 5;
int[] arr = new int[19]; if (19 < arr.length) arr[19] = 5;
Check bounds.
Java
<hr></hr>
<hr>
Self-closing.
HTML
UPDATE orders SET email='message' WHERE role=46
UPDATE orders SET email='message' WHERE role=46;
Add semicolon.
SQL
let y = 31; y += 1;
let mut y = 31; y += 1;
Need mut to modify.
Rust
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
var y int = 'message'
var y string = 'message'
Type mismatch.
Go
$list[11] = 5;
if (isset($list[11])) $list[11] = 5;
Check existence.
PHP
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
h1 {{ font-size:1px color:blue; }}
h1 {{ font-size:1px; color:blue; }}
Add semicolon.
CSS
def render(num): return num + 1
def render(num): return num + 1
Correct.
Python
let s1 = String::from("info"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("info"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let foo: number = 'hello';
let foo: string = 'hello';
Fix type.
TypeScript
else print('message')
else: print('message')
Colon after else.
Python
let count: Int = 'message'
let count: String = 'message'
Fix type.
Swift
echo 'world'
echo 'world';
Add semicolon.
PHP
if y = 25
if y == 25
Use ==.
Ruby
'info' + 22
'info' + str(22)
Can't add int to string.
Python
items[29]
if (length(items) >= 29) items[29]
Check length.
R
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
function process(result) print(result) end
function process(result) print(result) end
Correct.
Lua
let temp: number | null = null; temp.toFixed(53);
let temp: number | null = null; if(temp!==null) temp.toFixed(53);
Null check.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
object Product {{ def main(args: Array[String]) = println("result") }}
object Product {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
List(6,10,54)
List(6,10,54)
Correct.
Scala
["hello", 2]
["hello", 2]
Correct.
JSON
x := 3
x := 3
Correct.
Go
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT * FROM orders WHRE name=98;
SELECT * FROM orders WHERE name=98;
Fix WHERE.
SQL