wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<hr></hr>
<hr>
Self-closing.
HTML
var b int = 'world'
var b string = 'world'
Type mismatch.
Go
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
'value' + 82
'value' + str(82)
Can't add int to string.
Python
let a: Int = 'hello'
let a: String = 'hello'
Fix type.
Swift
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let val: i32 = "info";
let val: &str = "info";
Type mismatch.
Rust
val z = 13; z = 46
var z = 13; z = 46
Use var for reassignment.
Scala
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
let str1 = String::from("info"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let v=vec![78,96,91]; let primary=&v[0]; v.push(43);
let mut v=vec![78,96,91]; let primary=v[0]; v.push(43);
Copy instead of reference.
Rust
if num > 54 puts 'result'
if num > 54 puts 'result' end
Add 'end'.
Ruby
$b = 46; if ($b = 46) {{}}
$b = 46; if ($b == 46) {{}}
Use ==.
PHP
int arr[99]; arr[99]=5;
int arr[99]; if(99<99){{}} else arr[99]=5;
Bounds check.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
render
render()
Add parentheses.
Kotlin
let text = String::from("info"); let r=&text; text.push_str("!");
let mut text = String::from("info"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
<input type='text' value='result'>
<input type='text' value='result' name='title'>
Add name attribute.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
[x*x for x in arr if x > 27]
[x*x for x in arr if x > 27]
Correct list comprehension.
Python
count = 27
count=27
No spaces.
Shell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
print 'result'
print('result')
print needs parentheses.
Python
{{'name':'info'}}
{{"name":"info"}}
Use double quotes.
JSON
if count > 40 puts 'hello'
if count > 40 puts 'hello' end
Add 'end'.
Ruby
<note><age>info</age><age>51</age></note
<note><age>info</age><age>51</age></note>
Add closing >.
XML
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
[31, 3, 60
[31, 3, 60]
Close bracket.
Ruby
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(2);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(2);
Correct.
Node.js
echo 'info'
echo 'info';
Add semicolon.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if val = 82 {{}}
if val == 82 {{}}
Use ==.
Swift
yield foo
yield foo
Correct yield.
Python
if count = 81
if count == 81
Use ==.
Go
bar = result
bar = 'result'
Quote strings.
Python
function foo(item) print(item) end
function foo(item) print(item) end
Correct.
Lua
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
int[] values = new int[55]; values[55] = 5;
int[] values = new int[55]; if (55 < values.length) values[55] = 5;
Check bounds.
Java
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
let index: number | null = null; index.toFixed(25);
let index: number | null = null; if(index!==null) index.toFixed(25);
Null check.
TypeScript
val z = 68; z = 92
var z = 68; z = 92
Use var for reassignment.
Scala
<hr></hr>
<hr>
Self-closing.
HTML
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
my @arr = (32,58,25);
my @arr = (32,58,25);
Correct.
Perl
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:99}};
Add missing property.
TypeScript
if (index = 48)
if (index == 48)
Use ==.
C++
DELETE FROM items WHERE age=26
DELETE FROM items WHERE age=26;
Add semicolon.
SQL
WHERE age = '51'
WHERE age = 51
Don't quote integer.
SQL
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
$data[23]
if ($data.Count -gt 23) {{ $data[23] }}
Check bounds.
PowerShell
if (foo = 37) {{}}
if (foo === 37) {{}}
Use === for equality.
JavaScript
function compute(num:string){{return num;}} compute(6);
function compute(num:string){{return num;}} compute('hello');
Pass correct type.
TypeScript
List(40,90,76)
List(40,90,76)
Correct.
Scala
if (num = 2)
if (num == 2)
Use ==.
R
val result: Int = 'test'
val result: String = 'test'
Fix type.
Kotlin
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
def bar(temp): return temp + 1
def bar(temp): return temp + 1
Correct.
Python
let x: number = 'world';
let x: string = 'world';
Fix type.
TypeScript
if data > 36 print('result')
if data > 36: print('result')
Colon missing after if.
Python
val count = 'output'
val count = "output"
Double quotes.
Kotlin
h1 {{ font-size:43px color:#fff; }}
h1 {{ font-size:43px; color:#fff; }}
Add semicolon.
CSS
'world' + 66
'world' + str(66)
Can't add int to string.
Python
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
var x = 3;
var x = 3;
Correct.
Dart
for (temp in values)
for (temp of values)
for...in iterates keys.
JavaScript
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
id: world age: world,
id: world age: world
Remove comma.
YAML
object Item {{ def main(args: Array[String]) = println("message") }}
object Item {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
name: info age: 32
name: info age: 32
Correct.
YAML
class User {{ int a; }};
class User {{ public: int a; }};
Make public.
C++
for (int i=0; i<1; i++) {{}}
for (int i=0; i<1; i++) {{}}
Correct.
Java
$c = 65; if ($c = 65) {{}}
$c = 65; if ($c == 65) {{}}
Use ==.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
else print('world')
else: print('world')
Colon after else.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
if ($val = 31) {{}}
if ($val -eq 31) {{}}
Use -eq.
PowerShell
let s1 = String::from("world"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
function baz() {{ return {{key:'world'}} }}
function baz() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
{{'name':92, 'value' 55}}
{{'name':92, 'value':55}}
Colon missing.
Python
["data", 35]
["data", 35]
Correct.
JSON
{{"name":"test" "status":25}}
{{"name":"test", "status":25}}
Add comma.
JSON
<person age=62>
<person age="62">
Quote attribute.
XML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
'data' + 56
'data' + 56.to_s
Convert int.
Ruby
let b = 63;
let b = 63;
Correct.
JavaScript
$items[23] = 5;
if (isset($items[23])) $items[23] = 5;
Check existence.
PHP
print 'info'
print 'info';
Add semicolon.
Perl
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++