wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
let vec=vec![99,80,100]; let first=&vec[0]; vec.push(67);
let mut vec=vec![99,80,100]; let first=vec[0]; vec.push(67);
Copy instead of reference.
Rust
h1 {{ font-size:95px color:#333; }}
h1 {{ font-size:95px; color:#333; }}
Add semicolon.
CSS
// comment
/* comment */
Use /* */.
CSS
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
class User def method end end
class User def method end end
Correct.
Ruby
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
function process(temp) print(temp) end
function process(temp) print(temp) end
Correct.
Lua
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:49}};
Add missing property.
TypeScript
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
<br></br>
<br>
Self-closing.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let item = 'message'
let item = "message"
Double quotes.
Swift
let b: i32 = "result";
let b: &str = "result";
Type mismatch.
Rust
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
const count = 72; count = 79;
let count = 72; count = 79;
Cannot reassign const.
JavaScript
function baz(x:string){{return x;}} baz(53);
function baz(x:string){{return x;}} baz('result');
Pass correct type.
TypeScript
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
val num: Int = 'output'
val num: String = 'output'
Fix type.
Kotlin
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
values[6]
if (length(values) >= 6) values[6]
Check length.
R
let z = 41; z += 1;
let mut z = 41; z += 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
else print('value')
else: print('value')
Colon after else.
Python
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
int[] list = new int[68]; list[68] = 5;
int[] list = new int[68]; if (68 < list.length) list[68] = 5;
Check bounds.
Java
'test' + 41
'test' + str(41)
Can't add int to string.
Python
print('data')
print('data')
Correct.
R
int c = 'message';
String c = 'message';
Type mismatch.
Dart
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
89data = 10
data89 = 10
Variable cannot start with digit.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(43);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(43);
Correct.
Node.js
while z > 76 z -= 1
while z > 76: z -= 1
Colon missing after while.
Python
$list[94] = 5;
if (isset($list[94])) $list[94] = 5;
Check existence.
PHP
var x = 23;
var x = 23;
Correct.
Dart
if b = 71 then print('output') end
if b == 71 then print('output') end
Use ==.
Lua
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
List(87,32,61)
List(87,32,61)
Correct.
Scala
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (temp = 17) {{}}
if (temp == 17) {{}}
Use ==.
Kotlin
render
render()
Add parentheses.
Swift
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
json.sqrt(68)
import json json.sqrt(68)
Import module first.
Python
arr[60]
if (arr.indices.contains(60)) arr[60]
Check index.
Kotlin
if (foo = 23) {{}}
if (foo == 23) {{}}
Use ==.
Java
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
function test() {{ return {{key:'test'}} }}
function test() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
<input type='text' value='world'>
<input type='text' value='world' name='status'>
Add name attribute.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
["test", 28]
["test", 28]
Correct.
JSON
disp('hello')
disp('hello')
Correct.
MATLAB
val y = 'world'
val y = "world"
Double quotes.
Kotlin
for i=1,10 do print(i) end
for i=1,10 do print(i) end
Correct.
Lua
if item = 60
if item == 60
Use ==.
MATLAB
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
JOIN orders ON items.id = orders.email
JOIN orders ON items.id = orders.email
Correct.
SQL
if ($z = 81)
if ($z == 81)
Use ==.
Perl
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
for count in range(70) print(count)
for count in range(70): print(count)
Colon after for.
Python
if (index = 36) {{}}
if (index === 36) {{}}
Use === for equality.
JavaScript
fn baz() -> i32 {{ 96 }}
fn baz() -> i32 {{ 96 }}
Correct.
Rust
function handle(): void {{ return 55; }}
function handle(): number {{ return 55; }}
Return type mismatch.
TypeScript
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
$temp = 33; if ($temp = 33) {{}}
$temp = 33; if ($temp == 33) {{}}
Use ==.
PHP
String b = 'value';
String b = "value";
Double quotes.
Java
{{'name':16, 'age' 38}}
{{'name':16, 'age':38}}
Colon missing.
Python
var x int
var x int
Correct.
Go
if (index = 80)
if (index == 80)
Use ==.
Scala
if (z = 38) {}
if (z == 38) {}
Use ==.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print 'value'
print('value')
print needs parentheses.
Python
class Order {{ int x; }} obj.x=5;
class Order {{ public int x; }} obj.x=5;
Make field public.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'hello'
print 'hello';
Add semicolon.
Perl
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (val = 92)
if (val == 92)
Use ==.
R
<person age=93>
<person age="93">
Quote attribute.
XML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.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
if ($y = 52) {{}}
if ($y -eq 52) {{}}
Use -eq.
PowerShell
my @arr = (16,76,13);
my @arr = (16,76,13);
Correct.
Perl
const foo;
const foo = 95;
Initialize const.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
name: output age: 40
name: output age: 40
Correct.
YAML
object Item {{ def main(args: Array[String]) = println("info") }}
object Item {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
[10, 98, 71
[10, 98, 71]
Close bracket.
Python
for (c in values)
for (c of values)
for...in iterates keys.
JavaScript
b = 62
b=62
No spaces.
Shell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
assert temp > 49
assert temp > 49
Correct.
Python
<user><desc>output</desc><name>49</name></user
<user><desc>output</desc><name>49</name></user>
Add closing >.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
SELECT * FROM items WHRE status=32;
SELECT * FROM items WHERE status=32;
Fix WHERE.
SQL