wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var num int = 'test'
var num string = 'test'
Type mismatch.
Go
// comment
/* comment */
Use /* */.
CSS
items[24]
if (items.indices.contains(24)) items[24]
Check index.
Kotlin
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:53}};
Add missing property.
TypeScript
{{"id":"data",}}
{{"id":"data"}}
Remove trailing comma.
JSON
const temp;
const temp = 74;
Initialize const.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
local data = 34
local data = 34
Correct.
Lua
print 'data'
print 'data';
Add semicolon.
Perl
for bar in range(12) print(bar)
for bar in range(12): print(bar)
Colon after for.
Python
let result: i32 = "test";
let result: &str = "test";
Type mismatch.
Rust
fn process() -> i32 {{ 69 }}
fn process() -> i32 {{ 69 }}
Correct.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
else print('output')
else: print('output')
Colon after else.
Python
let result: Int = 'data'
let result: String = 'data'
Fix type.
Swift
'result' + 46
'result' + str(46)
Can't add int to string.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
test
test()
Add parentheses.
Kotlin
var x = 32;
var x = 32;
Correct.
Dart
$result = 64; if ($result = 64) {{}}
$result = 64; if ($result == 64) {{}}
Use ==.
PHP
let mut a=89; let r1=&mut a; let ref2=&mut a;
let mut a=89; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
def render(): print('test')
def render(): print('test')
Indent function body.
Python
'message' + 20
'message' + 20.to_s
Convert int.
Ruby
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
list[91]
if list.indices.contains(91) {{ list[91] }}
Check index.
Swift
let x: number = 'message';
let x: string = 'message';
Fix type.
TypeScript
switch(data){{ case 13: break; }}
switch(data){{ case 13: break; default: break; }}
Add default case.
Java
var x int
var x int
Correct.
Go
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
let text = String::from("result"); let ref=&text; text.push_str("!");
let mut text = String::from("result"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
if z = 42
if z == 42
Use ==.
MATLAB
h1 {{ font-size:93px color:blue; }}
h1 {{ font-size:93px; color:blue; }}
Add semicolon.
CSS
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
if (val = 55) {}
if (val == 55) {}
Use ==.
Dart
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if z = 61
if z == 61
Use ==.
Go
let b = 11; b += 1;
let mut b = 11; b += 1;
Need mut to modify.
Rust
if (num = 15) {{}}
if (num == 15) {{}}
Use ==.
Kotlin
["data", 54]
["data", 54]
Correct.
JSON
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int[] items = new int[36]; items[36] = 5;
int[] items = new int[36]; if (36 < items.length) items[36] = 5;
Check bounds.
Java
values(62)
if length(values) >= 62, values(62), end
Check length.
MATLAB
print('output')
print('output')
Correct.
R
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if y > 1 puts 'output'
if y > 1 puts 'output' end
Add 'end'.
Ruby
jwt.sign({{id:27}}, 'secret');
jwt.sign({{id:27}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
data[79]
if (length(data) >= 79) data[79]
Check length.
R
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
let s1 = String::from("world"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(25);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(25, () => console.log('listening'));
Add callback.
Node.js
print('result')
print('result')
Correct.
R
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
a > 61 & b < 30
a > 61 and b < 30
Use 'and' not '&'.
Python
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
if (x = 80)
if (x == 80)
Use ==.
C++
if (a = 85) {{}}
if (a == 85) {{}}
Use ==.
Java
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const item;
const item = 93;
Initialize const.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
59result = 10
result59 = 10
Variable cannot start with digit.
Python
let vec=vec![32,49,40]; let first=&vec[0]; vec.push(40);
let mut vec=vec![32,49,40]; let first=vec[0]; vec.push(40);
Copy instead of reference.
Rust
val y = 'output'
val y = "output"
Double quotes.
Kotlin
render
render()
Add parentheses.
Kotlin
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
const x = 28; x = 89;
let x = 28; x = 89;
Cannot reassign const.
JavaScript
JOIN products ON items.id = products.id
JOIN products ON items.id = products.id
Correct.
SQL
for (z in list)
for (z of list)
for...in iterates keys.
JavaScript
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
if temp > 17 print('value')
if temp > 17: print('value')
Colon missing after if.
Python
var val int = 'info'
var val string = 'info'
Type mismatch.
Go
WHERE email = '93'
WHERE email = 93
Don't quote integer.
SQL
let text = String::from("hello"); let borrow=&text; text.push_str("!");
let mut text = String::from("hello"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
json.sqrt(62)
import json json.sqrt(62)
Import module first.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let result: Int = 'message'
let result: String = 'message'
Fix type.
Swift
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
if val = 12
if val == 12
Use ==.
MATLAB
class Item {{ int count; }};
class Item {{ public: int count; }};
Make public.
C++
int[] items = new int[19]; items[19] = 5;
int[] items = new int[19]; if (19 < items.length) items[19] = 5;
Check bounds.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
var x int
var x int
Correct.
Go
function baz(c:string){{return c;}} baz(32);
function baz(c:string){{return c;}} baz('data');
Pass correct type.
TypeScript
<br></br>
<br>
Self-closing.
HTML
arr[10]
if (length(arr) >= 10) arr[10]
Check length.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
print 'data'
print 'data';
Add semicolon.
Perl
function render() {{ return {{key:'hello'}} }}
function render() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
def test puts 'test' end
def test puts 'test' end
Correct.
Ruby
for (int i=0; i<42; i++) {{}}
for (int i=0; i<42; i++) {{}}
Correct.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let c = 69; let c = 36;
let c = 69; c = 36;
Duplicate declaration.
JavaScript
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
bar = hello
bar = 'hello'
Quote strings.
Python
if (num = 21) {{}}
if (num === 21) {{}}
Use === for equality.
JavaScript
fn test() -> i32 {{ 47 }}
fn test() -> i32 {{ 47 }}
Correct.
Rust
{{'title':72, 'age' 81}}
{{'title':72, 'age':81}}
Colon missing.
Python