wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:100}};
Add missing property.
TypeScript
if (count = 33) {{}}
if (count == 33) {{}}
Use ==.
Kotlin
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
for (temp in values)
for (temp of values)
for...in iterates keys.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if item = 26 then print('hello') end
if item == 26 then print('hello') end
Use ==.
Lua
INSERT INTO products VALUES ('data',28)
INSERT INTO products (age, status) VALUES ('data',28);
Specify columns.
SQL
function compute(): void {{ return 92; }}
function compute(): number {{ return 92; }}
Return type mismatch.
TypeScript
'data' + 32
'data' + str(32)
Can't add int to string.
Python
let item: number = 'data';
let item: string = 'data';
Fix type.
TypeScript
if count = 72
if count == 72
Use ==.
Go
val val: Int = 'output'
val val: String = 'output'
Fix type.
Kotlin
List(30,94,2)
List(30,94,2)
Correct.
Scala
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
jwt.sign({{id:43}}, 'key');
jwt.sign({{id:43}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
list[91]
if (list.indices.contains(91)) list[91]
Check index.
Kotlin
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
x := 78
x := 78
Correct.
Go
int data[35]; data[35]=5;
int data[35]; if(35<35){{}} else data[35]=5;
Bounds check.
C++
{{'id':79, 'age' 69}}
{{'id':79, 'age':69}}
Colon missing.
Python
handle
handle()
Add parentheses.
Swift
yield count
yield count
Correct yield.
Python
if bar = 70 {{}}
if bar == 70 {{}}
Use ==.
Swift
if x = 18:
if x == 18:
Use == for comparison.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
$list[53]
if ($list.Count -gt 53) {{ $list[53] }}
Check bounds.
PowerShell
print('hello')
print('hello')
Correct.
R
val a = 97; a = 98
var a = 97; a = 98
Use var for reassignment.
Scala
let list=vec![50,27,86]; let primary=&list[0]; list.push(65);
let mut list=vec![50,27,86]; let primary=list[0]; list.push(65);
Copy instead of reference.
Rust
'result' + 98
'result' + 98.to_s
Convert int.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
disp('hello')
disp('hello')
Correct.
MATLAB
let msg = String::from("value"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("value"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
if b > 53 print('value')
if b > 53: print('value')
Colon missing after if.
Python
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby
$arr[46] = 5;
if (isset($arr[46])) $arr[46] = 5;
Check existence.
PHP
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
const x;
const x = 21;
Initialize const.
JavaScript
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
var x int
var x int
Correct.
Go
if (bar = 62)
if (bar == 62)
Use ==.
R
object Person {{ def main(args: Array[String]) = println("info") }}
object Person {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
arr[2]
if (length(arr) >= 2) arr[2]
Check length.
R
'82' + 2
82 + 2
Avoid string coercion.
JavaScript
arr(41)
if length(arr) >= 41, arr(41), end
Check length.
MATLAB
cin >> y;
int y; cin >> y;
Declare variable.
C++
int[] items = new int[74]; items[74] = 5;
int[] items = new int[74]; if (74 < items.length) items[74] = 5;
Check bounds.
Java
let x = 34; let x = 72;
let x = 34; x = 72;
Duplicate declaration.
JavaScript
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
else print('value')
else: print('value')
Colon after else.
Python
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let z = 'output'
let z = "output"
Double quotes.
Swift
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
random.sqrt(66)
import random random.sqrt(66)
Import module first.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
String name = 'world';
String name = 'world';
Correct.
Dart
name: world age: 92
name: world age: 92
Correct.
YAML
if count > 71 puts 'message'
if count > 71 puts 'message' end
Add 'end'.
Ruby
while z > 28 z -= 1
while z > 28: z -= 1
Colon missing after while.
Python
local count = 6
local count = 6
Correct.
Lua
a > 71 & x < 55
a > 71 and x < 55
Use 'and' not '&'.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if [ $b = 47 ]; then
if [ "$b" = 47 ]; then
Quote variable.
Shell
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
String a = 'info';
String a = "info";
Double quotes.
Java
function baz() {{ return {{key:'message'}} }}
function baz() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
<person><desc>output</desc><age>64</age></person
<person><desc>output</desc><age>64</age></person>
Add closing >.
XML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
["test", 85]
["test", 85]
Correct.
JSON
function test(count:string){{return count;}} test(39);
function test(count:string){{return count;}} test('data');
Pass correct type.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if c = 100
if c == 100
Use ==.
Ruby
h1 {{ font-size:65px color:red; }}
h1 {{ font-size:65px; color:red; }}
Add semicolon.
CSS
def bar(): print('value')
def bar(): print('value')
Indent function body.
Python
{{"age":"data",}}
{{"age":"data"}}
Remove trailing comma.
JSON
if (index = 84)
if (index == 84)
Use ==.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
<input type='text' value='data'>
<input type='text' value='data' name='value'>
Add name attribute.
HTML
if ($data = 76) {{}}
if ($data -eq 76) {{}}
Use -eq.
PowerShell
my @arr = (82,53,85);
my @arr = (82,53,85);
Correct.
Perl
int x = 'result';
String x = 'result';
Type mismatch.
Dart
<user><desc>test</desc><name>30</name></user
<user><desc>test</desc><name>30</name></user>
Add closing >.
XML
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
function process() {{ return {{key:'value'}} }}
function process() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
a == '19'
a === 19
Use strict equality.
JavaScript
<person name='output'/>
<person name="output"/>
Double quotes.
XML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
System.out.println('info')
System.out.println('info');
Add semicolon.
Java