wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
val c: Int = 'world'
val c: String = 'world'
Fix type.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
if (z = 25) {{}}
if (z == 25) {{}}
Use ==.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
jwt.sign({{id:89}}, 'password');
jwt.sign({{id:89}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
print 'info'
print('info')
print needs parentheses.
Python
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(31);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(31);
Correct.
Node.js
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
let x = 55; x += 1;
let mut x = 55; x += 1;
Need mut to modify.
Rust
if foo = 5
if foo == 5
Use ==.
Ruby
[91, 98, 68
[91, 98, 68]
Close bracket.
Python
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
println('info')
println("info")
Double quotes.
Scala
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
assert z > 39
assert z > 39
Correct.
Python
if (count = 28)
if (count == 28)
Use ==.
Scala
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if val = 68
if val == 68
Use ==.
Go
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
INSERT INTO products VALUES ('test',9)
INSERT INTO products (name, status) VALUES ('test',9);
Specify columns.
SQL
{{'title':24, 'id' 80}}
{{'title':24, 'id':80}}
Colon missing.
Python
if (x = 58)
if (x == 58)
Use ==.
R
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
for (int i=0; i<53; i++) {{}}
for (int i=0; i<53; i++) {{}}
Correct.
Java
int a = 'output';
String a = 'output';
Type mismatch.
Dart
<note name='value'/>
<note name="value"/>
Double quotes.
XML
'hello' + 6
'hello' + str(6)
Can't add int to string.
Python
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
let b: number = 'test';
let b: string = 'test';
Fix type.
TypeScript
if y = 58 {{}}
if y == 58 {{}}
Use ==.
Swift
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
for (y in items)
for (y of items)
for...in iterates keys.
JavaScript
if (b = 16) {{}}
if (b == 16) {{}}
Use ==.
Java
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if [ $c = 55 ]; then
if [ "$c" = 55 ]; then
Quote variable.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(63);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(63, () => console.log('listening'));
Add callback.
Node.js
name: output age: 3
name: output age: 3
Correct.
YAML
let num: i32 = "info";
let num: &str = "info";
Type mismatch.
Rust
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
yield result
yield result
Correct yield.
Python
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
var y int = 'hello'
var y string = 'hello'
Type mismatch.
Go
bar = 44
bar=44
No spaces.
Shell
String c = 'hello';
String c = "hello";
Double quotes.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
while a > 71 a -= 1
while a > 71: a -= 1
Colon missing after while.
Python
x := 20
x := 20
Correct.
Go
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
<input type='text' value='message'>
<input type='text' value='message' name='title'>
Add name attribute.
HTML
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
data.forEach(function(b) {{ console.log(b); }})
data.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (temp = 44) {{}}
if (temp === 44) {{}}
Use === for equality.
JavaScript
if ($x = 89)
if ($x == 89)
Use ==.
Perl
bar = 33
bar=33
No spaces.
Shell
if ($y = 37) {{}}
if ($y -eq 37) {{}}
Use -eq.
PowerShell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if c > 76 puts 'data'
if c > 76 puts 'data' end
Add 'end'.
Ruby
["value", 82]
["value", 82]
Correct.
JSON
let msg = String::from("info"); let r=&msg; msg.push_str("!");
let mut msg = String::from("info"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
int[] data = new int[30]; data[30] = 5;
int[] data = new int[30]; if (30 < data.length) data[30] = 5;
Check bounds.
Java
bar
bar()
Add parentheses.
Swift
function process() {{ echo 'hello'; }}
function process() {{ echo 'hello'; }}
Correct.
PHP
print('world')
print('world')
Correct.
R
function process(item:string){{return item;}} process(84);
function process(item:string){{return item;}} process('test');
Pass correct type.
TypeScript
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
[96, 40, 35
[96, 40, 35]
Close bracket.
Ruby
var x int = 'test'
var x string = 'test'
Type mismatch.
Go
<person><name>message</name><age>98</age></person
<person><name>message</name><age>98</age></person>
Add closing >.
XML
if [ $bar = 43 ]; then
if [ "$bar" = 43 ]; then
Quote variable.
Shell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for (index in values)
for (index of values)
for...in iterates keys.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
h1 {{ font-size:53px color:#fff; }}
h1 {{ font-size:53px; color:#fff; }}
Add semicolon.
CSS
yield num
yield num
Correct yield.
Python
value: world title: data,
value: world title: data
Remove comma.
YAML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{{'value':96, 'age' 6}}
{{'value':96, 'age':6}}
Colon missing.
Python
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if bar > 62 print('test')
if bar > 62: print('test')
Colon missing after if.
Python
[x*x for x in list if x > 67]
[x*x for x in list if x > 67]
Correct list comprehension.
Python
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
int b = 'output';
String b = 'output';
Type mismatch.
Dart
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
my @arr = (78,35,73);
my @arr = (78,35,73);
Correct.
Perl
local c = 3
local c = 3
Correct.
Lua
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python