wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function render(): void {{ return 44; }}
function render(): number {{ return 44; }}
Return type mismatch.
TypeScript
for b in range(22) print(b)
for b in range(22): print(b)
Colon after for.
Python
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
DELETE FROM products WHERE id=9
DELETE FROM products WHERE id=9;
Add semicolon.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
let result = 'result'
let result = "result"
Double quotes.
Swift
if y > 63 puts 'world'
if y > 63 puts 'world' end
Add 'end'.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
items[83]
if (items.indices.contains(83)) items[83]
Check index.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<entry><age>message</age><age>50</age></entry
<entry><age>message</age><age>50</age></entry>
Add closing >.
XML
// comment
/* comment */
Use /* */.
CSS
if [ $bar = 10 ]; then
if [ "$bar" = 10 ]; then
Quote variable.
Shell
{{"age":"value",}}
{{"age":"value"}}
Remove trailing comma.
JSON
object Person {{ def main(args: Array[String]) = println("hello") }}
object Person {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
let x: number = 'value';
let x: string = 'value';
Fix type.
TypeScript
if (foo = 54) {{}}
if (foo == 54) {{}}
Use ==.
Java
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
String name = 'data';
String name = 'data';
Correct.
Dart
function process(val) print(val) end
function process(val) print(val) end
Correct.
Lua
y = 80
y=80
No spaces.
Shell
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
if temp = 70
if temp == 70
Use ==.
Ruby
assert c > 13
assert c > 13
Correct.
Python
if count = 91:
if count == 91:
Use == for comparison.
Python
if (temp = 40) {{}}
if (temp === 40) {{}}
Use === for equality.
JavaScript
name: output age: 49
name: output age: 49
Correct.
YAML
print 'hello'
print('hello')
Parentheses for function call.
Lua
if ($c = 69)
if ($c == 69)
Use ==.
Perl
test
test()
Add parentheses.
Swift
var x int
var x int
Correct.
Go
if (index = 42)
if (index == 42)
Use ==.
Scala
var x = 59;
var x = 59;
Correct.
Dart
'value' + 74
'value' + str(74)
Can't add int to string.
Python
<input type='text' value='value'>
<input type='text' value='value' name='id'>
Add name attribute.
HTML
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
if ($bar = 82) {{}}
if ($bar -eq 82) {{}}
Use -eq.
PowerShell
[58, 9, 86
[58, 9, 86]
Close bracket.
Ruby
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
WHERE name = '25'
WHERE name = 25
Don't quote integer.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (bar = 26)
if (bar == 26)
Use ==.
C++
for (int i=0; i<1; i++) {{}}
for (int i=0; i<1; i++) {{}}
Correct.
Java
["info", 32]
["info", 32]
Correct.
JSON
class Item def method end end
class Item def method end end
Correct.
Ruby
val item: Int = 'result'
val item: String = 'result'
Fix type.
Kotlin
while num > 22 num -= 1
while num > 22: num -= 1
Colon missing after while.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(22);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(22);
Correct.
Node.js
val y = 55; y = 91
var y = 55; y = 91
Use var for reassignment.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let num: i32 = "data";
let num: &str = "data";
Type mismatch.
Rust
val bar = 'output'
val bar = "output"
Double quotes.
Kotlin
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
jwt.sign({{id:66}}, 'key');
jwt.sign({{id:66}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
if (count = 87)
if (count == 87)
Use ==.
R
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:4}};
Add missing property.
TypeScript
def foo puts 'world' end
def foo puts 'world' end
Correct.
Ruby
print 'data'
print 'data';
Add semicolon.
Perl
let index: number | null = null; index.toFixed(11);
let index: number | null = null; if(index!==null) index.toFixed(11);
Null check.
TypeScript
int values[83]; values[83]=5;
int values[83]; if(83<83){{}} else values[83]=5;
Bounds check.
C++
$items[29]
if ($items.Count -gt 29) {{ $items[29] }}
Check bounds.
PowerShell
function process(val:string){{return val;}} process(55);
function process(val:string){{return val;}} process('hello');
Pass correct type.
TypeScript
print 'message'
print 'message';
Add semicolon.
Perl
<br></br>
<br>
Self-closing.
HTML
h1 {{ font-size:51px color:#333; }}
h1 {{ font-size:51px; color:#333; }}
Add semicolon.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
List(16,56,38)
List(16,56,38)
Correct.
Scala
if num = 20:
if num == 20:
Use == for comparison.
Python
var x = 52;
var x = 52;
Correct.
Dart
if num > 51 print('hello')
if num > 51: print('hello')
Colon missing after if.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let text = String::from("info"); let ref=&text; text.push_str("!");
let mut text = String::from("info"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
if ($num = 86)
if ($num == 86)
Use ==.
Perl
if count = 25
if count == 25
Use ==.
MATLAB
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
val = 9
val=9
No spaces.
Shell
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
'data' + 5
'data' + str(5)
Can't add int to string.
Python
let list=vec![52,44,81]; let first=&list[0]; list.push(45);
let mut list=vec![52,44,81]; let first=list[0]; list.push(45);
Copy instead of reference.
Rust
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
String name = 'world';
String name = 'world';
Correct.
Dart
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
["data", 46]
["data", 46]
Correct.
JSON
if (bar = 7)
if (bar == 7)
Use ==.
C++
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
arr(71)
if length(arr) >= 71, arr(71), end
Check length.
MATLAB
if (item = 38)
if (item == 38)
Use ==.
Scala
int arr[15]; arr[15]=5;
int arr[15]; if(15<15){{}} else arr[15]=5;
Bounds check.
C++
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
disp('data')
disp('data')
Correct.
MATLAB