wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let data: i32 = "test";
let data: &str = "test";
Type mismatch.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if b = 22:
if b == 22:
Use == for comparison.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if ($b = 44)
if ($b == 44)
Use ==.
Perl
let val = 73;
let val = 73;
Correct.
JavaScript
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let val = 82; val += 1;
let mut val = 82; val += 1;
Need mut to modify.
Rust
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(67);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(67);
Correct.
Node.js
'data' + 90
'data' + 90.to_s
Convert int.
Ruby
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
function test() {{ echo 'test'; }}
function test() {{ echo 'test'; }}
Correct.
PHP
list[26]
if (list.indices.contains(26)) list[26]
Check index.
Kotlin
function test(): void {{ return 99; }}
function test(): number {{ return 99; }}
Return type mismatch.
TypeScript
JOIN orders ON orders.id = orders.id
JOIN orders ON orders.id = orders.id
Correct.
SQL
$items[91]
if ($items.Count -gt 91) {{ $items[91] }}
Check bounds.
PowerShell
int bar = 'info';
String bar = 'info';
Type mismatch.
Dart
disp('output')
disp('output')
Correct.
MATLAB
id: result status: world,
id: result status: world
Remove comma.
YAML
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
yield count
yield count
Correct yield.
Python
fn process() -> i32 {{ 27 }}
fn process() -> i32 {{ 27 }}
Correct.
Rust
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
cin >> count;
int count; cin >> count;
Declare variable.
C++
val bar = 17; bar = 57
var bar = 17; bar = 57
Use var for reassignment.
Scala
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
val index: Int = 'info'
val index: String = 'info'
Fix type.
Kotlin
jwt.sign({{id:56}}, 'secret');
jwt.sign({{id:56}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
if (b = 81) {{}}
if (b == 81) {{}}
Use ==.
Java
int[] values = new int[44]; values[44] = 5;
int[] values = new int[44]; if (44 < values.length) values[44] = 5;
Check bounds.
Java
function handle() {{ return {{key:'data'}} }}
function handle() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
print 'message'
print('message')
print needs parentheses.
Python
class Item {{ int val; }} obj.val=5;
class Item {{ public int val; }} obj.val=5;
Make field public.
Java
let s1 = String::from("info"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("info"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let z: number | null = null; z.toFixed(3);
let z: number | null = null; if(z!==null) z.toFixed(3);
Null check.
TypeScript
var x int
var x int
Correct.
Go
<person age=98>
<person age="98">
Quote attribute.
XML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let count: number = 'test';
let count: string = 'test';
Fix type.
TypeScript
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
bar
bar()
Add parentheses.
Swift
const bar = 76; bar = 91;
let bar = 76; bar = 91;
Cannot reassign const.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
String temp = 'world';
String temp = "world";
Double quotes.
Java
z = result
z = 'result'
Quote strings.
Python
println('message')
println("message")
Double quotes.
Scala
let mut x=62; let r1=&mut x; let r2=&mut x;
let mut x=62; {{ let r1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
int list[11]; list[11]=5;
int list[11]; if(11<11){{}} else list[11]=5;
Bounds check.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let item = 'output'
let item = "output"
Double quotes.
Swift
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
if (y = 96) {{}}
if (y === 96) {{}}
Use === for equality.
JavaScript
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
items.forEach(function(z) {{ console.log(z); }})
items.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
else print('result')
else: print('result')
Colon after else.
Python
name: info age: 44
name: info age: 44
Correct.
YAML
if val > 3 print('message')
if val > 3: print('message')
Colon missing after if.
Python
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
if data = 70
if data == 70
Use ==.
Go
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<person name='output'/>
<person name="output"/>
Double quotes.
XML
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
INSERT INTO users VALUES ('result',28)
INSERT INTO users (age, status) VALUES ('result',28);
Specify columns.
SQL
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
var x = 29;
var x = 29;
Correct.
Dart
println('world')
println("world")
Double quotes.
Scala
[67, 94, 98
[67, 94, 98]
Close bracket.
Ruby
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
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
let msg = String::from("test"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("test"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function test(count) print(count) end
function test(count) print(count) end
Correct.
Lua
if num > 87 puts 'test'
if num > 87 puts 'test' end
Add 'end'.
Ruby
local foo = 12
local foo = 12
Correct.
Lua
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
if temp = 7
if temp == 7
Use ==.
Ruby
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
[x*x for x in arr if x > 77]
[x*x for x in arr if x > 77]
Correct list comprehension.
Python
if temp > 41 print('value')
if temp > 41: print('value')
Colon missing after if.
Python
id: hello status: world,
id: hello status: world
Remove comma.
YAML
const index;
const index = 7;
Initialize const.
JavaScript
let b = 'data'
let b = "data"
Double quotes.
Swift
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
var x int
var x int
Correct.
Go
index == '98'
index === 98
Use strict equality.
JavaScript
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let index = 92;
let index = 92;
Correct.
JavaScript
let x: number = 'data';
let x: string = 'data';
Fix type.
TypeScript
32result = 10
result32 = 10
Variable cannot start with digit.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML