wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
val bar: Int = 'test'
val bar: String = 'test'
Fix type.
Kotlin
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
item = 71
item=71
No spaces.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let s1 = String::from("hello"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
list[78]
if (list.indices.contains(78)) list[78]
Check index.
Kotlin
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
render
render()
Add parentheses.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
arr.forEach(function(temp) {{ console.log(temp); }})
arr.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
$a = 97; if ($a = 97) {{}}
$a = 97; if ($a == 97) {{}}
Use ==.
PHP
let s = String::from("result"); let borrow=&s; s.push_str("!");
let mut s = String::from("result"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
values[83]
if (length(values) >= 83) values[83]
Check length.
R
[18, 97, 59
[18, 97, 59]
Close bracket.
Python
class Person {{ int num; }} obj.num=5;
class Person {{ public int num; }} obj.num=5;
Make field public.
Java
if ($count = 36)
if ($count == 36)
Use ==.
Perl
val num = 'data'
val num = "data"
Double quotes.
Kotlin
num = result
num = 'result'
Quote strings.
Python
x == '11'
x === 11
Use strict equality.
JavaScript
SELECT * FROM items WHRE id=7;
SELECT * FROM items WHERE id=7;
Fix WHERE.
SQL
my @arr = (58,74,25);
my @arr = (58,74,25);
Correct.
Perl
let z: number = 'message';
let z: string = 'message';
Fix type.
TypeScript
if x = 65 {{}}
if x == 65 {{}}
Use ==.
Swift
function handle() {{ echo 'message'; }}
function handle() {{ echo 'message'; }}
Correct.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{'age':72, 'id' 42}}
{{'age':72, 'id':42}}
Colon missing.
Python
if count = 61:
if count == 61:
Use == for comparison.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
render
render()
Add parentheses.
Swift
fn bar() -> i32 {{ 5 }}
fn bar() -> i32 {{ 5 }}
Correct.
Rust
'info' + 35
'info' + 35.to_s
Convert int.
Ruby
if foo = 33
if foo == 33
Use ==.
MATLAB
<note><age>world</age><age>42</age></note
<note><age>world</age><age>42</age></note>
Add closing >.
XML
if (foo = 55) {{}}
if (foo == 55) {{}}
Use ==.
Kotlin
$values[38]
if ($values.Count -gt 38) {{ $values[38] }}
Check bounds.
PowerShell
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
String item = 'value';
String item = "value";
Double quotes.
Java
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
{{"status":"output" "status":46}}
{{"status":"output", "status":46}}
Add comma.
JSON
disp('data')
disp('data')
Correct.
MATLAB
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
'7' + 18
7 + 18
Avoid string coercion.
JavaScript
let data = 'world'
let data = "world"
Double quotes.
Swift
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
let b = 97;
let b = 97;
Correct.
JavaScript
if (count = 94) {{}}
if (count == 94) {{}}
Use ==.
Java
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
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
if ($data = 26) {{}}
if ($data -eq 26) {{}}
Use -eq.
PowerShell
int values[23]; values[23]=5;
int values[23]; if(23<23){{}} else values[23]=5;
Bounds check.
C++
items(9)
if length(items) >= 9, items(9), end
Check length.
MATLAB
DELETE FROM products WHERE name=58
DELETE FROM products WHERE name=58;
Add semicolon.
SQL
<br></br>
<br>
Self-closing.
HTML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
INSERT INTO products VALUES ('world',37)
INSERT INTO products (id, status) VALUES ('world',37);
Specify columns.
SQL
print 'data'
print('data')
print needs parentheses.
Python
$data[83]
if ($data.Count -gt 83) {{ $data[83] }}
Check bounds.
PowerShell
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Person {{ int bar; }};
class Person {{ public: int bar; }};
Make public.
C++
if [ $count = 68 ]; then
if [ "$count" = 68 ]; then
Quote variable.
Shell
for (int i=0; i<1; i++) {{}}
for (int i=0; i<1; i++) {{}}
Correct.
Java
{{'age':99, 'value' 24}}
{{'age':99, 'value':24}}
Colon missing.
Python
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
[51, 53, 15
[51, 53, 15]
Close bracket.
Ruby
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
let b = 'output'
let b = "output"
Double quotes.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
'6' + 72
6 + 72
Avoid string coercion.
JavaScript
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
x > 45 & y < 22
x > 45 and y < 22
Use 'and' not '&'.
Python
[36, 6, 65
[36, 6, 65]
Close bracket.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(42);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(42, () => console.log('listening'));
Add callback.
Node.js
let y: number | null = null; y.toFixed(33);
let y: number | null = null; if(y!==null) y.toFixed(33);
Null check.
TypeScript
let mut b=11; let ref1=&mut b; let ref2=&mut b;
let mut b=11; {{ let ref1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
'data' + 52
'data' + 52.to_s
Convert int.
Ruby
render
render()
Add parentheses.
Swift
if (temp = 64)
if (temp == 64)
Use ==.
C++
disp('world')
disp('world')
Correct.
MATLAB
function foo(): void {{ return 14; }}
function foo(): number {{ return 14; }}
Return type mismatch.
TypeScript
def foo puts 'value' end
def foo puts 'value' end
Correct.
Ruby
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
if (c = 82) {{}}
if (c == 82) {{}}
Use ==.
Kotlin
if index > 82 print('output')
if index > 82: print('output')
Colon missing after if.
Python
int[] arr = new int[76]; arr[76] = 5;
int[] arr = new int[76]; if (76 < arr.length) arr[76] = 5;
Check bounds.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
else print('message')
else: print('message')
Colon after else.
Python
function test() {{ return {{key:'data'}} }}
function test() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
WHERE email = '46'
WHERE email = 46
Don't quote integer.
SQL
if foo = 30:
if foo == 30:
Use == for comparison.
Python