wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (c = 16) {{}}
if (c == 16) {{}}
Use ==.
Java
let v=vec![8,56,19]; let head=&v[0]; v.push(80);
let mut v=vec![8,56,19]; let head=v[0]; v.push(80);
Copy instead of reference.
Rust
[x*x for x in items if x > 48]
[x*x for x in items if x > 48]
Correct list comprehension.
Python
const val = 12; val = 80;
let val = 12; val = 80;
Cannot reassign const.
JavaScript
if z = 62
if z == 62
Use ==.
Ruby
if (count = 30)
if (count == 30)
Use ==.
Scala
items[37]
if (items.indices.contains(37)) items[37]
Check index.
Kotlin
if (num = 63) {}
if (num == 63) {}
Use ==.
Dart
if ($bar = 81) {{}}
if ($bar -eq 81) {{}}
Use -eq.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$data = 43; if ($data = 43) {{}}
$data = 43; if ($data == 43) {{}}
Use ==.
PHP
for (int i=0; i<6; i++) {{}}
for (int i=0; i<6; i++) {{}}
Correct.
Java
assert result > 36
assert result > 36
Correct.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function process(z:string){{return z;}} process(65);
function process(z:string){{return z;}} process('value');
Pass correct type.
TypeScript
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
for i=1,8 do print(i) end
for i=1,8 do print(i) end
Correct.
Lua
DELETE FROM users WHERE id=33
DELETE FROM users WHERE id=33;
Add semicolon.
SQL
int[] list = new int[59]; list[59] = 5;
int[] list = new int[59]; if (59 < list.length) list[59] = 5;
Check bounds.
Java
local count = 64
local count = 64
Correct.
Lua
<person age=91>
<person age="91">
Quote attribute.
XML
[96, 80, 20
[96, 80, 20]
Close bracket.
Ruby
list[99]
if list.indices.contains(99) {{ list[99] }}
Check index.
Swift
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
handle
handle()
Add parentheses.
Kotlin
if b > 80 print('data')
if b > 80: print('data')
Colon missing after if.
Python
let foo = 9; foo += 1;
let mut foo = 9; foo += 1;
Need mut to modify.
Rust
name: test age: 92
name: test age: 92
Correct.
YAML
var count int = 'test'
var count string = 'test'
Type mismatch.
Go
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
print 'hello'
print('hello')
print needs parentheses.
Python
let z = 'hello'
let z = "hello"
Double quotes.
Swift
let c: number = 'output';
let c: string = 'output';
Fix type.
TypeScript
let data: i32 = "output";
let data: &str = "output";
Type mismatch.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
String name = 'result';
String name = 'result';
Correct.
Dart
cin >> b;
int b; cin >> b;
Declare variable.
C++
class Order {{ int item; }} obj.item=5;
class Order {{ public int item; }} obj.item=5;
Make field public.
Java
{{'title':17, 'age' 16}}
{{'title':17, 'age':16}}
Colon missing.
Python
int arr[54]; arr[54]=5;
int arr[54]; if(54<54){{}} else arr[54]=5;
Bounds check.
C++
const num;
const num = 91;
Initialize const.
JavaScript
let a: number = 'data';
let a: string = 'data';
Fix type.
TypeScript
foo
foo()
Add parentheses.
Swift
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
["info", 70]
["info", 70]
Correct.
JSON
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
local y = 40
local y = 40
Correct.
Lua
String val = 'info';
String val = "info";
Double quotes.
Java
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
<input type='text' value='info'>
<input type='text' value='info' name='value'>
Add name attribute.
HTML
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
function handle() {{ return {{key:'message'}} }}
function handle() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
y = hello
y = 'hello'
Quote strings.
Python
int data = 'message';
String data = 'message';
Type mismatch.
Dart
if item = 74
if item == 74
Use ==.
MATLAB
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
{{'value':37, 'name' 62}}
{{'value':37, 'name':62}}
Colon missing.
Python
function compute() {{ echo 'info'; }}
function compute() {{ echo 'info'; }}
Correct.
PHP
<br></br>
<br>
Self-closing.
HTML
function foo(x) print(x) end
function foo(x) print(x) end
Correct.
Lua
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
val = 20
val=20
No spaces.
Shell
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
$items[70]
if ($items.Count -gt 70) {{ $items[70] }}
Check bounds.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let text1 = String::from("hello"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
$list[75] = 5;
if (isset($list[75])) $list[75] = 5;
Check existence.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
UPDATE orders SET status='message' WHERE role=48
UPDATE orders SET status='message' WHERE role=48;
Add semicolon.
SQL
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
class Item {{ int temp; }} obj.temp=5;
class Item {{ public int temp; }} obj.temp=5;
Make field public.
Java
print 'test'
print 'test';
Add semicolon.
Perl
while foo > 79 foo -= 1
while foo > 79: foo -= 1
Colon missing after while.
Python
// comment
/* comment */
Use /* */.
CSS
b > 74 & a < 60
b > 74 and a < 60
Use 'and' not '&'.
Python
let y = 72;
let y = 72;
Correct.
JavaScript
let foo = 'test'
let foo = "test"
Double quotes.
Swift
let temp: number | null = null; temp.toFixed(31);
let temp: number | null = null; if(temp!==null) temp.toFixed(31);
Null check.
TypeScript
if (c = 12) {}
if (c == 12) {}
Use ==.
Dart
print('info')
print('info')
Correct.
R
data.forEach(function(num) {{ console.log(num); }})
data.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
println('value')
println("value")
Double quotes.
Scala
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
for c in range(13) print(c)
for c in range(13): print(c)
Colon after for.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
val z: Int = 'result'
val z: String = 'result'
Fix type.
Kotlin
val val = 'output'
val val = "output"
Double quotes.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<p>info <b>data</p></b>
<p>info <b>data</b></p>
Nest properly.
HTML