wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int x = 'output';
String x = 'output';
Type mismatch.
Dart
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
class Order def method end end
class Order def method end end
Correct.
Ruby
<input type='text' value='value'>
<input type='text' value='value' name='value'>
Add name attribute.
HTML
bar = 75
bar=75
No spaces.
Shell
fn baz() -> i32 {{ 45 }}
fn baz() -> i32 {{ 45 }}
Correct.
Rust
if (y = 43) {{}}
if (y == 43) {{}}
Use ==.
Kotlin
function process(x:string){{return x;}} process(96);
function process(x:string){{return x;}} process('hello');
Pass correct type.
TypeScript
const foo;
const foo = 38;
Initialize const.
JavaScript
h1 {{ font-size:83px color:#333; }}
h1 {{ font-size:83px; color:#333; }}
Add semicolon.
CSS
title: value status: world,
title: value status: world
Remove comma.
YAML
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(99);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(99);
Correct.
Node.js
def render(): print('value')
def render(): print('value')
Indent function body.
Python
class Order {{ int temp; }} obj.temp=5;
class Order {{ public int temp; }} obj.temp=5;
Make field public.
Java
switch(item){{ case 39: break; }}
switch(item){{ case 39: break; default: break; }}
Add default case.
Java
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print 'hello'
print 'hello';
Add semicolon.
Perl
let c = 33; c += 1;
let mut c = 33; c += 1;
Need mut to modify.
Rust
["test", 8]
["test", 8]
Correct.
JSON
'value' + 91
'value' + 91.to_s
Convert int.
Ruby
list[63]
if list.indices.contains(63) {{ list[63] }}
Check index.
Swift
<person name='value'/>
<person name="value"/>
Double quotes.
XML
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
if val = 37 {{}}
if val == 37 {{}}
Use ==.
Swift
print 'result'
print('result')
print needs parentheses.
Python
else print('data')
else: print('data')
Colon after else.
Python
function test() {{ echo 'value'; }}
function test() {{ echo 'value'; }}
Correct.
PHP
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
int[] items = new int[82]; items[82] = 5;
int[] items = new int[82]; if (82 < items.length) items[82] = 5;
Check bounds.
Java
{{"id":"result",}}
{{"id":"result"}}
Remove trailing comma.
JSON
jwt.sign({{id:67}}, 'key');
jwt.sign({{id:67}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
<person age=7>
<person age="7">
Quote attribute.
XML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
handle
handle()
Add parentheses.
Kotlin
$temp = 88; if ($temp = 88) {{}}
$temp = 88; if ($temp == 88) {{}}
Use ==.
PHP
x := 70
x := 70
Correct.
Go
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
println('result')
println("result")
Double quotes.
Scala
<hr></hr>
<hr>
Self-closing.
HTML
function baz(temp) print(temp) end
function baz(temp) print(temp) end
Correct.
Lua
if (count = 95)
if (count == 95)
Use ==.
R
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
WHERE name = '93'
WHERE name = 93
Don't quote integer.
SQL
a > 17 & b < 23
a > 17 and b < 23
Use 'and' not '&'.
Python
let x: number = 'result';
let x: string = 'result';
Fix type.
TypeScript
if val = 85
if val == 85
Use ==.
Ruby
var x = 34;
var x = 34;
Correct.
Dart
for y in range(78) print(y)
for y in range(78): print(y)
Colon after for.
Python
$items[93]
if ($items.Count -gt 93) {{ $items[93] }}
Check bounds.
PowerShell
let c: Int = 'data'
let c: String = 'data'
Fix type.
Swift
disp('output')
disp('output')
Correct.
MATLAB
const data = 96; data = 2;
let data = 96; data = 2;
Cannot reassign const.
JavaScript
let list=vec![21,31,41]; let head=&list[0]; list.push(64);
let mut list=vec![21,31,41]; let head=list[0]; list.push(64);
Copy instead of reference.
Rust
// comment
/* comment */
Use /* */.
CSS
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if ($x = 8) {{}}
if ($x -eq 8) {{}}
Use -eq.
PowerShell
val temp = 'test'
val temp = "test"
Double quotes.
Kotlin
if ($x = 67)
if ($x == 67)
Use ==.
Perl
$list[66] = 5;
if (isset($list[66])) $list[66] = 5;
Check existence.
PHP
for (int i=0; i<3; i++) {{}}
for (int i=0; i<3; i++) {{}}
Correct.
Java
my @arr = (84,41,68);
my @arr = (84,41,68);
Correct.
Perl
if ($x = 51)
if ($x == 51)
Use ==.
Perl
x == '33'
x === 33
Use strict equality.
JavaScript
fn baz() -> i32 {{ 58 }}
fn baz() -> i32 {{ 58 }}
Correct.
Rust
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
if (y = 44)
if (y == 44)
Use ==.
C++
class Product {{ int foo; }} obj.foo=5;
class Product {{ public int foo; }} obj.foo=5;
Make field public.
Java
print 'world'
print 'world';
Add semicolon.
Perl
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
data(28)
if length(data) >= 28, data(28), end
Check length.
MATLAB
test
test()
Add parentheses.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
var z int = 'data'
var z string = 'data'
Type mismatch.
Go
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
UPDATE orders SET name='hello' WHERE role=69
UPDATE orders SET name='hello' WHERE role=69;
Add semicolon.
SQL
JOIN profiles ON users.id = profiles.id
JOIN profiles ON users.id = profiles.id
Correct.
SQL
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
String val = 'result';
String val = "result";
Double quotes.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
WHERE email = '30'
WHERE email = 30
Don't quote integer.
SQL
<person age=97>
<person age="97">
Quote attribute.
XML
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let vec=vec![18,69,51]; let head=&vec[0]; vec.push(17);
let mut vec=vec![18,69,51]; let head=vec[0]; vec.push(17);
Copy instead of reference.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
a > 5 & y < 100
a > 5 and y < 100
Use 'and' not '&'.
Python
if a = 97 then print('test') end
if a == 97 then print('test') end
Use ==.
Lua
arr[73]
if (arr.indices.contains(73)) arr[73]
Check index.
Kotlin
var x = 77;
var x = 77;
Correct.
Dart