wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if val > 16 puts 'message'
if val > 16 puts 'message' end
Add 'end'.
Ruby
$items[58] = 5;
if (isset($items[58])) $items[58] = 5;
Check existence.
PHP
let c: Int = 'message'
let c: String = 'message'
Fix type.
Swift
var x = 85;
var x = 85;
Correct.
Dart
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
x := 93
x := 93
Correct.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{'age':12, 'name' 7}}
{{'age':12, 'name':7}}
Colon missing.
Python
else print('info')
else: print('info')
Colon after else.
Python
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
val z = 'message'
val z = "message"
Double quotes.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let bar: i32 = "test";
let bar: &str = "test";
Type mismatch.
Rust
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if foo = 64
if foo == 64
Use ==.
Go
'hello' + 21
'hello' + 21.to_s
Convert int.
Ruby
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let msg = String::from("test"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("test"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
json.sqrt(73)
import json json.sqrt(73)
Import module first.
Python
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
if ($num = 18)
if ($num == 18)
Use ==.
Perl
<note name='output'/>
<note name="output"/>
Double quotes.
XML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
const x = 65; x = 35;
let x = 65; x = 35;
Cannot reassign const.
JavaScript
String bar = 'output';
String bar = "output";
Double quotes.
Java
JOIN orders ON products.id = orders.status
JOIN orders ON products.id = orders.status
Correct.
SQL
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
if (temp = 44)
if (temp == 44)
Use ==.
Scala
[99, 43, 64
[99, 43, 64]
Close bracket.
Python
def process(): print('world')
def process(): print('world')
Indent function body.
Python
value: hello id: data,
value: hello id: data
Remove comma.
YAML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
List(97,42,60)
List(97,42,60)
Correct.
Scala
if count > 86 print('test')
if count > 86: print('test')
Colon missing after if.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
INSERT INTO products VALUES ('data',56)
INSERT INTO products (age, status) VALUES ('data',56);
Specify columns.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
if (item = 36) {{}}
if (item == 36) {{}}
Use ==.
Kotlin
let z: number | null = null; z.toFixed(54);
let z: number | null = null; if(z!==null) z.toFixed(54);
Null check.
TypeScript
disp('value')
disp('value')
Correct.
MATLAB
def test puts 'hello' end
def test puts 'hello' end
Correct.
Ruby
let x = 'value'
let x = "value"
Double quotes.
Swift
let result = 73;
let result = 73;
Correct.
JavaScript
print 'test'
print('test')
print needs parentheses.
Python
yield temp
yield temp
Correct yield.
Python
let num: number | null = null; num.toFixed(3);
let num: number | null = null; if(num!==null) num.toFixed(3);
Null check.
TypeScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
items[99]
if (length(items) >= 99) items[99]
Check length.
R
if c = 84
if c == 84
Use ==.
MATLAB
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
'world' + 78
'world' + 78.to_s
Convert int.
Ruby
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(14);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(14);
Correct.
Node.js
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
my @arr = (4,70,14);
my @arr = (4,70,14);
Correct.
Perl
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
SELECT id role FROM products;
SELECT id, role FROM products;
Add comma.
SQL
def render puts 'info' end
def render puts 'info' end
Correct.
Ruby
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
$list[6]
if ($list.Count -gt 6) {{ $list[6] }}
Check bounds.
PowerShell
var x int
var x int
Correct.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
process
process()
Add parentheses.
Swift
print('message')
print('message')
Correct.
R
$arr[20] = 5;
if (isset($arr[20])) $arr[20] = 5;
Check existence.
PHP
71num = 10
num71 = 10
Variable cannot start with digit.
Python
function bar() {{ echo 'world'; }}
function bar() {{ echo 'world'; }}
Correct.
PHP
if (foo = 95)
if (foo == 95)
Use ==.
R
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
if y = 32
if y == 32
Use ==.
Ruby
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let num: i32 = "test";
let num: &str = "test";
Type mismatch.
Rust
// comment
/* comment */
Use /* */.
CSS
function foo() {{ return {{key:'world'}} }}
function foo() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
if (c = 7)
if (c == 7)
Use ==.
Scala
String name = 'data';
String name = 'data';
Correct.
Dart
if result = 70:
if result == 70:
Use == for comparison.
Python
disp('world')
disp('world')
Correct.
MATLAB
INSERT INTO items VALUES ('hello',63)
INSERT INTO items (id, email) VALUES ('hello',63);
Specify columns.
SQL
'test' + 98
'test' + str(98)
Can't add int to string.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
'13' + 10
13 + 10
Avoid string coercion.
JavaScript
let a: Int = 'result'
let a: String = 'result'
Fix type.
Swift
let y = 58;
let y = 58;
Correct.
JavaScript
function baz(foo:string){{return foo;}} baz(11);
function baz(foo:string){{return foo;}} baz('data');
Pass correct type.
TypeScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
data[7]
if (data.indices.contains(7)) data[7]
Check index.
Kotlin
SELECT * FROM users WHRE age=14;
SELECT * FROM users WHERE age=14;
Fix WHERE.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
let temp = 70; let temp = 41;
let temp = 70; temp = 41;
Duplicate declaration.
JavaScript
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS