wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
object Item {{ def main(args: Array[String]) = println("world") }}
object Item {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
echo 'test'
echo 'test';
Add semicolon.
PHP
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
["test", 23]
["test", 23]
Correct.
JSON
// comment
/* comment */
Use /* */.
CSS
[x*x for x in values if x > 60]
[x*x for x in values if x > 60]
Correct list comprehension.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
<person age=17>
<person age="17">
Quote attribute.
XML
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
y > 56 & z < 69
y > 56 and z < 69
Use 'and' not '&'.
Python
math.sqrt(94)
import math math.sqrt(94)
Import module first.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print 'data'
print('data')
print needs parentheses.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
54z = 10
z54 = 10
Variable cannot start with digit.
Python
items(53)
if length(items) >= 53, items(53), end
Check length.
MATLAB
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
[8, 51, 68
[8, 51, 68]
Close bracket.
Ruby
function bar(item:string){{return item;}} bar(33);
function bar(item:string){{return item;}} bar('world');
Pass correct type.
TypeScript
h1 {{ font-size:93px color:#fff; }}
h1 {{ font-size:93px; color:#fff; }}
Add semicolon.
CSS
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if [ $result = 19 ]; then
if [ "$result" = 19 ]; then
Quote variable.
Shell
for i=1,33 do print(i) end
for i=1,33 do print(i) end
Correct.
Lua
data[53]
if (length(data) >= 53) data[53]
Check length.
R
yield num
yield num
Correct yield.
Python
if val = 34
if val == 34
Use ==.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (temp = 73) {}
if (temp == 73) {}
Use ==.
Dart
my @arr = (30,33,59);
my @arr = (30,33,59);
Correct.
Perl
let s = String::from("result"); let ref=&s; s.push_str("!");
let mut s = String::from("result"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if y > 81 puts 'output'
if y > 81 puts 'output' end
Add 'end'.
Ruby
if x = 10
if x == 10
Use ==.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(12);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(12);
Correct.
Node.js
def baz(x): return x + 1
def baz(x): return x + 1
Correct.
Python
let str1 = String::from("info"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
b = value
b = 'value'
Quote strings.
Python
val item = 98; item = 1
var item = 98; item = 1
Use var for reassignment.
Scala
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
const foo;
const foo = 70;
Initialize const.
JavaScript
String y = 'info';
String y = "info";
Double quotes.
Java
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
'world' + 81
'world' + 81.to_s
Convert int.
Ruby
print('message')
print('message')
Correct.
R
<hr></hr>
<hr>
Self-closing.
HTML
int a = 'info';
String a = 'info';
Type mismatch.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
UPDATE users SET status='info' WHERE status=63
UPDATE users SET status='info' WHERE status=63;
Add semicolon.
SQL
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:82}};
Add missing property.
TypeScript
jwt.sign({{id:52}}, 'password');
jwt.sign({{id:52}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int arr[9]; arr[9]=5;
int arr[9]; if(9<9){{}} else arr[9]=5;
Bounds check.
C++
int[] values = new int[23]; values[23] = 5;
int[] values = new int[23]; if (23 < values.length) values[23] = 5;
Check bounds.
Java
List(27,39,91)
List(27,39,91)
Correct.
Scala
let list=vec![75,8,57]; let head=&list[0]; list.push(81);
let mut list=vec![75,8,57]; let head=list[0]; list.push(81);
Copy instead of reference.
Rust
print 'test'
print 'test';
Add semicolon.
Perl
if (bar = 31)
if (bar == 31)
Use ==.
R
$data[35]
if ($data.Count -gt 35) {{ $data[35] }}
Check bounds.
PowerShell
if (index = 90)
if (index == 90)
Use ==.
Scala
let b: number = 'result';
let b: string = 'result';
Fix type.
TypeScript
def baz(): print('world')
def baz(): print('world')
Indent function body.
Python
if (foo = 11) {{}}
if (foo == 11) {{}}
Use ==.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
'34' + 16
34 + 16
Avoid string coercion.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$list[22] = 5;
if (isset($list[22])) $list[22] = 5;
Check existence.
PHP
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
while index > 95 index -= 1
while index > 95: index -= 1
Colon missing after while.
Python
handle
handle()
Add parentheses.
Kotlin
data[96]
if (data.indices.contains(96)) data[96]
Check index.
Kotlin
<p>data <b>hello</p></b>
<p>data <b>hello</b></p>
Nest properly.
HTML
$count = 42; if ($count = 42) {{}}
$count = 42; if ($count == 42) {{}}
Use ==.
PHP
else print('data')
else: print('data')
Colon after else.
Python
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
<person><age>output</age><age>38</age></person
<person><age>output</age><age>38</age></person>
Add closing >.
XML
if val = 56 then print('message') end
if val == 56 then print('message') end
Use ==.
Lua
<br></br>
<br>
Self-closing.
HTML
SELECT * FROM users WHRE name=60;
SELECT * FROM users WHERE name=60;
Fix WHERE.
SQL
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
let y = 13; let y = 72;
let y = 13; y = 72;
Duplicate declaration.
JavaScript
DELETE FROM items WHERE status=88
DELETE FROM items WHERE status=88;
Add semicolon.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
if z = 94:
if z == 94:
Use == for comparison.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
[28, 18, 64
[28, 18, 64]
Close bracket.
Ruby
let s1 = String::from("output"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
function compute(bar) print(bar) end
function compute(bar) print(bar) end
Correct.
Lua
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++