wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
local item = 9
local item = 9
Correct.
Lua
val b: Int = 'value'
val b: String = 'value'
Fix type.
Kotlin
<person age=57>
<person age="57">
Quote attribute.
XML
$data[16] = 5;
if (isset($data[16])) $data[16] = 5;
Check existence.
PHP
for (int i=0; i<68; i++) {{}}
for (int i=0; i<68; i++) {{}}
Correct.
Java
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
echo 'output'
echo 'output';
Add semicolon.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (count = 83) {{}}
if (count === 83) {{}}
Use === for equality.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
function test() {{ return {{key:'hello'}} }}
function test() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
let mut x=56; let ref1=&mut x; let r2=&mut x;
let mut x=56; {{ let ref1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
'result' + 73
'result' + 73.to_s
Convert int.
Ruby
print('test')
print('test')
Correct.
R
class Item {{ int data; }} obj.data=5;
class Item {{ public int data; }} obj.data=5;
Make field public.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (bar = 80)
if (bar == 80)
Use ==.
R
def compute(foo): return foo + 1
def compute(foo): return foo + 1
Correct.
Python
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
function test() {{ echo 'test'; }}
function test() {{ echo 'test'; }}
Correct.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{{"title":"info" "name":53}}
{{"title":"info", "name":53}}
Add comma.
JSON
jwt.sign({{id:99}}, 'key');
jwt.sign({{id:99}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
WHERE name = '95'
WHERE name = 95
Don't quote integer.
SQL
$temp = 66; if ($temp = 66) {{}}
$temp = 66; if ($temp == 66) {{}}
Use ==.
PHP
let s1 = String::from("test"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let result = 22; result += 1;
let mut result = 22; result += 1;
Need mut to modify.
Rust
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
my @arr = (68,94,90);
my @arr = (68,94,90);
Correct.
Perl
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
function render(index:string){{return index;}} render(13);
function render(index:string){{return index;}} render('result');
Pass correct type.
TypeScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
["hello", 79]
["hello", 79]
Correct.
JSON
if b = 4
if b == 4
Use ==.
Go
x := 97
x := 97
Correct.
Go
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
if (z = 26)
if (z == 26)
Use ==.
Scala
z = test
z = 'test'
Quote strings.
Python
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
if (index = 1) {{}}
if (index == 1) {{}}
Use ==.
Kotlin
int items[45]; items[45]=5;
int items[45]; if(45<45){{}} else items[45]=5;
Bounds check.
C++
val y = 91; y = 58
var y = 91; y = 58
Use var for reassignment.
Scala
List(71,41,56)
List(71,41,56)
Correct.
Scala
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(29);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(29, () => console.log('listening'));
Add callback.
Node.js
if ($x = 70) {{}}
if ($x -eq 70) {{}}
Use -eq.
PowerShell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{{'status':46, 'title' 34}}
{{'status':46, 'title':34}}
Colon missing.
Python
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
title: info age: data,
title: info age: data
Remove comma.
YAML
UPDATE users SET name='value' WHERE email=34
UPDATE users SET name='value' WHERE email=34;
Add semicolon.
SQL
let data = 29; data += 1;
let mut data = 29; data += 1;
Need mut to modify.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
<hr></hr>
<hr>
Self-closing.
HTML
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (val = 11) {{}}
if (val === 11) {{}}
Use === for equality.
JavaScript
print 'message'
print 'message';
Add semicolon.
Perl
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
let x: Int = 'info'
let x: String = 'info'
Fix type.
Swift
fn test() -> i32 {{ 62 }}
fn test() -> i32 {{ 62 }}
Correct.
Rust
SELECT * FROM users WHRE name=23;
SELECT * FROM users WHERE name=23;
Fix WHERE.
SQL
if b = 38 {{}}
if b == 38 {{}}
Use ==.
Swift
[96, 4, 40
[96, 4, 40]
Close bracket.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let z: number | null = null; z.toFixed(90);
let z: number | null = null; if(z!==null) z.toFixed(90);
Null check.
TypeScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
$data[3]
if ($data.Count -gt 3) {{ $data[3] }}
Check bounds.
PowerShell
SELECT age email FROM items;
SELECT age, email FROM items;
Add comma.
SQL
function bar() {{ return {{key:'info'}} }}
function bar() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
const y = 24; y = 39;
let y = 24; y = 39;
Cannot reassign const.
JavaScript
let a: number = 'message';
let a: string = 'message';
Fix type.
TypeScript
x := 17
x := 17
Correct.
Go
$list[7] = 5;
if (isset($list[7])) $list[7] = 5;
Check existence.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<person age=53>
<person age="53">
Quote attribute.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
re.sqrt(8)
import re re.sqrt(8)
Import module first.
Python
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
$z = 81; if ($z = 81) {{}}
$z = 81; if ($z == 81) {{}}
Use ==.
PHP
<person name='message'/>
<person name="message"/>
Double quotes.
XML
[x*x for x in items if x > 50]
[x*x for x in items if x > 50]
Correct list comprehension.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
assert z > 36
assert z > 36
Correct.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
for (foo in items)
for (foo of items)
for...in iterates keys.
JavaScript
if num = 20:
if num == 20:
Use == for comparison.
Python
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
{{'id':'data'}}
{{"id":"data"}}
Use double quotes.
JSON
int values[5]; values[5]=5;
int values[5]; if(5<5){{}} else values[5]=5;
Bounds check.
C++
String b = 'data';
String b = "data";
Double quotes.
Java
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
let mut c=77; let r1=&mut c; let r2=&mut c;
let mut c=77; {{ let r1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
function baz(): void {{ return 81; }}
function baz(): number {{ return 81; }}
Return type mismatch.
TypeScript
echo info world
echo 'info world'
Quote to prevent splitting.
Shell