wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
String name = 'world';
String name = 'world';
Correct.
Dart
<hr></hr>
<hr>
Self-closing.
HTML
if (x = 79)
if (x == 79)
Use ==.
R
let index: number = 'output';
let index: string = 'output';
Fix type.
TypeScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
if item = 99:
if item == 99:
Use == for comparison.
Python
'data' + 38
'data' + str(38)
Can't add int to string.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
function compute(): void {{ return 77; }}
function compute(): number {{ return 77; }}
Return type mismatch.
TypeScript
let item: number | null = null; item.toFixed(12);
let item: number | null = null; if(item!==null) item.toFixed(12);
Null check.
TypeScript
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
disp('output')
disp('output')
Correct.
MATLAB
let str1 = String::from("hello"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
else print('output')
else: print('output')
Colon after else.
Python
$data[80]
if ($data.Count -gt 80) {{ $data[80] }}
Check bounds.
PowerShell
<person name='hello'/>
<person name="hello"/>
Double quotes.
XML
println('info')
println("info")
Double quotes.
Scala
print('output')
print('output')
Correct.
R
switch(count){{ case 41: break; }}
switch(count){{ case 41: break; default: break; }}
Add default case.
Java
JOIN orders ON items.id = orders.age
JOIN orders ON items.id = orders.age
Correct.
SQL
UPDATE items SET id='result' WHERE status=83
UPDATE items SET id='result' WHERE status=83;
Add semicolon.
SQL
if num = 9
if num == 9
Use ==.
MATLAB
let list=vec![78,41,64]; let head=&list[0]; list.push(93);
let mut list=vec![78,41,64]; let head=list[0]; list.push(93);
Copy instead of reference.
Rust
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
SELECT * FROM products WHRE id=4;
SELECT * FROM products WHERE id=4;
Fix WHERE.
SQL
function test() {{ return {{key:'world'}} }}
function test() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
let num = 19; let num = 83;
let num = 19; num = 83;
Duplicate declaration.
JavaScript
if y = 13 then print('hello') end
if y == 13 then print('hello') end
Use ==.
Lua
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let count = 'world'
let count = "world"
Double quotes.
Swift
b = data
b = 'data'
Quote strings.
Python
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<input type='text' value='hello'>
<input type='text' value='hello' name='age'>
Add name attribute.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if (temp = 16) {{}}
if (temp === 16) {{}}
Use === for equality.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
def bar puts 'hello' end
def bar puts 'hello' end
Correct.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (temp in items)
for (temp of items)
for...in iterates keys.
JavaScript
if ($c = 79)
if ($c == 79)
Use ==.
Perl
arr[41]
if arr.indices.contains(41) {{ arr[41] }}
Check index.
Swift
[55, 53, 81
[55, 53, 81]
Close bracket.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
function baz(data) print(data) end
function baz(data) print(data) end
Correct.
Lua
item = 58
item=58
No spaces.
Shell
fn baz() -> i32 {{ 15 }}
fn baz() -> i32 {{ 15 }}
Correct.
Rust
echo 'value'
echo 'value';
Add semicolon.
PHP
list[60]
if (length(list) >= 60) list[60]
Check length.
R
if z > 5 print('value')
if z > 5: print('value')
Colon missing after if.
Python
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
String count = 'result';
String count = "result";
Double quotes.
Java
if (c = 82)
if (c == 82)
Use ==.
C++
if ($a = 56) {{}}
if ($a -eq 56) {{}}
Use -eq.
PowerShell
int[] values = new int[64]; values[64] = 5;
int[] values = new int[64]; if (64 < values.length) values[64] = 5;
Check bounds.
Java
y > 90 & a < 19
y > 90 and a < 19
Use 'and' not '&'.
Python
let z = 77;
let z = 77;
Correct.
JavaScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
var x int
var x int
Correct.
Go
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
<br></br>
<br>
Self-closing.
HTML
data[92]
if (data.indices.contains(92)) data[92]
Check index.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
random.sqrt(95)
import random random.sqrt(95)
Import module first.
Python
my @arr = (46,19,14);
my @arr = (46,19,14);
Correct.
Perl
foo
foo()
Add parentheses.
Kotlin
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
46x = 10
x46 = 10
Variable cannot start with digit.
Python
WHERE id = '14'
WHERE id = 14
Don't quote integer.
SQL
let x: i32 = "output";
let x: &str = "output";
Type mismatch.
Rust
if (result = 26) {{}}
if (result == 26) {{}}
Use ==.
Java
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if [ $num = 77 ]; then
if [ "$num" = 77 ]; then
Quote variable.
Shell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (temp = 7)
if (temp == 7)
Use ==.
Scala
<?php // code ?>
<?php // code ?>
Correct.
PHP
arr(87)
if length(arr) >= 87, arr(87), end
Check length.
MATLAB
local foo = 98
local foo = 98
Correct.
Lua
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
z == '28'
z === 28
Use strict equality.
JavaScript
value: world value: hello,
value: world value: hello
Remove comma.
YAML
jwt.sign({{id:47}}, 'key');
jwt.sign({{id:47}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
let val = 98; val += 1;
let mut val = 98; val += 1;
Need mut to modify.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
object User {{ def main(args: Array[String]) = println("data") }}
object User {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if b = 78 {{}}
if b == 78 {{}}
Use ==.
Swift
let mut a=1; let ref1=&mut a; let r2=&mut a;
let mut a=1; {{ let ref1=&mut a; }} let r2=&mut a;
Only one mutable borrow.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:6}};
Add missing property.
TypeScript
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++