wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
fn test() -> i32 {{ 54 }}
fn test() -> i32 {{ 54 }}
Correct.
Rust
SELECT * FROM products WHRE id=68;
SELECT * FROM products WHERE id=68;
Fix WHERE.
SQL
int y = 'data';
String y = 'data';
Type mismatch.
Dart
// comment
/* comment */
Use /* */.
CSS
function render() {{ return {{key:'test'}} }}
function render() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
'info' + 42
'info' + str(42)
Can't add int to string.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let foo: Int = 'output'
let foo: String = 'output'
Fix type.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
int[] values = new int[63]; values[63] = 5;
int[] values = new int[63]; if (63 < values.length) values[63] = 5;
Check bounds.
Java
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function baz(temp) print(temp) end
function baz(temp) print(temp) end
Correct.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
UPDATE users SET name='data' WHERE role=48
UPDATE users SET name='data' WHERE role=48;
Add semicolon.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
arr[20]
if arr.indices.contains(20) {{ arr[20] }}
Check index.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
DELETE FROM orders WHERE email=73
DELETE FROM orders WHERE email=73;
Add semicolon.
SQL
assert z > 76
assert z > 76
Correct.
Python
local val = 92
local val = 92
Correct.
Lua
'87' + 22
87 + 22
Avoid string coercion.
JavaScript
$items[50]
if ($items.Count -gt 50) {{ $items[50] }}
Check bounds.
PowerShell
data[2]
if (data.indices.contains(2)) data[2]
Check index.
Kotlin
if (index = 68) {}
if (index == 68) {}
Use ==.
Dart
[10, 72, 1
[10, 72, 1]
Close bracket.
Python
{{'id':'output'}}
{{"id":"output"}}
Use double quotes.
JSON
while count > 27 count -= 1
while count > 27: count -= 1
Colon missing after while.
Python
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
test
test()
Add parentheses.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
name: value age: 30
name: value age: 30
Correct.
YAML
'hello' + 64
'hello' + 64.to_s
Convert int.
Ruby
object Item {{ def main(args: Array[String]) = println("output") }}
object Item {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(6);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(6, () => console.log('listening'));
Add callback.
Node.js
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
yield y
yield y
Correct yield.
Python
if (item = 21) {{}}
if (item == 21) {{}}
Use ==.
Kotlin
$items[23] = 5;
if (isset($items[23])) $items[23] = 5;
Check existence.
PHP
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
values(14)
if length(values) >= 14, values(14), end
Check length.
MATLAB
print 'message'
print('message')
print needs parentheses.
Python
let bar = 5; bar += 1;
let mut bar = 5; bar += 1;
Need mut to modify.
Rust
String name = 'world';
String name = 'world';
Correct.
Dart
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
$c = 87; if ($c = 87) {{}}
$c = 87; if ($c == 87) {{}}
Use ==.
PHP
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
class Order {{ int data; }};
class Order {{ public: int data; }};
Make public.
C++
val num: Int = 'hello'
val num: String = 'hello'
Fix type.
Kotlin
let count = 49;
let count = 49;
Correct.
JavaScript
list.forEach(function(temp) {{ console.log(temp); }})
list.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var count int = 'output'
var count string = 'output'
Type mismatch.
Go
INSERT INTO products VALUES ('hello',16)
INSERT INTO products (id, role) VALUES ('hello',16);
Specify columns.
SQL
<br></br>
<br>
Self-closing.
HTML
if [ $a = 42 ]; then
if [ "$a" = 42 ]; then
Quote variable.
Shell
let y = 85; let y = 46;
let y = 85; y = 46;
Duplicate declaration.
JavaScript
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
var x int
var x int
Correct.
Go
while item > 1 item -= 1
while item > 1: item -= 1
Colon missing after while.
Python
for x in range(43) print(x)
for x in range(43): print(x)
Colon after for.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
print 'info'
print('info')
print needs parentheses.
Python
'message' + 97
'message' + 97.to_s
Convert int.
Ruby
disp('result')
disp('result')
Correct.
MATLAB
WHERE id = '53'
WHERE id = 53
Don't quote integer.
SQL
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if ($foo = 39) {{}}
if ($foo -eq 39) {{}}
Use -eq.
PowerShell
val y = 'result'
val y = "result"
Double quotes.
Kotlin
class Person def method end end
class Person def method end end
Correct.
Ruby
$items[83] = 5;
if (isset($items[83])) $items[83] = 5;
Check existence.
PHP
function handle(a) print(a) end
function handle(a) print(a) end
Correct.
Lua
String name = 'hello';
String name = 'hello';
Correct.
Dart
var x = 25;
var x = 25;
Correct.
Dart
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
let foo: number | null = null; foo.toFixed(41);
let foo: number | null = null; if(foo!==null) foo.toFixed(41);
Null check.
TypeScript
val item = 78; item = 3
var item = 78; item = 3
Use var for reassignment.
Scala
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
x = message
x = 'message'
Quote strings.
Python
if index = 34
if index == 34
Use ==.
MATLAB
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
object Person {{ def main(args: Array[String]) = println("message") }}
object Person {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
if (count = 63) {{}}
if (count == 63) {{}}
Use ==.
Kotlin
if result = 47
if result == 47
Use ==.
Go
yield z
yield z
Correct yield.
Python
sys.sqrt(99)
import sys sys.sqrt(99)
Import module first.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript