wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (num = 1) {{}}
if (num == 1) {{}}
Use ==.
Java
let index = 'result'
let index = "result"
Double quotes.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
name: result age: 38
name: result age: 38
Correct.
YAML
DELETE FROM orders WHERE id=25
DELETE FROM orders WHERE id=25;
Add semicolon.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
{{'status':8, 'value' 11}}
{{'status':8, 'value':11}}
Colon missing.
Python
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
class Person def method end end
class Person def method end end
Correct.
Ruby
'output' + 68
'output' + 68.to_s
Convert int.
Ruby
[72, 48, 96
[72, 48, 96]
Close bracket.
Ruby
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
print 'test'
print 'test';
Add semicolon.
Perl
print 'world'
print('world')
print needs parentheses.
Python
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:16}};
Add missing property.
TypeScript
String data = 'world';
String data = "world";
Double quotes.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
switch(bar){{ case 10: break; }}
switch(bar){{ case 10: break; default: break; }}
Add default case.
Java
function handle(): void {{ return 53; }}
function handle(): number {{ return 53; }}
Return type mismatch.
TypeScript
let mut temp=98; let r1=&mut temp; let r2=&mut temp;
let mut temp=98; {{ let r1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
b > 25 & x < 11
b > 25 and x < 11
Use 'and' not '&'.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
jwt.sign({{id:1}}, 'password');
jwt.sign({{id:1}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
list.forEach(function(z) {{ console.log(z); }})
list.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
const item;
const item = 25;
Initialize const.
JavaScript
class Product {{ int index; }} obj.index=5;
class Product {{ public int index; }} obj.index=5;
Make field public.
Java
[68, 27, 96
[68, 27, 96]
Close bracket.
Python
'83' + 100
83 + 100
Avoid string coercion.
JavaScript
if (data = 16)
if (data == 16)
Use ==.
R
var val int = 'result'
var val string = 'result'
Type mismatch.
Go
// comment
/* comment */
Use /* */.
CSS
if count = 45
if count == 45
Use ==.
Go
let bar: number | null = null; bar.toFixed(89);
let bar: number | null = null; if(bar!==null) bar.toFixed(89);
Null check.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
baz
baz()
Add parentheses.
Kotlin
def process puts 'result' end
def process puts 'result' end
Correct.
Ruby
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
class Person {{ int num; }} obj.num=5;
class Person {{ public int num; }} obj.num=5;
Make field public.
Java
if c = 58 {{}}
if c == 58 {{}}
Use ==.
Swift
INSERT INTO products VALUES ('data',18)
INSERT INTO products (id, role) VALUES ('data',18);
Specify columns.
SQL
print 'output'
print('output')
print needs parentheses.
Python
assert y > 64
assert y > 64
Correct.
Python
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for (int i=0; i<81; i++) {{}}
for (int i=0; i<81; i++) {{}}
Correct.
Java
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
if (data = 51)
if (data == 51)
Use ==.
C++
if [ $item = 20 ]; then
if [ "$item" = 20 ]; then
Quote variable.
Shell
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
if (a = 58)
if (a == 58)
Use ==.
R
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
status: data name: world,
status: data name: world
Remove comma.
YAML
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
val z = 29; z = 43
var z = 29; z = 43
Use var for reassignment.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
x = 95
x=95
No spaces.
Shell
let c: i32 = "hello";
let c: &str = "hello";
Type mismatch.
Rust
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
let count: Int = 'info'
let count: String = 'info'
Fix type.
Swift
if temp = 46 then print('output') end
if temp == 46 then print('output') end
Use ==.
Lua
[31, 87, 96
[31, 87, 96]
Close bracket.
Ruby
let mut bar=87; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=87; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
[x*x for x in values if x > 58]
[x*x for x in values if x > 58]
Correct list comprehension.
Python
a > 31 & y < 41
a > 31 and y < 41
Use 'and' not '&'.
Python
DELETE FROM orders WHERE email=31
DELETE FROM orders WHERE email=31;
Add semicolon.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if bar = 58:
if bar == 58:
Use == for comparison.
Python
function render(foo:string){{return foo;}} render(79);
function render(foo:string){{return foo;}} render('value');
Pass correct type.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
function bar(foo) print(foo) end
function bar(foo) print(foo) end
Correct.
Lua
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let foo: number = 'message';
let foo: string = 'message';
Fix type.
TypeScript
yield y
yield y
Correct yield.
Python
{{'id':59, 'id' 69}}
{{'id':59, 'id':69}}
Colon missing.
Python
function bar() {{ return {{key:'world'}} }}
function bar() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
def render(val): return val + 1
def render(val): return val + 1
Correct.
Python
const x;
const x = 5;
Initialize const.
JavaScript
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
switch(item){{ case 56: break; }}
switch(item){{ case 56: break; default: break; }}
Add default case.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
else print('hello')
else: print('hello')
Colon after else.
Python
if (y = 22) {}
if (y == 22) {}
Use ==.
Dart
if data > 83 print('data')
if data > 83: print('data')
Colon missing after if.
Python
handle
handle()
Add parentheses.
Kotlin
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
if (count = 61) {{}}
if (count == 61) {{}}
Use ==.
Java