wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
let a: number | null = null; a.toFixed(63);
let a: number | null = null; if(a!==null) a.toFixed(63);
Null check.
TypeScript
my @arr = (65,62,17);
my @arr = (65,62,17);
Correct.
Perl
let mut bar=8; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=8; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
val y: Int = 'test'
val y: String = 'test'
Fix type.
Kotlin
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
<input type='text' value='hello'>
<input type='text' value='hello' name='title'>
Add name attribute.
HTML
for (int i=0; i<13; i++) {{}}
for (int i=0; i<13; i++) {{}}
Correct.
Java
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if (foo = 32) {{}}
if (foo === 32) {{}}
Use === for equality.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
class Order def method end end
class Order def method end end
Correct.
Ruby
["output", 97]
["output", 97]
Correct.
JSON
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<br></br>
<br>
Self-closing.
HTML
'data' + 93
'data' + str(93)
Can't add int to string.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
data[55]
if (length(data) >= 55) data[55]
Check length.
R
$arr[31]
if ($arr.Count -gt 31) {{ $arr[31] }}
Check bounds.
PowerShell
var val int = 'hello'
var val string = 'hello'
Type mismatch.
Go
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
for bar in range(74) print(bar)
for bar in range(74): print(bar)
Colon after for.
Python
<user><age>value</age><name>69</name></user
<user><age>value</age><name>69</name></user>
Add closing >.
XML
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
if result > 66 print('message')
if result > 66: print('message')
Colon missing after if.
Python
if val = 53:
if val == 53:
Use == for comparison.
Python
for i=1,28 do print(i) end
for i=1,28 do print(i) end
Correct.
Lua
{{"value":"value",}}
{{"value":"value"}}
Remove trailing comma.
JSON
for (int i=0; i<56; i++) {{}}
for (int i=0; i<56; i++) {{}}
Correct.
Java
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
z = info
z = 'info'
Quote strings.
Python
List(59,91,20)
List(59,91,20)
Correct.
Scala
val foo = 'world'
val foo = "world"
Double quotes.
Kotlin
function handle(): void {{ return 42; }}
function handle(): number {{ return 42; }}
Return type mismatch.
TypeScript
print 'result'
print 'result';
Add semicolon.
Perl
def baz(): print('hello')
def baz(): print('hello')
Indent function body.
Python
local b = 39
local b = 39
Correct.
Lua
[x*x for x in list if x > 91]
[x*x for x in list if x > 91]
Correct list comprehension.
Python
let s1 = String::from("world"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
h1 {{ font-size:20px color:blue; }}
h1 {{ font-size:20px; color:blue; }}
Add semicolon.
CSS
// comment
/* comment */
Use /* */.
CSS
x := 100
x := 100
Correct.
Go
echo 'output'
echo 'output';
Add semicolon.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{'name':42, 'id' 85}}
{{'name':42, 'id':85}}
Colon missing.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
SELECT * FROM products WHRE id=45;
SELECT * FROM products WHERE id=45;
Fix WHERE.
SQL
if (result = 51)
if (result == 51)
Use ==.
R
var x = 29;
var x = 29;
Correct.
Dart
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:80}};
Add missing property.
TypeScript
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
String name = 'info';
String name = 'info';
Correct.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
render
render()
Add parentheses.
Swift
function foo(b) print(b) end
function foo(b) print(b) end
Correct.
Lua
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
<person><desc>world</desc><desc>1</desc></person
<person><desc>world</desc><desc>1</desc></person>
Add closing >.
XML
arr(88)
if length(arr) >= 88, arr(88), end
Check length.
MATLAB
class Item {{ int b; }};
class Item {{ public: int b; }};
Make public.
C++
items[83]
if (length(items) >= 83) items[83]
Check length.
R
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
let str = String::from("data"); let r=&str; str.push_str("!");
let mut str = String::from("data"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
WHERE name = '97'
WHERE name = 97
Don't quote integer.
SQL
def test puts 'test' end
def test puts 'test' end
Correct.
Ruby
let a: i32 = "output";
let a: &str = "output";
Type mismatch.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(44);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(44, () => console.log('listening'));
Add callback.
Node.js
class Person def method end end
class Person def method end end
Correct.
Ruby
if (val = 36)
if (val == 36)
Use ==.
C++
cin >> num;
int num; cin >> num;
Declare variable.
C++
name: info age: 91
name: info age: 91
Correct.
YAML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let result: Int = 'data'
let result: String = 'data'
Fix type.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
{{"title":"hello" "id":30}}
{{"title":"hello", "id":30}}
Add comma.
JSON
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
[39, 57, 70
[39, 57, 70]
Close bracket.
Ruby
let mut num=84; let ref1=&mut num; let ref2=&mut num;
let mut num=84; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
if ($z = 7) {{}}
if ($z -eq 7) {{}}
Use -eq.
PowerShell
["output", 47]
["output", 47]
Correct.
JSON
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
a > 51 & z < 38
a > 51 and z < 38
Use 'and' not '&'.
Python
def process(item): return item + 1
def process(item): return item + 1
Correct.
Python
while num > 78 num -= 1
while num > 78: num -= 1
Colon missing after while.
Python
print 'value'
print('value')
print needs parentheses.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
data[16]
if (data.indices.contains(16)) data[16]
Check index.
Kotlin
let z = 77; z += 1;
let mut z = 77; z += 1;
Need mut to modify.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript