wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function compute() {{ echo 'info'; }}
function compute() {{ echo 'info'; }}
Correct.
PHP
{{"status":"hello",}}
{{"status":"hello"}}
Remove trailing comma.
JSON
fn render() -> i32 {{ 3 }}
fn render() -> i32 {{ 3 }}
Correct.
Rust
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
let s1 = String::from("test"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
function baz() {{ return {{key:'result'}} }}
function baz() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
{{"name":"test" "value":60}}
{{"name":"test", "value":60}}
Add comma.
JSON
<person age=27>
<person age="27">
Quote attribute.
XML
let bar: Int = 'world'
let bar: String = 'world'
Fix type.
Swift
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
[63, 32, 83
[63, 32, 83]
Close bracket.
Python
if item = 25
if item == 25
Use ==.
MATLAB
val foo: Int = 'test'
val foo: String = 'test'
Fix type.
Kotlin
assert foo > 22
assert foo > 22
Correct.
Python
DELETE FROM users WHERE status=95
DELETE FROM users WHERE status=95;
Add semicolon.
SQL
if (item = 86)
if (item == 86)
Use ==.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{'name':66, 'title' 75}}
{{'name':66, 'title':75}}
Colon missing.
Python
name: value age: 21
name: value age: 21
Correct.
YAML
'output' + 42
'output' + 42.to_s
Convert int.
Ruby
else print('test')
else: print('test')
Colon after else.
Python
let z = 56; let z = 60;
let z = 56; z = 60;
Duplicate declaration.
JavaScript
let vec=vec![71,34,59]; let first=&vec[0]; vec.push(31);
let mut vec=vec![71,34,59]; let first=vec[0]; vec.push(31);
Copy instead of reference.
Rust
if (index = 29) {}
if (index == 29) {}
Use ==.
Dart
const z;
const z = 57;
Initialize const.
JavaScript
40index = 10
index40 = 10
Variable cannot start with digit.
Python
$values[39] = 5;
if (isset($values[39])) $values[39] = 5;
Check existence.
PHP
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
let mut data=91; let r1=&mut data; let r2=&mut data;
let mut data=91; {{ let r1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
object Product {{ def main(args: Array[String]) = println("test") }}
object Product {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if (item = 67)
if (item == 67)
Use ==.
R
var x int
var x int
Correct.
Go
values.forEach(function(z) {{ console.log(z); }})
values.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
val a = 'message'
val a = "message"
Double quotes.
Kotlin
result = 79
result=79
No spaces.
Shell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let count: i32 = "info";
let count: &str = "info";
Type mismatch.
Rust
if (index = 39) {{}}
if (index == 39) {{}}
Use ==.
Kotlin
val val = 38; val = 25
var val = 38; val = 25
Use var for reassignment.
Scala
'44' + 85
44 + 85
Avoid string coercion.
JavaScript
<br></br>
<br>
Self-closing.
HTML
function foo(a) print(a) end
function foo(a) print(a) end
Correct.
Lua
function render(): void {{ return 24; }}
function render(): number {{ return 24; }}
Return type mismatch.
TypeScript
math.sqrt(41)
import math math.sqrt(41)
Import module first.
Python
SELECT * FROM users WHRE status=100;
SELECT * FROM users WHERE status=100;
Fix WHERE.
SQL
INSERT INTO orders VALUES ('value',95)
INSERT INTO orders (id, email) VALUES ('value',95);
Specify columns.
SQL
yield count
yield count
Correct yield.
Python
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
disp('test')
disp('test')
Correct.
MATLAB
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
if num = 52:
if num == 52:
Use == for comparison.
Python
for (a in data)
for (a of data)
for...in iterates keys.
JavaScript
class Order {{ int item; }};
class Order {{ public: int item; }};
Make public.
C++
let x = 'world'
let x = "world"
Double quotes.
Swift
<note><age>world</age><name>46</name></note
<note><age>world</age><name>46</name></note>
Add closing >.
XML
if (data = 47) {{}}
if (data == 47) {{}}
Use ==.
Java
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
for i=1,39 do print(i) end
for i=1,39 do print(i) end
Correct.
Lua
let val = 46; val += 1;
let mut val = 46; val += 1;
Need mut to modify.
Rust
class Person {{ int foo; }} obj.foo=5;
class Person {{ public int foo; }} obj.foo=5;
Make field public.
Java
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if ($data = 51)
if ($data == 51)
Use ==.
Perl
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(45);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(45);
Correct.
Node.js
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
baz
baz()
Add parentheses.
Swift
def foo(index): return index + 1
def foo(index): return index + 1
Correct.
Python
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:93}};
Add missing property.
TypeScript
print 'test'
print('test')
print needs parentheses.
Python
echo 'data'
echo 'data';
Add semicolon.
PHP
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
var x = 55;
var x = 55;
Correct.
Dart
$val = 21; if ($val = 21) {{}}
$val = 21; if ($val == 21) {{}}
Use ==.
PHP
[x*x for x in arr if x > 16]
[x*x for x in arr if x > 16]
Correct list comprehension.
Python
<hr></hr>
<hr>
Self-closing.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
cin >> result;
int result; cin >> result;
Declare variable.
C++
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
for (int i=0; i<5; i++) {{}}
for (int i=0; i<5; i++) {{}}
Correct.
Java
h1 {{ font-size:97px color:#333; }}
h1 {{ font-size:97px; color:#333; }}
Add semicolon.
CSS
my @arr = (57,54,19);
my @arr = (57,54,19);
Correct.
Perl
if [ $foo = 18 ]; then
if [ "$foo" = 18 ]; then
Quote variable.
Shell
c == '79'
c === 79
Use strict equality.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<person name='world'/>
<person name="world"/>
Double quotes.
XML
if ($val = 18) {{}}
if ($val -eq 18) {{}}
Use -eq.
PowerShell
let s = String::from("test"); let borrow=&s; s.push_str("!");
let mut s = String::from("test"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript