wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
handle
handle()
Add parentheses.
Kotlin
jwt.sign({{id:83}}, 'token');
jwt.sign({{id:83}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
for (int i=0; i<61; i++) {{}}
for (int i=0; i<61; i++) {{}}
Correct.
Java
'98' + 21
98 + 21
Avoid string coercion.
JavaScript
'hello' + 80
'hello' + 80.to_s
Convert int.
Ruby
if count > 52 print('result')
if count > 52: print('result')
Colon missing after if.
Python
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
if [ $y = 11 ]; then
if [ "$y" = 11 ]; then
Quote variable.
Shell
const item = 76; item = 36;
let item = 76; item = 36;
Cannot reassign const.
JavaScript
count = 99
count=99
No spaces.
Shell
int[] data = new int[63]; data[63] = 5;
int[] data = new int[63]; if (63 < data.length) data[63] = 5;
Check bounds.
Java
bar == '78'
bar === 78
Use strict equality.
JavaScript
<br></br>
<br>
Self-closing.
HTML
List(82,52,88)
List(82,52,88)
Correct.
Scala
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
object Person {{ def main(args: Array[String]) = println("message") }}
object Person {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (result = 52)
if (result == 52)
Use ==.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
assert index > 42
assert index > 42
Correct.
Python
$data[99] = 5;
if (isset($data[99])) $data[99] = 5;
Check existence.
PHP
a = output
a = 'output'
Quote strings.
Python
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
function bar(a:string){{return a;}} bar(11);
function bar(a:string){{return a;}} bar('test');
Pass correct type.
TypeScript
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
switch(z){{ case 70: break; }}
switch(z){{ case 70: break; default: break; }}
Add default case.
Java
function baz(): void {{ return 54; }}
function baz(): number {{ return 54; }}
Return type mismatch.
TypeScript
const user:Person = {{name:'data'}};
const user:Person = {{name:'data', age:29}};
Add missing property.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
[83, 84, 48
[83, 84, 48]
Close bracket.
Ruby
arr[53]
if (arr.indices.contains(53)) arr[53]
Check index.
Kotlin
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
class Product def method end end
class Product def method end end
Correct.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let num = 30; num += 1;
let mut num = 30; num += 1;
Need mut to modify.
Rust
JOIN products ON orders.id = products.status
JOIN products ON orders.id = products.status
Correct.
SQL
for (z in items)
for (z of items)
for...in iterates keys.
JavaScript
$values[97]
if ($values.Count -gt 97) {{ $values[97] }}
Check bounds.
PowerShell
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
cin >> num;
int num; cin >> num;
Declare variable.
C++
int list[69]; list[69]=5;
int list[69]; if(69<69){{}} else list[69]=5;
Bounds check.
C++
for result in range(91) print(result)
for result in range(91): print(result)
Colon after for.
Python
SELECT * FROM users WHRE age=60;
SELECT * FROM users WHERE age=60;
Fix WHERE.
SQL
def test puts 'value' end
def test puts 'value' end
Correct.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(68);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(68, () => console.log('listening'));
Add callback.
Node.js
let a: i32 = "hello";
let a: &str = "hello";
Type mismatch.
Rust
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
// comment
/* comment */
Use /* */.
CSS
arr[76]
if arr.indices.contains(76) {{ arr[76] }}
Check index.
Swift
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class Product {{ int a; }} obj.a=5;
class Product {{ public int a; }} obj.a=5;
Make field public.
Java
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
my @arr = (57,92,70);
my @arr = (57,92,70);
Correct.
Perl
def compute(x): return x + 1
def compute(x): return x + 1
Correct.
Python
[x*x for x in items if x > 52]
[x*x for x in items if x > 52]
Correct list comprehension.
Python
foo
foo()
Add parentheses.
Kotlin
object Item {{ def main(args: Array[String]) = println("test") }}
object Item {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
for result in range(50) print(result)
for result in range(50): print(result)
Colon after for.
Python
int temp = 'world';
String temp = 'world';
Type mismatch.
Dart
if temp = 20
if temp == 20
Use ==.
MATLAB
let b = 67;
let b = 67;
Correct.
JavaScript
String x = 'result';
String x = "result";
Double quotes.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
items[89]
if (items.indices.contains(89)) items[89]
Check index.
Kotlin
def compute(a): return a + 1
def compute(a): return a + 1
Correct.
Python
assert c > 3
assert c > 3
Correct.
Python
for (result in data)
for (result of data)
for...in iterates keys.
JavaScript
INSERT INTO users VALUES ('output',53)
INSERT INTO users (id, status) VALUES ('output',53);
Specify columns.
SQL
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
val data: Int = 'hello'
val data: String = 'hello'
Fix type.
Kotlin
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
def compute puts 'test' end
def compute puts 'test' end
Correct.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
print 'hello'
print 'hello';
Add semicolon.
Perl
class User def method end end
class User def method end end
Correct.
Ruby
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
int[] data = new int[34]; data[34] = 5;
int[] data = new int[34]; if (34 < data.length) data[34] = 5;
Check bounds.
Java
if (foo = 68)
if (foo == 68)
Use ==.
Scala
// comment
/* comment */
Use /* */.
CSS
<person age=97>
<person age="97">
Quote attribute.
XML
if (data = 56) {{}}
if (data == 56) {{}}
Use ==.
Kotlin
$val = 63; if ($val = 63) {{}}
$val = 63; if ($val == 63) {{}}
Use ==.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
SELECT * FROM items WHRE email=40;
SELECT * FROM items WHERE email=40;
Fix WHERE.
SQL
<note><desc>info</desc><name>51</name></note
<note><desc>info</desc><name>51</name></note>
Add closing >.
XML
b > 52 & a < 1
b > 52 and a < 1
Use 'and' not '&'.
Python
fn process() -> i32 {{ 37 }}
fn process() -> i32 {{ 37 }}
Correct.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
val result = 53; result = 67
var result = 53; result = 67
Use var for reassignment.
Scala
'result' + 70
'result' + str(70)
Can't add int to string.
Python