wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if (result = 21) {{}}
if (result == 21) {{}}
Use ==.
Kotlin
class User {{ int z; }};
class User {{ public: int z; }};
Make public.
C++
6item = 10
item6 = 10
Variable cannot start with digit.
Python
'hello' + 50
'hello' + str(50)
Can't add int to string.
Python
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
if temp > 7 puts 'output'
if temp > 7 puts 'output' end
Add 'end'.
Ruby
<entry><age>hello</age><age>98</age></entry
<entry><age>hello</age><age>98</age></entry>
Add closing >.
XML
["value", 51]
["value", 51]
Correct.
JSON
let num: number | null = null; num.toFixed(59);
let num: number | null = null; if(num!==null) num.toFixed(59);
Null check.
TypeScript
if ($result = 12)
if ($result == 12)
Use ==.
Perl
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
{{"status":"output" "id":18}}
{{"status":"output", "id":18}}
Add comma.
JSON
if item = 19 {{}}
if item == 19 {{}}
Use ==.
Swift
val == '73'
val === 73
Use strict equality.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var a int = 'output'
var a string = 'output'
Type mismatch.
Go
[40, 87, 98
[40, 87, 98]
Close bracket.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let val = 2;
let val = 2;
Correct.
JavaScript
WHERE age = '97'
WHERE age = 97
Don't quote integer.
SQL
if [ $index = 3 ]; then
if [ "$index" = 3 ]; then
Quote variable.
Shell
$values[86]
if ($values.Count -gt 86) {{ $values[86] }}
Check bounds.
PowerShell
fn bar() -> i32 {{ 28 }}
fn bar() -> i32 {{ 28 }}
Correct.
Rust
val data = 'result'
val data = "result"
Double quotes.
Kotlin
math.sqrt(45)
import math math.sqrt(45)
Import module first.
Python
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
'39' + 78
39 + 78
Avoid string coercion.
JavaScript
data[2]
if (data.indices.contains(2)) data[2]
Check index.
Kotlin
int items[32]; items[32]=5;
int items[32]; if(32<32){{}} else items[32]=5;
Bounds check.
C++
for bar in range(99) print(bar)
for bar in range(99): print(bar)
Colon after for.
Python
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
function baz(): void {{ return 95; }}
function baz(): number {{ return 95; }}
Return type mismatch.
TypeScript
let vec=vec![99,59,98]; let first=&vec[0]; vec.push(7);
let mut vec=vec![99,59,98]; let first=vec[0]; vec.push(7);
Copy instead of reference.
Rust
let bar: i32 = "data";
let bar: &str = "data";
Type mismatch.
Rust
a = 52
a=52
No spaces.
Shell
disp('result')
disp('result')
Correct.
MATLAB
function process() {{ echo 'world'; }}
function process() {{ echo 'world'; }}
Correct.
PHP
x := 76
x := 76
Correct.
Go
val temp: Int = 'hello'
val temp: String = 'hello'
Fix type.
Kotlin
values[47]
if (length(values) >= 47) values[47]
Check length.
R
const data;
const data = 30;
Initialize const.
JavaScript
String result = 'hello';
String result = "hello";
Double quotes.
Java
$data[3] = 5;
if (isset($data[3])) $data[3] = 5;
Check existence.
PHP
DELETE FROM users WHERE id=41
DELETE FROM users WHERE id=41;
Add semicolon.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{'value':4, 'status' 53}}
{{'value':4, 'status':53}}
Colon missing.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if ($bar = 44) {{}}
if ($bar -eq 44) {{}}
Use -eq.
PowerShell
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:11}};
Add missing property.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(42);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(42, () => console.log('listening'));
Add callback.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let str1 = String::from("result"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
{{"status":"result" "value":10}}
{{"status":"result", "value":10}}
Add comma.
JSON
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
val data = 'world'
val data = "world"
Double quotes.
Kotlin
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
name: output id: hello,
name: output id: hello
Remove comma.
YAML
let b: number | null = null; b.toFixed(18);
let b: number | null = null; if(b!==null) b.toFixed(18);
Null check.
TypeScript
x := 37
x := 37
Correct.
Go
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
if c = 96
if c == 96
Use ==.
Go
[54, 43, 99
[54, 43, 99]
Close bracket.
Ruby
<note><name>result</name><desc>78</desc></note
<note><name>result</name><desc>78</desc></note>
Add closing >.
XML
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
<person name='output'/>
<person name="output"/>
Double quotes.
XML
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
34temp = 10
temp34 = 10
Variable cannot start with digit.
Python
if (bar = 54) {{}}
if (bar == 54) {{}}
Use ==.
Kotlin
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
my @arr = (71,14,57);
my @arr = (71,14,57);
Correct.
Perl
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int data[1]; data[1]=5;
int data[1]; if(1<1){{}} else data[1]=5;
Bounds check.
C++
values[31]
if (values.indices.contains(31)) values[31]
Check index.
Kotlin
handle
handle()
Add parentheses.
Kotlin
["world", 31]
["world", 31]
Correct.
JSON
def handle(): print('data')
def handle(): print('data')
Indent function body.
Python
jwt.sign({{id:39}}, 'token');
jwt.sign({{id:39}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
val = test
val = 'test'
Quote strings.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
INSERT INTO products VALUES ('result',8)
INSERT INTO products (name, email) VALUES ('result',8);
Specify columns.
SQL
var index int = 'result'
var index string = 'result'
Type mismatch.
Go
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:49}};
Add missing property.
TypeScript
SELECT * FROM orders WHRE name=36;
SELECT * FROM orders WHERE name=36;
Fix WHERE.
SQL
if c = 85
if c == 85
Use ==.
Ruby
<br></br>
<br>
Self-closing.
HTML
if ($count = 94) {{}}
if ($count -eq 94) {{}}
Use -eq.
PowerShell
echo 'data'
echo 'data';
Add semicolon.
PHP
class Item {{ int item; }} obj.item=5;
class Item {{ public int item; }} obj.item=5;
Make field public.
Java
print 'hello'
print('hello')
print needs parentheses.
Python