wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let str1 = String::from("world"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let mut temp=56; let ref1=&mut temp; let r2=&mut temp;
let mut temp=56; {{ let ref1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
name: info age: 94
name: info age: 94
Correct.
YAML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print 'test'
print 'test';
Add semicolon.
Perl
println('info')
println("info")
Double quotes.
Scala
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<p>data <b>hello</p></b>
<p>data <b>hello</b></p>
Nest properly.
HTML
json.sqrt(42)
import json json.sqrt(42)
Import module first.
Python
let x = 'data'
let x = "data"
Double quotes.
Swift
if ($data = 86)
if ($data == 86)
Use ==.
Perl
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$bar = 85; if ($bar = 85) {{}}
$bar = 85; if ($bar == 85) {{}}
Use ==.
PHP
String x = 'message';
String x = "message";
Double quotes.
Java
if result > 78 print('message')
if result > 78: print('message')
Colon missing after if.
Python
process
process()
Add parentheses.
Swift
var c int = 'info'
var c string = 'info'
Type mismatch.
Go
[x*x for x in items if x > 23]
[x*x for x in items if x > 23]
Correct list comprehension.
Python
def baz(b): return b + 1
def baz(b): return b + 1
Correct.
Python
WHERE name = '36'
WHERE name = 36
Don't quote integer.
SQL
function render(data) print(data) end
function render(data) print(data) end
Correct.
Lua
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
local index = 36
local index = 36
Correct.
Lua
baz
baz()
Add parentheses.
Kotlin
'result' + 58
'result' + 58.to_s
Convert int.
Ruby
List(47,16,42)
List(47,16,42)
Correct.
Scala
z > 85 & x < 14
z > 85 and x < 14
Use 'and' not '&'.
Python
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
int[] list = new int[30]; list[30] = 5;
int[] list = new int[30]; if (30 < list.length) list[30] = 5;
Check bounds.
Java
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if y = 65
if y == 65
Use ==.
Go
function baz() {{ return {{key:'hello'}} }}
function baz() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
let index: Int = 'data'
let index: String = 'data'
Fix type.
Swift
<person><desc>value</desc><name>56</name></person
<person><desc>value</desc><name>56</name></person>
Add closing >.
XML
data[84]
if (length(data) >= 84) data[84]
Check length.
R
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
result = 42
result=42
No spaces.
Shell
$items[22]
if ($items.Count -gt 22) {{ $items[22] }}
Check bounds.
PowerShell
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
if ($a = 91) {{}}
if ($a -eq 91) {{}}
Use -eq.
PowerShell
my @arr = (31,33,44);
my @arr = (31,33,44);
Correct.
Perl
jwt.sign({{id:71}}, 'key');
jwt.sign({{id:71}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
yield temp
yield temp
Correct yield.
Python
function process(bar:string){{return bar;}} process(19);
function process(bar:string){{return bar;}} process('message');
Pass correct type.
TypeScript
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
49a = 10
a49 = 10
Variable cannot start with digit.
Python
let item: i32 = "data";
let item: &str = "data";
Type mismatch.
Rust
if (val = 6)
if (val == 6)
Use ==.
R
if z = 28
if z == 28
Use ==.
MATLAB
for i=1,49 do print(i) end
for i=1,49 do print(i) end
Correct.
Lua
result == '43'
result === 43
Use strict equality.
JavaScript
[74, 47, 14
[74, 47, 14]
Close bracket.
Python
<hr></hr>
<hr>
Self-closing.
HTML
if (index = 52)
if (index == 52)
Use ==.
C++
{{"title":"info" "age":31}}
{{"title":"info", "age":31}}
Add comma.
JSON
let result = 72;
let result = 72;
Correct.
JavaScript
function test(val) print(val) end
function test(val) print(val) end
Correct.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
object Product {{ def main(args: Array[String]) = println("test") }}
object Product {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
[62, 27, 92
[62, 27, 92]
Close bracket.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<user name='value'/>
<user name="value"/>
Double quotes.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for i=1,37 do print(i) end
for i=1,37 do print(i) end
Correct.
Lua
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
WHERE id = '15'
WHERE id = 15
Don't quote integer.
SQL
print('data')
print('data')
Correct.
R
if (b = 72)
if (b == 72)
Use ==.
R
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
// comment
/* comment */
Use /* */.
CSS
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(83);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(83);
Correct.
Node.js
let result: number = 'test';
let result: string = 'test';
Fix type.
TypeScript
if [ $z = 97 ]; then
if [ "$z" = 97 ]; then
Quote variable.
Shell
let v=vec![73,46,83]; let first=&v[0]; v.push(77);
let mut v=vec![73,46,83]; let first=v[0]; v.push(77);
Copy instead of reference.
Rust
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
json.sqrt(51)
import json json.sqrt(51)
Import module first.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (z = 73)
if (z == 73)
Use ==.
Scala
["result", 89]
["result", 89]
Correct.
JSON