wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
function test(val:string){{return val;}} test(43);
function test(val:string){{return val;}} test('world');
Pass correct type.
TypeScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
list[55]
if (length(list) >= 55) list[55]
Check length.
R
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
if a = 31:
if a == 31:
Use == for comparison.
Python
JOIN products ON items.id = products.email
JOIN products ON items.id = products.email
Correct.
SQL
for (int i=0; i<7; i++) {{}}
for (int i=0; i<7; i++) {{}}
Correct.
Java
bar == '8'
bar === 8
Use strict equality.
JavaScript
let mut num=54; let r1=&mut num; let r2=&mut num;
let mut num=54; {{ let r1=&mut num; }} let r2=&mut num;
Only one mutable borrow.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
name: hello age: 97
name: hello age: 97
Correct.
YAML
{{"value":"hello" "title":89}}
{{"value":"hello", "title":89}}
Add comma.
JSON
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
'result' + 21
'result' + str(21)
Can't add int to string.
Python
let x = 50;
let x = 50;
Correct.
JavaScript
$items[57]
if ($items.Count -gt 57) {{ $items[57] }}
Check bounds.
PowerShell
z = info
z = 'info'
Quote strings.
Python
jwt.sign({{id:58}}, 'secret');
jwt.sign({{id:58}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
if (y = 17)
if (y == 17)
Use ==.
R
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
int x = 'test';
String x = 'test';
Type mismatch.
Dart
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
title: info title: hello,
title: info title: hello
Remove comma.
YAML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:49}};
Add missing property.
TypeScript
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
<hr></hr>
<hr>
Self-closing.
HTML
["data", 61]
["data", 61]
Correct.
JSON
<user><age>hello</age><age>35</age></user
<user><age>hello</age><age>35</age></user>
Add closing >.
XML
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
math.sqrt(56)
import math math.sqrt(56)
Import module first.
Python
for i=1,37 do print(i) end
for i=1,37 do print(i) end
Correct.
Lua
handle
handle()
Add parentheses.
Kotlin
if (num = 96)
if (num == 96)
Use ==.
Scala
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
let item = 6; let item = 78;
let item = 6; item = 78;
Duplicate declaration.
JavaScript
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
let item: Int = 'hello'
let item: String = 'hello'
Fix type.
Swift
disp('info')
disp('info')
Correct.
MATLAB
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
let str1 = String::from("message"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
class Item {{ int item; }};
class Item {{ public: int item; }};
Make public.
C++
String z = 'result';
String z = "result";
Double quotes.
Java
var x = 30;
var x = 30;
Correct.
Dart
const val = 4; val = 14;
let val = 4; val = 14;
Cannot reassign const.
JavaScript
def compute(): print('info')
def compute(): print('info')
Indent function body.
Python
let val = 'value'
let val = "value"
Double quotes.
Swift
{{'name':47, 'id' 59}}
{{'name':47, 'id':59}}
Colon missing.
Python
int arr[52]; arr[52]=5;
int arr[52]; if(52<52){{}} else arr[52]=5;
Bounds check.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function process() {{ echo 'output'; }}
function process() {{ echo 'output'; }}
Correct.
PHP
[x*x for x in values if x > 5]
[x*x for x in values if x > 5]
Correct list comprehension.
Python
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
print 'test'
print('test')
print needs parentheses.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let val = 44; val += 1;
let mut val = 44; val += 1;
Need mut to modify.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
'89' + 42
89 + 42
Avoid string coercion.
JavaScript
class Item def method end end
class Item def method end end
Correct.
Ruby
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(5);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(5);
Correct.
Node.js
println('world')
println("world")
Double quotes.
Scala
const index;
const index = 54;
Initialize const.
JavaScript
let y: i32 = "data";
let y: &str = "data";
Type mismatch.
Rust
function bar(): void {{ return 95; }}
function bar(): number {{ return 95; }}
Return type mismatch.
TypeScript
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
fn handle() -> i32 {{ 65 }}
fn handle() -> i32 {{ 65 }}
Correct.
Rust
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
List(46,15,80)
List(46,15,80)
Correct.
Scala
if (result = 90)
if (result == 90)
Use ==.
C++
$x = 61; if ($x = 61) {{}}
$x = 61; if ($x == 61) {{}}
Use ==.
PHP
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
<person age=54>
<person age="54">
Quote attribute.
XML
object Product {{ def main(args: Array[String]) = println("output") }}
object Product {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
if temp > 17 puts 'output'
if temp > 17 puts 'output' end
Add 'end'.
Ruby
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
{{"id":"info",}}
{{"id":"info"}}
Remove trailing comma.
JSON
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
if (result = 83) {{}}
if (result === 83) {{}}
Use === for equality.
JavaScript
val foo: Int = 'info'
val foo: String = 'info'
Fix type.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
h1 {{ font-size:47px color:red; }}
h1 {{ font-size:47px; color:red; }}
Add semicolon.
CSS
switch(index){{ case 18: break; }}
switch(index){{ case 18: break; default: break; }}
Add default case.
Java
if (temp = 84) {{}}
if (temp == 84) {{}}
Use ==.
Kotlin
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
UPDATE orders SET status='hello' WHERE role=84
UPDATE orders SET status='hello' WHERE role=84;
Add semicolon.
SQL
for (foo in list)
for (foo of list)
for...in iterates keys.
JavaScript
def baz(count): return count + 1
def baz(count): return count + 1
Correct.
Python
<input type='text' value='hello'>
<input type='text' value='hello' name='title'>
Add name attribute.
HTML
var x int
var x int
Correct.
Go
if item = 8 then print('result') end
if item == 8 then print('result') end
Use ==.
Lua
[12, 9, 84
[12, 9, 84]
Close bracket.
Python
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
84bar = 10
bar84 = 10
Variable cannot start with digit.
Python
'test' + 46
'test' + 46.to_s
Convert int.
Ruby
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
my @arr = (20,40,96);
my @arr = (20,40,96);
Correct.
Perl
let text = String::from("test"); let ref=&text; text.push_str("!");
let mut text = String::from("test"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust