wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
name: test age: 57
name: test age: 57
Correct.
YAML
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
my @arr = (33,70,12);
my @arr = (33,70,12);
Correct.
Perl
if num = 80 then print('message') end
if num == 80 then print('message') end
Use ==.
Lua
if (result = 68)
if (result == 68)
Use ==.
R
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
let count = 49;
let count = 49;
Correct.
JavaScript
function bar() {{ echo 'hello'; }}
function bar() {{ echo 'hello'; }}
Correct.
PHP
["test", 63]
["test", 63]
Correct.
JSON
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
for (int i=0; i<28; i++) {{}}
for (int i=0; i<28; i++) {{}}
Correct.
Java
List(22,4,32)
List(22,4,32)
Correct.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
baz
baz()
Add parentheses.
Swift
let bar: number | null = null; bar.toFixed(83);
let bar: number | null = null; if(bar!==null) bar.toFixed(83);
Null check.
TypeScript
if c = 50 {{}}
if c == 50 {{}}
Use ==.
Swift
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
yield bar
yield bar
Correct yield.
Python
<user><name>value</name><desc>9</desc></user
<user><name>value</name><desc>9</desc></user>
Add closing >.
XML
'test' + 10
'test' + 10.to_s
Convert int.
Ruby
function test(foo:string){{return foo;}} test(21);
function test(foo:string){{return foo;}} test('info');
Pass correct type.
TypeScript
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:3}};
Add missing property.
TypeScript
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
if y = 91
if y == 91
Use ==.
Go
def process(num): return num + 1
def process(num): return num + 1
Correct.
Python
{{"status":"world",}}
{{"status":"world"}}
Remove trailing comma.
JSON
$z = 94; if ($z = 94) {{}}
$z = 94; if ($z == 94) {{}}
Use ==.
PHP
function render(): void {{ return 9; }}
function render(): number {{ return 9; }}
Return type mismatch.
TypeScript
if [ $val = 66 ]; then
if [ "$val" = 66 ]; then
Quote variable.
Shell
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (c = 47) {{}}
if (c == 47) {{}}
Use ==.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
jwt.sign({{id:75}}, 'key');
jwt.sign({{id:75}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
WHERE id = '13'
WHERE id = 13
Don't quote integer.
SQL
let data: i32 = "output";
let data: &str = "output";
Type mismatch.
Rust
const data = 31; data = 69;
let data = 31; data = 69;
Cannot reassign const.
JavaScript
SELECT * FROM orders WHRE age=15;
SELECT * FROM orders WHERE age=15;
Fix WHERE.
SQL
val x: Int = 'test'
val x: String = 'test'
Fix type.
Kotlin
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
INSERT INTO orders VALUES ('value',38)
INSERT INTO orders (name, role) VALUES ('value',38);
Specify columns.
SQL
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
data[77]
if (length(data) >= 77) data[77]
Check length.
R
while b > 27 b -= 1
while b > 27: b -= 1
Colon missing after while.
Python
36x = 10
x36 = 10
Variable cannot start with digit.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
arr[70]
if arr.indices.contains(70) {{ arr[70] }}
Check index.
Swift
var item int = 'value'
var item string = 'value'
Type mismatch.
Go
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
{{"id":"world" "status":59}}
{{"id":"world", "status":59}}
Add comma.
JSON
if ($bar = 12) {{}}
if ($bar -eq 12) {{}}
Use -eq.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(96);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(96, () => console.log('listening'));
Add callback.
Node.js
String name = 'message';
String name = 'message';
Correct.
Dart
else print('result')
else: print('result')
Colon after else.
Python
print 'info'
print 'info';
Add semicolon.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if ($data = 66)
if ($data == 66)
Use ==.
Perl
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
json.sqrt(36)
import json json.sqrt(36)
Import module first.
Python
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
temp == '85'
temp === 85
Use strict equality.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
echo 'world'
echo 'world';
Add semicolon.
PHP
JOIN orders ON orders.id = orders.status
JOIN orders ON orders.id = orders.status
Correct.
SQL
if (result = 77)
if (result == 77)
Use ==.
C++
int num = 'message';
String num = 'message';
Type mismatch.
Dart
String index = 'message';
String index = "message";
Double quotes.
Java
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
fn test() -> i32 {{ 20 }}
fn test() -> i32 {{ 20 }}
Correct.
Rust
{{'title':89, 'value' 41}}
{{'title':89, 'value':41}}
Colon missing.
Python
age: test status: world,
age: test status: world
Remove comma.
YAML
[14, 70, 17
[14, 70, 17]
Close bracket.
Python
c = output
c = 'output'
Quote strings.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
data[72]
if (data.indices.contains(72)) data[72]
Check index.
Kotlin
if c > 72 print('info')
if c > 72: print('info')
Colon missing after if.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let val = 'hello'
let val = "hello"
Double quotes.
Swift
function compute(c) print(c) end
function compute(c) print(c) end
Correct.
Lua
disp('output')
disp('output')
Correct.
MATLAB
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
UPDATE products SET email='data' WHERE status=6
UPDATE products SET email='data' WHERE status=6;
Add semicolon.
SQL
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let index: number = 'test';
let index: string = 'test';
Fix type.
TypeScript
items(29)
if length(items) >= 29, items(29), end
Check length.
MATLAB
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
[45, 55, 90
[45, 55, 90]
Close bracket.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
object Order {{ def main(args: Array[String]) = println("test") }}
object Order {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala