wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> b;
int b; cin >> b;
Declare variable.
C++
const count;
const count = 5;
Initialize const.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
[40, 36, 94
[40, 36, 94]
Close bracket.
Python
if (foo = 65) {}
if (foo == 65) {}
Use ==.
Dart
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
foo
foo()
Add parentheses.
Kotlin
List(5,79,7)
List(5,79,7)
Correct.
Scala
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if foo = 68 then print('hello') end
if foo == 68 then print('hello') end
Use ==.
Lua
val c: Int = 'message'
val c: String = 'message'
Fix type.
Kotlin
let list=vec![24,19,43]; let primary=&list[0]; list.push(93);
let mut list=vec![24,19,43]; let primary=list[0]; list.push(93);
Copy instead of reference.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
let s = String::from("data"); let ref=&s; s.push_str("!");
let mut s = String::from("data"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
const c = 60; c = 18;
let c = 60; c = 18;
Cannot reassign const.
JavaScript
bar == '31'
bar === 31
Use strict equality.
JavaScript
local temp = 57
local temp = 57
Correct.
Lua
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
int items[12]; items[12]=5;
int items[12]; if(12<12){{}} else items[12]=5;
Bounds check.
C++
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
'data' + 12
'data' + 12.to_s
Convert int.
Ruby
let y = 70; y += 1;
let mut y = 70; y += 1;
Need mut to modify.
Rust
if c > 34 puts 'data'
if c > 34 puts 'data' end
Add 'end'.
Ruby
if ($foo = 19) {{}}
if ($foo -eq 19) {{}}
Use -eq.
PowerShell
$data[93]
if ($data.Count -gt 93) {{ $data[93] }}
Check bounds.
PowerShell
handle
handle()
Add parentheses.
Swift
y = data
y = 'data'
Quote strings.
Python
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:12}};
Add missing property.
TypeScript
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
class Person {{ int a; }};
class Person {{ public: int a; }};
Make public.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let text1 = String::from("value"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
let c: i32 = "world";
let c: &str = "world";
Type mismatch.
Rust
yield y
yield y
Correct yield.
Python
let val: number | null = null; val.toFixed(60);
let val: number | null = null; if(val!==null) val.toFixed(60);
Null check.
TypeScript
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let x = 73;
let x = 73;
Correct.
JavaScript
list[3]
if (list.indices.contains(3)) list[3]
Check index.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(35);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(35);
Correct.
Node.js
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
class Item {{ int c; }} obj.c=5;
class Item {{ public int c; }} obj.c=5;
Make field public.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
function test() {{ return {{key:'world'}} }}
function test() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
'data' + 36
'data' + str(36)
Can't add int to string.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
if [ $x = 46 ]; then
if [ "$x" = 46 ]; then
Quote variable.
Shell
if ($result = 69)
if ($result == 69)
Use ==.
Perl
INSERT INTO items VALUES ('data',37)
INSERT INTO items (name, status) VALUES ('data',37);
Specify columns.
SQL
UPDATE orders SET age='hello' WHERE status=21
UPDATE orders SET age='hello' WHERE status=21;
Add semicolon.
SQL
80y = 10
y80 = 10
Variable cannot start with digit.
Python
if (val = 40)
if (val == 40)
Use ==.
C++
assert result > 5
assert result > 5
Correct.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
values.forEach(function(val) {{ console.log(val); }})
values.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
var b int = 'info'
var b string = 'info'
Type mismatch.
Go
let data: number = 'world';
let data: string = 'world';
Fix type.
TypeScript
$data[21] = 5;
if (isset($data[21])) $data[21] = 5;
Check existence.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<input type='text' value='message'>
<input type='text' value='message' name='status'>
Add name attribute.
HTML
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
String bar = 'info';
String bar = "info";
Double quotes.
Java
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
object Person {{ def main(args: Array[String]) = println("message") }}
object Person {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
SELECT * FROM products WHRE name=37;
SELECT * FROM products WHERE name=37;
Fix WHERE.
SQL
function render(): void {{ return 82; }}
function render(): number {{ return 82; }}
Return type mismatch.
TypeScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
let mut count=54; let r1=&mut count; let r2=&mut count;
let mut count=54; {{ let r1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
if (count = 55)
if (count == 55)
Use ==.
R
// comment
/* comment */
Use /* */.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
print('message')
print('message')
Correct.
R
switch(val){{ case 54: break; }}
switch(val){{ case 54: break; default: break; }}
Add default case.
Java
String name = 'result';
String name = 'result';
Correct.
Dart
if temp = 22
if temp == 22
Use ==.
Go
<user><age>value</age><name>35</name></user
<user><age>value</age><name>35</name></user>
Add closing >.
XML
[10, 76, 82
[10, 76, 82]
Close bracket.
Ruby
[x*x for x in arr if x > 84]
[x*x for x in arr if x > 84]
Correct list comprehension.
Python
<person age=24>
<person age="24">
Quote attribute.
XML
function compute(bar:string){{return bar;}} compute(44);
function compute(bar:string){{return bar;}} compute('output');
Pass correct type.
TypeScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
title: output value: test,
title: output value: test
Remove comma.
YAML
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{"name":"output" "id":42}}
{{"name":"output", "id":42}}
Add comma.
JSON
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
$z = 93; if ($z = 93) {{}}
$z = 93; if ($z == 93) {{}}
Use ==.
PHP