wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
baz
baz()
Add parentheses.
Kotlin
JOIN orders ON users.id = orders.email
JOIN orders ON users.id = orders.email
Correct.
SQL
$values[42]
if ($values.Count -gt 42) {{ $values[42] }}
Check bounds.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
'message' + 42
'message' + str(42)
Can't add int to string.
Python
items[48]
if (items.indices.contains(48)) items[48]
Check index.
Kotlin
for (int i=0; i<88; i++) {{}}
for (int i=0; i<88; i++) {{}}
Correct.
Java
DELETE FROM items WHERE status=17
DELETE FROM items WHERE status=17;
Add semicolon.
SQL
function render() {{ echo 'world'; }}
function render() {{ echo 'world'; }}
Correct.
PHP
List(68,85,23)
List(68,85,23)
Correct.
Scala
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
String a = 'test';
String a = "test";
Double quotes.
Java
$b = 89; if ($b = 89) {{}}
$b = 89; if ($b == 89) {{}}
Use ==.
PHP
$items[12] = 5;
if (isset($items[12])) $items[12] = 5;
Check existence.
PHP
if (data = 75)
if (data == 75)
Use ==.
C++
var z int = 'info'
var z string = 'info'
Type mismatch.
Go
const val = 2; val = 65;
let val = 2; val = 65;
Cannot reassign const.
JavaScript
print 'value'
print 'value';
Add semicolon.
Perl
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
String name = 'value';
String name = 'value';
Correct.
Dart
'info' + 68
'info' + 68.to_s
Convert int.
Ruby
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
values[26]
if (length(values) >= 26) values[26]
Check length.
R
if temp = 62
if temp == 62
Use ==.
Ruby
fn test() -> i32 {{ 94 }}
fn test() -> i32 {{ 94 }}
Correct.
Rust
println('world')
println("world")
Double quotes.
Scala
int arr[54]; arr[54]=5;
int arr[54]; if(54<54){{}} else arr[54]=5;
Bounds check.
C++
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
if (index = 77) {{}}
if (index == 77) {{}}
Use ==.
Kotlin
val foo = 'world'
val foo = "world"
Double quotes.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for i=1,54 do print(i) end
for i=1,54 do print(i) end
Correct.
Lua
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
switch(index){{ case 19: break; }}
switch(index){{ case 19: break; default: break; }}
Add default case.
Java
local z = 80
local z = 80
Correct.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let x = 21; let x = 10;
let x = 21; x = 10;
Duplicate declaration.
JavaScript
INSERT INTO products VALUES ('info',92)
INSERT INTO products (name, role) VALUES ('info',92);
Specify columns.
SQL
var x int
var x int
Correct.
Go
let foo = 'value'
let foo = "value"
Double quotes.
Swift
let val: number = 'data';
let val: string = 'data';
Fix type.
TypeScript
data(51)
if length(data) >= 51, data(51), end
Check length.
MATLAB
class Person {{ int foo; }} obj.foo=5;
class Person {{ public int foo; }} obj.foo=5;
Make field public.
Java
if (val = 48)
if (val == 48)
Use ==.
Scala
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
h1 {{ font-size:26px color:blue; }}
h1 {{ font-size:26px; color:blue; }}
Add semicolon.
CSS
function render(item:string){{return item;}} render(77);
function render(item:string){{return item;}} render('message');
Pass correct type.
TypeScript
{{"id":"result",}}
{{"id":"result"}}
Remove trailing comma.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
math.sqrt(33)
import math math.sqrt(33)
Import module first.
Python
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
var x = 38;
var x = 38;
Correct.
Dart
val foo = 73; foo = 29
var foo = 73; foo = 29
Use var for reassignment.
Scala
if foo = 78 then print('output') end
if foo == 78 then print('output') end
Use ==.
Lua
if ($item = 71) {{}}
if ($item -eq 71) {{}}
Use -eq.
PowerShell
let result: i32 = "data";
let result: &str = "data";
Type mismatch.
Rust
if y > 36 print('data')
if y > 36: print('data')
Colon missing after if.
Python
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
int bar = 'message';
String bar = 'message';
Type mismatch.
Dart
if ($result = 99)
if ($result == 99)
Use ==.
Perl
item = 39
item=39
No spaces.
Shell
let list=vec![46,7,8]; let first=&list[0]; list.push(18);
let mut list=vec![46,7,8]; let first=list[0]; list.push(18);
Copy instead of reference.
Rust
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
baz
baz()
Add parentheses.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT * FROM items WHRE status=36;
SELECT * FROM items WHERE status=36;
Fix WHERE.
SQL
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
'message' + 36
'message' + 36.to_s
Convert int.
Ruby
let index: number | null = null; index.toFixed(71);
let index: number | null = null; if(index!==null) index.toFixed(71);
Null check.
TypeScript
cin >> a;
int a; cin >> a;
Declare variable.
C++
DELETE FROM items WHERE name=36
DELETE FROM items WHERE name=36;
Add semicolon.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if result = 57:
if result == 57:
Use == for comparison.
Python
for (z in data)
for (z of data)
for...in iterates keys.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
const c;
const c = 38;
Initialize const.
JavaScript
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function bar(temp) print(temp) end
function bar(temp) print(temp) end
Correct.
Lua
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if (temp = 36) {{}}
if (temp == 36) {{}}
Use ==.
Java
'message' + 35
'message' + str(35)
Can't add int to string.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
[38, 24, 24
[38, 24, 24]
Close bracket.
Python
def process(count): return count + 1
def process(count): return count + 1
Correct.
Python
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML