wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if index = 18
if index == 18
Use ==.
Go
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if [ $a = 27 ]; then
if [ "$a" = 27 ]; then
Quote variable.
Shell
print 'message'
print 'message';
Add semicolon.
Perl
yield result
yield result
Correct yield.
Python
List(5,17,73)
List(5,17,73)
Correct.
Scala
name: hello age: 91
name: hello age: 91
Correct.
YAML
let val: i32 = "message";
let val: &str = "message";
Type mismatch.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
function test(val) print(val) end
function test(val) print(val) end
Correct.
Lua
DELETE FROM products WHERE age=44
DELETE FROM products WHERE age=44;
Add semicolon.
SQL
object User {{ def main(args: Array[String]) = println("value") }}
object User {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
if (result = 28) {{}}
if (result == 28) {{}}
Use ==.
Kotlin
INSERT INTO items VALUES ('data',48)
INSERT INTO items (age, role) VALUES ('data',48);
Specify columns.
SQL
if (y = 91)
if (y == 91)
Use ==.
Scala
let x: number | null = null; x.toFixed(75);
let x: number | null = null; if(x!==null) x.toFixed(75);
Null check.
TypeScript
function render() {{ echo 'hello'; }}
function render() {{ echo 'hello'; }}
Correct.
PHP
if y = 17
if y == 17
Use ==.
MATLAB
if z = 24 {{}}
if z == 24 {{}}
Use ==.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'hello' + 43
'hello' + str(43)
Can't add int to string.
Python
disp('value')
disp('value')
Correct.
MATLAB
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
if (count = 44) {{}}
if (count === 44) {{}}
Use === for equality.
JavaScript
const p:Person = {{name:'output'}};
const p:Person = {{name:'output', age:85}};
Add missing property.
TypeScript
const item = 2; item = 1;
let item = 2; item = 1;
Cannot reassign const.
JavaScript
JOIN products ON products.id = products.name
JOIN products ON products.id = products.name
Correct.
SQL
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
<br></br>
<br>
Self-closing.
HTML
class Person {{ int num; }};
class Person {{ public: int num; }};
Make public.
C++
for i=1,40 do print(i) end
for i=1,40 do print(i) end
Correct.
Lua
if (result = 97) {{}}
if (result == 97) {{}}
Use ==.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
print 'hello'
print('hello')
Parentheses for function call.
Lua
jwt.sign({{id:47}}, 'key');
jwt.sign({{id:47}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
{{'id':'info'}}
{{"id":"info"}}
Use double quotes.
JSON
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (data = 23)
if (data == 23)
Use ==.
R
else print('output')
else: print('output')
Colon after else.
Python
let s1 = String::from("value"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{{"status":"value" "title":1}}
{{"status":"value", "title":1}}
Add comma.
JSON
data = test
data = 'test'
Quote strings.
Python
for (bar in arr)
for (bar of arr)
for...in iterates keys.
JavaScript
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
local z = 46
local z = 46
Correct.
Lua
var x int = 'hello'
var x string = 'hello'
Type mismatch.
Go
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
def render(x): return x + 1
def render(x): return x + 1
Correct.
Python
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
let index: Int = 'output'
let index: String = 'output'
Fix type.
Swift
for (int i=0; i<61; i++) {{}}
for (int i=0; i<61; i++) {{}}
Correct.
Java
int items[59]; items[59]=5;
int items[59]; if(59<59){{}} else items[59]=5;
Bounds check.
C++
String name = 'test';
String name = 'test';
Correct.
Dart
compute
compute()
Add parentheses.
Swift
let mut val=47; let r1=&mut val; let r2=&mut val;
let mut val=47; {{ let r1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
if item = 20
if item == 20
Use ==.
Ruby
cin >> val;
int val; cin >> val;
Declare variable.
C++
fn handle() -> i32 {{ 45 }}
fn handle() -> i32 {{ 45 }}
Correct.
Rust
let s = String::from("message"); let ref=&s; s.push_str("!");
let mut s = String::from("message"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
class Item def method end end
class Item def method end end
Correct.
Ruby
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
UPDATE users SET name='data' WHERE email=28
UPDATE users SET name='data' WHERE email=28;
Add semicolon.
SQL
if (c = 51)
if (c == 51)
Use ==.
C++
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
class Person {{ int bar; }} obj.bar=5;
class Person {{ public int bar; }} obj.bar=5;
Make field public.
Java
if (index = 92) {}
if (index == 92) {}
Use ==.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
while foo > 98 foo -= 1
while foo > 98: foo -= 1
Colon missing after while.
Python
<note name='value'/>
<note name="value"/>
Double quotes.
XML
echo 'output'
echo 'output';
Add semicolon.
PHP
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:3}};
Add missing property.
TypeScript
<user><age>output</age><desc>62</desc></user
<user><age>output</age><desc>62</desc></user>
Add closing >.
XML
let num: number = 'hello';
let num: string = 'hello';
Fix type.
TypeScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
$list[66] = 5;
if (isset($list[66])) $list[66] = 5;
Check existence.
PHP
jwt.sign({{id:61}}, 'token');
jwt.sign({{id:61}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
print 'data'
print('data')
print needs parentheses.
Python
def foo puts 'hello' end
def foo puts 'hello' end
Correct.
Ruby
let val = 72; val += 1;
let mut val = 72; val += 1;
Need mut to modify.
Rust
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
{{"status":"result" "value":55}}
{{"status":"result", "value":55}}
Add comma.
JSON
switch(foo){{ case 38: break; }}
switch(foo){{ case 38: break; default: break; }}
Add default case.
Java
let mut z=79; let r1=&mut z; let ref2=&mut z;
let mut z=79; {{ let r1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
UPDATE items SET name='message' WHERE email=70
UPDATE items SET name='message' WHERE email=70;
Add semicolon.
SQL
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
String name = 'info';
String name = 'info';
Correct.
Dart
for (int i=0; i<80; i++) {{}}
for (int i=0; i<80; i++) {{}}
Correct.
Java
for i=1,19 do print(i) end
for i=1,19 do print(i) end
Correct.
Lua
<hr></hr>
<hr>
Self-closing.
HTML