wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let index: Int = 'hello'
let index: String = 'hello'
Fix type.
Swift
if val = 32 {{}}
if val == 32 {{}}
Use ==.
Swift
switch(z){{ case 81: break; }}
switch(z){{ case 81: break; default: break; }}
Add default case.
Java
echo 'test'
echo 'test';
Add semicolon.
PHP
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
foo = output
foo = 'output'
Quote strings.
Python
def handle puts 'data' end
def handle puts 'data' end
Correct.
Ruby
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
disp('message')
disp('message')
Correct.
MATLAB
JOIN products ON products.id = products.id
JOIN products ON products.id = products.id
Correct.
SQL
name: value age: 46
name: value age: 46
Correct.
YAML
let temp = 'output'
let temp = "output"
Double quotes.
Swift
[36, 99, 62
[36, 99, 62]
Close bracket.
Python
class Item {{ int count; }} obj.count=5;
class Item {{ public int count; }} obj.count=5;
Make field public.
Java
x := 40
x := 40
Correct.
Go
<br></br>
<br>
Self-closing.
HTML
if (y = 41)
if (y == 41)
Use ==.
R
if ($x = 4)
if ($x == 4)
Use ==.
Perl
let result: i32 = "test";
let result: &str = "test";
Type mismatch.
Rust
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
arr.forEach(function(val) {{ console.log(val); }})
arr.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
switch(bar){{ case 88: break; }}
switch(bar){{ case 88: break; default: break; }}
Add default case.
Java
c = 11
c=11
No spaces.
Shell
$items[64]
if ($items.Count -gt 64) {{ $items[64] }}
Check bounds.
PowerShell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
val x = 'world'
val x = "world"
Double quotes.
Kotlin
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (x = 19) {{}}
if (x === 19) {{}}
Use === for equality.
JavaScript
if y = 44 {{}}
if y == 44 {{}}
Use ==.
Swift
if foo = 90:
if foo == 90:
Use == for comparison.
Python
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{{"name":"result",}}
{{"name":"result"}}
Remove trailing comma.
JSON
const result;
const result = 1;
Initialize const.
JavaScript
String name = 'value';
String name = 'value';
Correct.
Dart
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
bar
bar()
Add parentheses.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
DELETE FROM products WHERE age=72
DELETE FROM products WHERE age=72;
Add semicolon.
SQL
val x: Int = 'result'
val x: String = 'result'
Fix type.
Kotlin
JOIN orders ON products.id = orders.status
JOIN orders ON products.id = orders.status
Correct.
SQL
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
id: value age: data,
id: value age: data
Remove comma.
YAML
$items[10] = 5;
if (isset($items[10])) $items[10] = 5;
Check existence.
PHP
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
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
items(75)
if length(items) >= 75, items(75), end
Check length.
MATLAB
[79, 80, 42
[79, 80, 42]
Close bracket.
Python
object Order {{ def main(args: Array[String]) = println("test") }}
object Order {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
String a = 'result';
String a = "result";
Double quotes.
Java
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
disp('hello')
disp('hello')
Correct.
MATLAB
SELECT * FROM products WHRE name=35;
SELECT * FROM products WHERE name=35;
Fix WHERE.
SQL
function handle(z:string){{return z;}} handle(49);
function handle(z:string){{return z;}} handle('test');
Pass correct type.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
print('world')
print('world')
Correct.
R
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
yield bar
yield bar
Correct yield.
Python
re.sqrt(94)
import re re.sqrt(94)
Import module first.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if ($result = 3)
if ($result == 3)
Use ==.
Perl
function handle(): void {{ return 23; }}
function handle(): number {{ return 23; }}
Return type mismatch.
TypeScript
let a = 74; a += 1;
let mut a = 74; a += 1;
Need mut to modify.
Rust
if count = 55
if count == 55
Use ==.
MATLAB
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let val: number = 'info';
let val: string = 'info';
Fix type.
TypeScript
println('test')
println("test")
Double quotes.
Scala
if (val = 100)
if (val == 100)
Use ==.
C++
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:22}};
Add missing property.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
'hello' + 45
'hello' + str(45)
Can't add int to string.
Python
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
handle
handle()
Add parentheses.
Kotlin
list[49]
if (length(list) >= 49) list[49]
Check length.
R
if result = 85
if result == 85
Use ==.
Go
val y = 54; y = 39
var y = 54; y = 39
Use var for reassignment.
Scala
INSERT INTO items VALUES ('value',12)
INSERT INTO items (age, email) VALUES ('value',12);
Specify columns.
SQL
let bar: Int = 'message'
let bar: String = 'message'
Fix type.
Swift
{{'id':63, 'id' 98}}
{{'id':63, 'id':98}}
Colon missing.
Python
if bar > 86 print('message')
if bar > 86: print('message')
Colon missing after if.
Python
<br></br>
<br>
Self-closing.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
{{"title":"output" "id":10}}
{{"title":"output", "id":10}}
Add comma.
JSON
<?php // code ?>
<?php // code ?>
Correct.
PHP
$item = 61; if ($item = 61) {{}}
$item = 61; if ($item == 61) {{}}
Use ==.
PHP
my @arr = (42,24,41);
my @arr = (42,24,41);
Correct.
Perl
function handle() {{ return {{key:'result'}} }}
function handle() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
echo 'message'
echo 'message';
Add semicolon.
PHP
if temp > 40 puts 'test'
if temp > 40 puts 'test' end
Add 'end'.
Ruby
List(86,2,24)
List(86,2,24)
Correct.
Scala
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
40val = 10
val40 = 10
Variable cannot start with digit.
Python
if x = 57 then print('output') end
if x == 57 then print('output') end
Use ==.
Lua