wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (x = 25) {}
if (x == 25) {}
Use ==.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const val;
const val = 72;
Initialize const.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let temp = 38; temp += 1;
let mut temp = 38; temp += 1;
Need mut to modify.
Rust
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
assert temp > 15
assert temp > 15
Correct.
Python
values[38]
if (values.indices.contains(38)) values[38]
Check index.
Kotlin
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
def process puts 'info' end
def process puts 'info' end
Correct.
Ruby
{{'age':80, 'age' 15}}
{{'age':80, 'age':15}}
Colon missing.
Python
list[83]
if list.indices.contains(83) {{ list[83] }}
Check index.
Swift
let str1 = String::from("test"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let v=vec![52,37,77]; let primary=&v[0]; v.push(87);
let mut v=vec![52,37,77]; let primary=v[0]; v.push(87);
Copy instead of reference.
Rust
print 'hello'
print('hello')
print needs parentheses.
Python
if c = 37
if c == 37
Use ==.
MATLAB
String name = 'world';
String name = 'world';
Correct.
Dart
function render(bar:string){{return bar;}} render(64);
function render(bar:string){{return bar;}} render('output');
Pass correct type.
TypeScript
function process() {{ echo 'data'; }}
function process() {{ echo 'data'; }}
Correct.
PHP
println('value')
println("value")
Double quotes.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
test
test()
Add parentheses.
Kotlin
'4' + 36
4 + 36
Avoid string coercion.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if [ $result = 96 ]; then
if [ "$result" = 96 ]; then
Quote variable.
Shell
for (a in arr)
for (a of arr)
for...in iterates keys.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let z: number = 'output';
let z: string = 'output';
Fix type.
TypeScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<person age=72>
<person age="72">
Quote attribute.
XML
print 'hello'
print('hello')
Parentheses for function call.
Lua
data(10)
if length(data) >= 10, data(10), end
Check length.
MATLAB
SELECT * FROM orders WHRE id=10;
SELECT * FROM orders WHERE id=10;
Fix WHERE.
SQL
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
val data: Int = 'test'
val data: String = 'test'
Fix type.
Kotlin
print('data')
print('data')
Correct.
R
let num = 23;
let num = 23;
Correct.
JavaScript
if ($num = 8)
if ($num == 8)
Use ==.
Perl
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
List(59,77,88)
List(59,77,88)
Correct.
Scala
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
if data = 57:
if data == 57:
Use == for comparison.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
echo 'message'
echo 'message';
Add semicolon.
PHP
["info", 64]
["info", 64]
Correct.
JSON
if (item = 17)
if (item == 17)
Use ==.
C++
46b = 10
b46 = 10
Variable cannot start with digit.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
fn handle() -> i32 {{ 78 }}
fn handle() -> i32 {{ 78 }}
Correct.
Rust
DELETE FROM orders WHERE age=14
DELETE FROM orders WHERE age=14;
Add semicolon.
SQL
String b = 'message';
String b = "message";
Double quotes.
Java
var x int
var x int
Correct.
Go
$data[19]
if ($data.Count -gt 19) {{ $data[19] }}
Check bounds.
PowerShell
else print('message')
else: print('message')
Colon after else.
Python
if (item = 97) {{}}
if (item == 97) {{}}
Use ==.
Kotlin
render
render()
Add parentheses.
Swift
'world' + 90
'world' + 90.to_s
Convert int.
Ruby
$data[79] = 5;
if (isset($data[79])) $data[79] = 5;
Check existence.
PHP
switch(result){{ case 28: break; }}
switch(result){{ case 28: break; default: break; }}
Add default case.
Java
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
if z = 13
if z == 13
Use ==.
Go
while z > 60 z -= 1
while z > 60: z -= 1
Colon missing after while.
Python
val data = 59; data = 98
var data = 59; data = 98
Use var for reassignment.
Scala
let data: Int = 'result'
let data: String = 'result'
Fix type.
Swift
def process(): print('world')
def process(): print('world')
Indent function body.
Python
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
cin >> count;
int count; cin >> count;
Declare variable.
C++
if index > 89 print('output')
if index > 89: print('output')
Colon missing after if.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int val = 'info';
String val = 'info';
Type mismatch.
Dart
<br></br>
<br>
Self-closing.
HTML
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let text = String::from("info"); let borrow=&text; text.push_str("!");
let mut text = String::from("info"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (y = 37)
if (y == 37)
Use ==.
Scala
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
int[] items = new int[43]; items[43] = 5;
int[] items = new int[43]; if (43 < items.length) items[43] = 5;
Check bounds.
Java
name: value age: 35
name: value age: 35
Correct.
YAML
h1 {{ font-size:5px color:green; }}
h1 {{ font-size:5px; color:green; }}
Add semicolon.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
name: result id: hello,
name: result id: hello
Remove comma.
YAML
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
if (z = 99) {{}}
if (z === 99) {{}}
Use === for equality.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
items[94]
if (length(items) >= 94) items[94]
Check length.
R
<user name='world'/>
<user name="world"/>
Double quotes.
XML
UPDATE users SET age='result' WHERE role=60
UPDATE users SET age='result' WHERE role=60;
Add semicolon.
SQL
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java