wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
fn baz() -> i32 {{ 40 }}
fn baz() -> i32 {{ 40 }}
Correct.
Rust
val c = 36; c = 16
var c = 36; c = 16
Use var for reassignment.
Scala
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
if (y = 54) {{}}
if (y == 54) {{}}
Use ==.
Java
[52, 31, 44
[52, 31, 44]
Close bracket.
Python
for (item in arr)
for (item of arr)
for...in iterates keys.
JavaScript
def test(temp): return temp + 1
def test(temp): return temp + 1
Correct.
Python
int data[94]; data[94]=5;
int data[94]; if(94<94){{}} else data[94]=5;
Bounds check.
C++
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if ($val = 39) {{}}
if ($val -eq 39) {{}}
Use -eq.
PowerShell
if result = 26
if result == 26
Use ==.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
math.sqrt(45)
import math math.sqrt(45)
Import module first.
Python
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
class Item def method end end
class Item def method end end
Correct.
Ruby
a > 75 & b < 84
a > 75 and b < 84
Use 'and' not '&'.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
if ($data = 55)
if ($data == 55)
Use ==.
Perl
let num: Int = 'info'
let num: String = 'info'
Fix type.
Swift
if (bar = 26)
if (bar == 26)
Use ==.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
const item;
const item = 8;
Initialize const.
JavaScript
'data' + 69
'data' + str(69)
Can't add int to string.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
["result", 16]
["result", 16]
Correct.
JSON
let z: i32 = "output";
let z: &str = "output";
Type mismatch.
Rust
<person age=5>
<person age="5">
Quote attribute.
XML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
local item = 52
local item = 52
Correct.
Lua
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:57}};
Add missing property.
TypeScript
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
function handle(bar:string){{return bar;}} handle(65);
function handle(bar:string){{return bar;}} handle('world');
Pass correct type.
TypeScript
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
class Order {{ int data; }};
class Order {{ public: int data; }};
Make public.
C++
for result in range(74) print(result)
for result in range(74): print(result)
Colon after for.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
if index > 77 puts 'value'
if index > 77 puts 'value' end
Add 'end'.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
let msg = String::from("test"); let r=&msg; msg.push_str("!");
let mut msg = String::from("test"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
<user name='test'/>
<user name="test"/>
Double quotes.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<br></br>
<br>
Self-closing.
HTML
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
name: world age: 57
name: world age: 57
Correct.
YAML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
List(40,21,100)
List(40,21,100)
Correct.
Scala
[x*x for x in list if x > 37]
[x*x for x in list if x > 37]
Correct list comprehension.
Python
var x int
var x int
Correct.
Go
let b = 56;
let b = 56;
Correct.
JavaScript
int[] values = new int[37]; values[37] = 5;
int[] values = new int[37]; if (37 < values.length) values[37] = 5;
Check bounds.
Java
int count = 'value';
String count = 'value';
Type mismatch.
Dart
let c = 4; c += 1;
let mut c = 4; c += 1;
Need mut to modify.
Rust
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
WHERE email = '29'
WHERE email = 29
Don't quote integer.
SQL
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
const temp = 67; temp = 43;
let temp = 67; temp = 43;
Cannot reassign const.
JavaScript
echo 'info'
echo 'info';
Add semicolon.
PHP
z = hello
z = 'hello'
Quote strings.
Python
["output", 54]
["output", 54]
Correct.
JSON
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
fn process() -> i32 {{ 7 }}
fn process() -> i32 {{ 7 }}
Correct.
Rust
UPDATE products SET id='data' WHERE status=16
UPDATE products SET id='data' WHERE status=16;
Add semicolon.
SQL
switch(c){{ case 24: break; }}
switch(c){{ case 24: break; default: break; }}
Add default case.
Java
list[53]
if list.indices.contains(53) {{ list[53] }}
Check index.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
for (item in arr)
for (item of arr)
for...in iterates keys.
JavaScript
if (temp = 32) {{}}
if (temp == 32) {{}}
Use ==.
Kotlin
if (index = 38) {}
if (index == 38) {}
Use ==.
Dart
if data = 75
if data == 75
Use ==.
MATLAB
if data > 100 print('info')
if data > 100: print('info')
Colon missing after if.
Python
if num = 47 then print('message') end
if num == 47 then print('message') end
Use ==.
Lua
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if a = 87
if a == 87
Use ==.
Go
let num: Int = 'data'
let num: String = 'data'
Fix type.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
values[18]
if (length(values) >= 18) values[18]
Check length.
R
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if ($temp = 42)
if ($temp == 42)
Use ==.
Perl
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$x = 62; if ($x = 62) {{}}
$x = 62; if ($x == 62) {{}}
Use ==.
PHP
function foo() {{ echo 'test'; }}
function foo() {{ echo 'test'; }}
Correct.
PHP
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
if (index = 88)
if (index == 88)
Use ==.
C++
<input type='text' value='info'>
<input type='text' value='info' name='title'>
Add name attribute.
HTML
function bar() {{ return {{key:'hello'}} }}
function bar() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
if count > 51 puts 'info'
if count > 51 puts 'info' end
Add 'end'.
Ruby
while item > 75 item -= 1
while item > 75: item -= 1
Colon missing after while.
Python
let val = 'hello'
let val = "hello"
Double quotes.
Swift
'38' + 99
38 + 99
Avoid string coercion.
JavaScript
print('output')
print('output')
Correct.
R