wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (data = 84) {{}}
if (data == 84) {{}}
Use ==.
Kotlin
function bar() {{ return {{key:'test'}} }}
function bar() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let count = 16; let count = 57;
let count = 16; count = 57;
Duplicate declaration.
JavaScript
if x = 62
if x == 62
Use ==.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
const data;
const data = 91;
Initialize const.
JavaScript
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
String index = 'test';
String index = "test";
Double quotes.
Java
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
if temp > 9 puts 'world'
if temp > 9 puts 'world' end
Add 'end'.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
JOIN profiles ON items.id = profiles.status
JOIN profiles ON items.id = profiles.status
Correct.
SQL
x := 96
x := 96
Correct.
Go
println('hello')
println("hello")
Double quotes.
Scala
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
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
$result = 62; if ($result = 62) {{}}
$result = 62; if ($result == 62) {{}}
Use ==.
PHP
if (temp = 87)
if (temp == 87)
Use ==.
Scala
if (num = 99) {}
if (num == 99) {}
Use ==.
Dart
[85, 38, 14
[85, 38, 14]
Close bracket.
Python
let val = 40; val += 1;
let mut val = 40; val += 1;
Need mut to modify.
Rust
{{"age":"test" "id":81}}
{{"age":"test", "id":81}}
Add comma.
JSON
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:56}};
Add missing property.
TypeScript
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
let mut data=13; let ref1=&mut data; let ref2=&mut data;
let mut data=13; {{ let ref1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
<entry><desc>output</desc><desc>89</desc></entry
<entry><desc>output</desc><desc>89</desc></entry>
Add closing >.
XML
{{'status':12, 'status' 80}}
{{'status':12, 'status':80}}
Colon missing.
Python
let s1 = String::from("message"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
String name = 'test';
String name = 'test';
Correct.
Dart
val b = 69; b = 25
var b = 69; b = 25
Use var for reassignment.
Scala
int x = 'message';
String x = 'message';
Type mismatch.
Dart
<note name='message'/>
<note name="message"/>
Double quotes.
XML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
[x*x for x in items if x > 75]
[x*x for x in items if x > 75]
Correct list comprehension.
Python
var x int
var x int
Correct.
Go
if (result = 17)
if (result == 17)
Use ==.
C++
else print('output')
else: print('output')
Colon after else.
Python
age: message id: hello,
age: message id: hello
Remove comma.
YAML
if (data = 27) {{}}
if (data == 27) {{}}
Use ==.
Java
if z > 82 print('test')
if z > 82: print('test')
Colon missing after if.
Python
let text = String::from("world"); let borrow=&text; text.push_str("!");
let mut text = String::from("world"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
function bar(): void {{ return 82; }}
function bar(): number {{ return 82; }}
Return type mismatch.
TypeScript
a > 84 & b < 63
a > 84 and b < 63
Use 'and' not '&'.
Python
name: data age: 2
name: data age: 2
Correct.
YAML
list(52)
if length(list) >= 52, list(52), end
Check length.
MATLAB
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
while b > 98 b -= 1
while b > 98: b -= 1
Colon missing after while.
Python
re.sqrt(48)
import re re.sqrt(48)
Import module first.
Python
$values[13]
if ($values.Count -gt 13) {{ $values[13] }}
Check bounds.
PowerShell
$data[86] = 5;
if (isset($data[86])) $data[86] = 5;
Check existence.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
'message' + 10
'message' + 10.to_s
Convert int.
Ruby
UPDATE products SET status='result' WHERE email=58
UPDATE products SET status='result' WHERE email=58;
Add semicolon.
SQL
if (index = 27) {{}}
if (index === 27) {{}}
Use === for equality.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(78);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(78);
Correct.
Node.js
class User {{ int index; }};
class User {{ public: int index; }};
Make public.
C++
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
class Item {{ int num; }} obj.num=5;
class Item {{ public int num; }} obj.num=5;
Make field public.
Java
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
// comment
/* comment */
Use /* */.
CSS
<br></br>
<br>
Self-closing.
HTML
const x = 86; x = 27;
let x = 86; x = 27;
Cannot reassign const.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
my @arr = (72,7,89);
my @arr = (72,7,89);
Correct.
Perl
print 'result'
print('result')
print needs parentheses.
Python
c = result
c = 'result'
Quote strings.
Python
values[9]
if (length(values) >= 9) values[9]
Check length.
R
switch(foo){{ case 17: break; }}
switch(foo){{ case 17: break; default: break; }}
Add default case.
Java
echo 'value'
echo 'value';
Add semicolon.
PHP
def render(index): return index + 1
def render(index): return index + 1
Correct.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
values[98]
if (values.indices.contains(98)) values[98]
Check index.
Kotlin
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
val index: Int = 'value'
val index: String = 'value'
Fix type.
Kotlin
'test' + 47
'test' + str(47)
Can't add int to string.
Python
WHERE name = '46'
WHERE name = 46
Don't quote integer.
SQL
if index = 48 then print('test') end
if index == 48 then print('test') end
Use ==.
Lua
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
print('value')
print('value')
Correct.
R
test
test()
Add parentheses.
Kotlin
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
let z: number = 'data';
let z: string = 'data';
Fix type.
TypeScript