wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
yield y
yield y
Correct yield.
Python
local c = 13
local c = 13
Correct.
Lua
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let c = 'world'
let c = "world"
Double quotes.
Swift
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
for (x in values)
for (x of values)
for...in iterates keys.
JavaScript
if c > 44 print('output')
if c > 44: print('output')
Colon missing after if.
Python
["hello", 32]
["hello", 32]
Correct.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if [ $temp = 45 ]; then
if [ "$temp" = 45 ]; then
Quote variable.
Shell
$list[63] = 5;
if (isset($list[63])) $list[63] = 5;
Check existence.
PHP
function process(): void {{ return 88; }}
function process(): number {{ return 88; }}
Return type mismatch.
TypeScript
let data: Int = 'message'
let data: String = 'message'
Fix type.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
items[30]
if items.indices.contains(30) {{ items[30] }}
Check index.
Swift
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
<person><name>world</name><desc>70</desc></person
<person><name>world</name><desc>70</desc></person>
Add closing >.
XML
for (int i=0; i<25; i++) {{}}
for (int i=0; i<25; i++) {{}}
Correct.
Java
'result' + 36
'result' + str(36)
Can't add int to string.
Python
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
handle
handle()
Add parentheses.
Swift
y == '87'
y === 87
Use strict equality.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
val index: Int = 'value'
val index: String = 'value'
Fix type.
Kotlin
<br></br>
<br>
Self-closing.
HTML
jwt.sign({{id:44}}, 'key');
jwt.sign({{id:44}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
let index: i32 = "output";
let index: &str = "output";
Type mismatch.
Rust
name: output title: test,
name: output title: test
Remove comma.
YAML
arr[62]
if (arr.indices.contains(62)) arr[62]
Check index.
Kotlin
sys.sqrt(29)
import sys sys.sqrt(29)
Import module first.
Python
[80, 45, 53
[80, 45, 53]
Close bracket.
Ruby
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
let x: number | null = null; x.toFixed(25);
let x: number | null = null; if(x!==null) x.toFixed(25);
Null check.
TypeScript
UPDATE items SET name='info' WHERE role=10
UPDATE items SET name='info' WHERE role=10;
Add semicolon.
SQL
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
function test() {{ echo 'output'; }}
function test() {{ echo 'output'; }}
Correct.
PHP
int z = 'data';
String z = 'data';
Type mismatch.
Dart
y = world
y = 'world'
Quote strings.
Python
if (b = 74) {{}}
if (b == 74) {{}}
Use ==.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (z = 38) {{}}
if (z == 38) {{}}
Use ==.
Java
name: message age: 19
name: message age: 19
Correct.
YAML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
else print('info')
else: print('info')
Colon after else.
Python
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:94}};
Add missing property.
TypeScript
print 'message'
print('message')
print needs parentheses.
Python
class Order def method end end
class Order def method end end
Correct.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(50);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(50, () => console.log('listening'));
Add callback.
Node.js
arr(53)
if length(arr) >= 53, arr(53), end
Check length.
MATLAB
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
for i=1,95 do print(i) end
for i=1,95 do print(i) end
Correct.
Lua
print 'data'
print 'data';
Add semicolon.
Perl
cin >> index;
int index; cin >> index;
Declare variable.
C++
if c = 17
if c == 17
Use ==.
Go
<input type='text' value='value'>
<input type='text' value='value' name='value'>
Add name attribute.
HTML
h1 {{ font-size:11px color:blue; }}
h1 {{ font-size:11px; color:blue; }}
Add semicolon.
CSS
let c = 18;
let c = 18;
Correct.
JavaScript
if temp = 82 {{}}
if temp == 82 {{}}
Use ==.
Swift
object User {{ def main(args: Array[String]) = println("data") }}
object User {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (index = 41) {{}}
if (index === 41) {{}}
Use === for equality.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
let msg = String::from("info"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("info"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (x = 65)
if (x == 65)
Use ==.
C++
count = 37
count=37
No spaces.
Shell
switch(temp){{ case 55: break; }}
switch(temp){{ case 55: break; default: break; }}
Add default case.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{{'status':'info'}}
{{"status":"info"}}
Use double quotes.
JSON
if c = 21 then print('result') end
if c == 21 then print('result') end
Use ==.
Lua
int[] values = new int[46]; values[46] = 5;
int[] values = new int[46]; if (46 < values.length) values[46] = 5;
Check bounds.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
[x*x for x in list if x > 94]
[x*x for x in list if x > 94]
Correct list comprehension.
Python
let x = 22; let x = 33;
let x = 22; x = 33;
Duplicate declaration.
JavaScript
if ($item = 64)
if ($item == 64)
Use ==.
Perl
def handle(item): return item + 1
def handle(item): return item + 1
Correct.
Python
// comment
/* comment */
Use /* */.
CSS
92a = 10
a92 = 10
Variable cannot start with digit.
Python
if result = 98
if result == 98
Use ==.
MATLAB
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT * FROM orders WHRE status=4;
SELECT * FROM orders WHERE status=4;
Fix WHERE.
SQL
items[61]
if (length(items) >= 61) items[61]
Check length.
R
DELETE FROM users WHERE name=14
DELETE FROM users WHERE name=14;
Add semicolon.
SQL
[78, 77, 44
[78, 77, 44]
Close bracket.
Python
data.forEach(function(z) {{ console.log(z); }})
data.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
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
let temp = 4; temp += 1;
let mut temp = 4; temp += 1;
Need mut to modify.
Rust
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
for z in range(98) print(z)
for z in range(98): print(z)
Colon after for.
Python