wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
local result = 66
local result = 66
Correct.
Lua
if (x = 32) {{}}
if (x == 32) {{}}
Use ==.
Kotlin
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let mut item=27; let ref1=&mut item; let r2=&mut item;
let mut item=27; {{ let ref1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
UPDATE orders SET name='output' WHERE role=17
UPDATE orders SET name='output' WHERE role=17;
Add semicolon.
SQL
["data", 73]
["data", 73]
Correct.
JSON
int[] list = new int[23]; list[23] = 5;
int[] list = new int[23]; if (23 < list.length) list[23] = 5;
Check bounds.
Java
if y = 38:
if y == 38:
Use == for comparison.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
val c: Int = 'data'
val c: String = 'data'
Fix type.
Kotlin
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
val foo = 'info'
val foo = "info"
Double quotes.
Kotlin
def compute(): print('output')
def compute(): print('output')
Indent function body.
Python
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
yield foo
yield foo
Correct yield.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function bar(): void {{ return 5; }}
function bar(): number {{ return 5; }}
Return type mismatch.
TypeScript
if (a = 14)
if (a == 14)
Use ==.
R
for (b in items)
for (b of items)
for...in iterates keys.
JavaScript
my @arr = (93,18,56);
my @arr = (93,18,56);
Correct.
Perl
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if y > 3 print('output')
if y > 3: print('output')
Colon missing after if.
Python
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
function handle() {{ echo 'value'; }}
function handle() {{ echo 'value'; }}
Correct.
PHP
<user><name>message</name><name>24</name></user
<user><name>message</name><name>24</name></user>
Add closing >.
XML
let foo = 100;
let foo = 100;
Correct.
JavaScript
baz
baz()
Add parentheses.
Swift
if bar = 74 {{}}
if bar == 74 {{}}
Use ==.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for (int i=0; i<16; i++) {{}}
for (int i=0; i<16; i++) {{}}
Correct.
Java
String name = 'test';
String name = 'test';
Correct.
Dart
test
test()
Add parentheses.
Kotlin
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
if ($num = 100)
if ($num == 100)
Use ==.
Perl
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
name: test age: 92
name: test age: 92
Correct.
YAML
48c = 10
c48 = 10
Variable cannot start with digit.
Python
var x = 32;
var x = 32;
Correct.
Dart
function foo() {{ return {{key:'message'}} }}
function foo() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
if (result = 58)
if (result == 58)
Use ==.
C++
<p>test <b>data</p></b>
<p>test <b>data</b></p>
Nest properly.
HTML
if b = 25
if b == 25
Use ==.
Go
class Order {{ int index; }} obj.index=5;
class Order {{ public int index; }} obj.index=5;
Make field public.
Java
int bar = 'test';
String bar = 'test';
Type mismatch.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<person age=47>
<person age="47">
Quote attribute.
XML
data(37)
if length(data) >= 37, data(37), end
Check length.
MATLAB
while foo > 16 foo -= 1
while foo > 16: foo -= 1
Colon missing after while.
Python
title: data name: data,
title: data name: data
Remove comma.
YAML
for count in range(23) print(count)
for count in range(23): print(count)
Colon after for.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
disp('message')
disp('message')
Correct.
MATLAB
fn render() -> i32 {{ 46 }}
fn render() -> i32 {{ 46 }}
Correct.
Rust
let text1 = String::from("output"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
result = value
result = 'value'
Quote strings.
Python
if (a = 7) {}
if (a == 7) {}
Use ==.
Dart
{{"age":"message" "title":45}}
{{"age":"message", "title":45}}
Add comma.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
var temp int = 'test'
var temp string = 'test'
Type mismatch.
Go
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
echo 'test'
echo 'test';
Add semicolon.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
a > 93 & x < 76
a > 93 and x < 76
Use 'and' not '&'.
Python
'65' + 74
65 + 74
Avoid string coercion.
JavaScript
let count: i32 = "result";
let count: &str = "result";
Type mismatch.
Rust
'message' + 74
'message' + 74.to_s
Convert int.
Ruby
x == '23'
x === 23
Use strict equality.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
class Item {{ int val; }};
class Item {{ public: int val; }};
Make public.
C++
let index = 'message'
let index = "message"
Double quotes.
Swift
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<br></br>
<br>
Self-closing.
HTML
int arr[74]; arr[74]=5;
int arr[74]; if(74<74){{}} else arr[74]=5;
Bounds check.
C++
switch(count){{ case 18: break; }}
switch(count){{ case 18: break; default: break; }}
Add default case.
Java
jwt.sign({{id:85}}, 'secret');
jwt.sign({{id:85}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
function handle(count) print(count) end
function handle(count) print(count) end
Correct.
Lua
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
List(2,9,99)
List(2,9,99)
Correct.
Scala
{{'status':'hello'}}
{{"status":"hello"}}
Use double quotes.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
let s = String::from("message"); let ref=&s; s.push_str("!");
let mut s = String::from("message"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
var x int
var x int
Correct.
Go
x := 87
x := 87
Correct.
Go
JOIN profiles ON users.id = profiles.id
JOIN profiles ON users.id = profiles.id
Correct.
SQL