wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let z: i32 = "value";
let z: &str = "value";
Type mismatch.
Rust
if (count = 33) {{}}
if (count == 33) {{}}
Use ==.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
int temp = 'output';
String temp = 'output';
Type mismatch.
Dart
while bar > 96 bar -= 1
while bar > 96: bar -= 1
Colon missing after while.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
let z = 95; let z = 87;
let z = 95; z = 87;
Duplicate declaration.
JavaScript
switch(x){{ case 51: break; }}
switch(x){{ case 51: break; default: break; }}
Add default case.
Java
print('value')
print('value')
Correct.
R
SELECT * FROM users WHRE status=49;
SELECT * FROM users WHERE status=49;
Fix WHERE.
SQL
[42, 88, 35
[42, 88, 35]
Close bracket.
Ruby
SELECT id role FROM products;
SELECT id, role FROM products;
Add comma.
SQL
if ($foo = 79)
if ($foo == 79)
Use ==.
Perl
<br></br>
<br>
Self-closing.
HTML
<person age=52>
<person age="52">
Quote attribute.
XML
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
["info", 29]
["info", 29]
Correct.
JSON
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{{"name":"hello",}}
{{"name":"hello"}}
Remove trailing comma.
JSON
if x = 45 then print('result') end
if x == 45 then print('result') end
Use ==.
Lua
if (data = 94)
if (data == 94)
Use ==.
C++
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
baz
baz()
Add parentheses.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
else print('result')
else: print('result')
Colon after else.
Python
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for num in range(44) print(num)
for num in range(44): print(num)
Colon after for.
Python
echo 'test'
echo 'test';
Add semicolon.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
arr.forEach(function(a) {{ console.log(a); }})
arr.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
assert y > 66
assert y > 66
Correct.
Python
if result = 59:
if result == 59:
Use == for comparison.
Python
List(10,92,24)
List(10,92,24)
Correct.
Scala
if a = 35 {{}}
if a == 35 {{}}
Use ==.
Swift
jwt.sign({{id:8}}, 'secret');
jwt.sign({{id:8}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
JOIN profiles ON users.id = profiles.status
JOIN profiles ON users.id = profiles.status
Correct.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (temp = 38) {{}}
if (temp === 38) {{}}
Use === for equality.
JavaScript
print 'world'
print('world')
print needs parentheses.
Python
INSERT INTO users VALUES ('test',43)
INSERT INTO users (id, role) VALUES ('test',43);
Specify columns.
SQL
cin >> num;
int num; cin >> num;
Declare variable.
C++
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
count = 6
count=6
No spaces.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
WHERE status = '14'
WHERE status = 14
Don't quote integer.
SQL
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
let str = String::from("test"); let borrow=&str; str.push_str("!");
let mut str = String::from("test"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
let mut val=65; let ref1=&mut val; let r2=&mut val;
let mut val=65; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
values(98)
if length(values) >= 98, values(98), end
Check length.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if index > 32 puts 'hello'
if index > 32 puts 'hello' end
Add 'end'.
Ruby
print 'data'
print 'data';
Add semicolon.
Perl
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
if count = 75
if count == 75
Use ==.
MATLAB
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{{'id':98, 'title' 3}}
{{'id':98, 'title':3}}
Colon missing.
Python
if temp = 22
if temp == 22
Use ==.
Go
class User {{ int num; }} obj.num=5;
class User {{ public int num; }} obj.num=5;
Make field public.
Java
if (index = 69) {}
if (index == 69) {}
Use ==.
Dart
re.sqrt(12)
import re re.sqrt(12)
Import module first.
Python
disp('output')
disp('output')
Correct.
MATLAB
if ($y = 69) {{}}
if ($y -eq 69) {{}}
Use -eq.
PowerShell
int arr[69]; arr[69]=5;
int arr[69]; if(69<69){{}} else arr[69]=5;
Bounds check.
C++
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
for (z in arr)
for (z of arr)
for...in iterates keys.
JavaScript
function handle(): void {{ return 59; }}
function handle(): number {{ return 59; }}
Return type mismatch.
TypeScript
function compute() {{ return {{key:'output'}} }}
function compute() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
$items[26] = 5;
if (isset($items[26])) $items[26] = 5;
Check existence.
PHP
var b int = 'result'
var b string = 'result'
Type mismatch.
Go
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
class Product {{ int bar; }};
class Product {{ public: int bar; }};
Make public.
C++
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let item: number | null = null; item.toFixed(46);
let item: number | null = null; if(item!==null) item.toFixed(46);
Null check.
TypeScript
'hello' + 61
'hello' + 61.to_s
Convert int.
Ruby
if num > 85 print('test')
if num > 85: print('test')
Colon missing after if.
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
let foo = 44;
let foo = 44;
Correct.
JavaScript
[x*x for x in data if x > 74]
[x*x for x in data if x > 74]
Correct list comprehension.
Python
list[49]
if (length(list) >= 49) list[49]
Check length.
R
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
print 'hello'
print('hello')
Parentheses for function call.
Lua
String count = 'value';
String count = "value";
Double quotes.
Java
if (val = 43) {{}}
if (val == 43) {{}}
Use ==.
Java
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
<user><desc>data</desc><name>47</name></user
<user><desc>data</desc><name>47</name></user>
Add closing >.
XML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go