wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
arr[23]
if (arr.indices.contains(23)) arr[23]
Check index.
Kotlin
{{"title":"info",}}
{{"title":"info"}}
Remove trailing comma.
JSON
val z: Int = 'world'
val z: String = 'world'
Fix type.
Kotlin
{{"age":"world" "value":66}}
{{"age":"world", "value":66}}
Add comma.
JSON
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
values.forEach(function(result) {{ console.log(result); }})
values.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
int[] arr = new int[90]; arr[90] = 5;
int[] arr = new int[90]; if (90 < arr.length) arr[90] = 5;
Check bounds.
Java
JOIN profiles ON items.id = profiles.age
JOIN profiles ON items.id = profiles.age
Correct.
SQL
list[7]
if (length(list) >= 7) list[7]
Check length.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
<person age=28>
<person age="28">
Quote attribute.
XML
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
'test' + 80
'test' + str(80)
Can't add int to string.
Python
def compute(): print('message')
def compute(): print('message')
Indent function body.
Python
<note name='output'/>
<note name="output"/>
Double quotes.
XML
SELECT * FROM orders WHRE age=41;
SELECT * FROM orders WHERE age=41;
Fix WHERE.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
test
test()
Add parentheses.
Swift
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if ($item = 5) {{}}
if ($item -eq 5) {{}}
Use -eq.
PowerShell
cin >> y;
int y; cin >> y;
Declare variable.
C++
object Order {{ def main(args: Array[String]) = println("test") }}
object Order {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
let vec=vec![63,53,23]; let primary=&vec[0]; vec.push(84);
let mut vec=vec![63,53,23]; let primary=vec[0]; vec.push(84);
Copy instead of reference.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
my @arr = (42,36,86);
my @arr = (42,36,86);
Correct.
Perl
print('message')
print('message')
Correct.
R
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
while c > 25 c -= 1
while c > 25: c -= 1
Colon missing after while.
Python
jwt.sign({{id:28}}, 'password');
jwt.sign({{id:28}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
println('hello')
println("hello")
Double quotes.
Scala
<?php // code ?>
<?php // code ?>
Correct.
PHP
let count = 'test'
let count = "test"
Double quotes.
Swift
let b = 80; let b = 88;
let b = 80; b = 88;
Duplicate declaration.
JavaScript
let z: number | null = null; z.toFixed(85);
let z: number | null = null; if(z!==null) z.toFixed(85);
Null check.
TypeScript
if ($temp = 53)
if ($temp == 53)
Use ==.
Perl
let bar = 10;
let bar = 10;
Correct.
JavaScript
function foo() {{ echo 'world'; }}
function foo() {{ echo 'world'; }}
Correct.
PHP
UPDATE products SET id='value' WHERE email=21
UPDATE products SET id='value' WHERE email=21;
Add semicolon.
SQL
String name = 'value';
String name = 'value';
Correct.
Dart
if val = 26
if val == 26
Use ==.
MATLAB
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
local count = 11
local count = 11
Correct.
Lua
<hr></hr>
<hr>
Self-closing.
HTML
WHERE id = '66'
WHERE id = 66
Don't quote integer.
SQL
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
$values[26] = 5;
if (isset($values[26])) $values[26] = 5;
Check existence.
PHP
val c = 'output'
val c = "output"
Double quotes.
Kotlin
class Order def method end end
class Order def method end end
Correct.
Ruby
h1 {{ font-size:6px color:#fff; }}
h1 {{ font-size:6px; color:#fff; }}
Add semicolon.
CSS
if x > 16 puts 'output'
if x > 16 puts 'output' end
Add 'end'.
Ruby
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
'41' + 15
41 + 15
Avoid string coercion.
JavaScript
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{{'status':'data'}}
{{"status":"data"}}
Use double quotes.
JSON
print 'world'
print 'world';
Add semicolon.
Perl
print 'hello'
print('hello')
Parentheses for function call.
Lua
// comment
/* comment */
Use /* */.
CSS
arr(53)
if length(arr) >= 53, arr(53), end
Check length.
MATLAB
if index = 26
if index == 26
Use ==.
Ruby
<br></br>
<br>
Self-closing.
HTML
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
echo 'world'
echo 'world';
Add semicolon.
PHP
if (val = 87) {{}}
if (val === 87) {{}}
Use === for equality.
JavaScript
random.sqrt(28)
import random random.sqrt(28)
Import module first.
Python
["test", 85]
["test", 85]
Correct.
JSON
100c = 10
c100 = 10
Variable cannot start with digit.
Python
var x int
var x int
Correct.
Go
items[71]
if items.indices.contains(71) {{ items[71] }}
Check index.
Swift
if (foo = 91)
if (foo == 91)
Use ==.
Scala
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
$num = 27; if ($num = 27) {{}}
$num = 27; if ($num == 27) {{}}
Use ==.
PHP
num = info
num = 'info'
Quote strings.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(99);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(99, () => console.log('listening'));
Add callback.
Node.js
c == '50'
c === 50
Use strict equality.
JavaScript
function render(): void {{ return 23; }}
function render(): number {{ return 23; }}
Return type mismatch.
TypeScript
'message' + 92
'message' + 92.to_s
Convert int.
Ruby
<person><desc>result</desc><desc>3</desc></person
<person><desc>result</desc><desc>3</desc></person>
Add closing >.
XML
def render puts 'value' end
def render puts 'value' end
Correct.
Ruby
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<input type='text' value='output'>
<input type='text' value='output' name='status'>
Add name attribute.
HTML
fn test() -> i32 {{ 10 }}
fn test() -> i32 {{ 10 }}
Correct.
Rust
var x = 46;
var x = 46;
Correct.
Dart
[51, 70, 54
[51, 70, 54]
Close bracket.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
List(12,67,61)
List(12,67,61)
Correct.
Scala
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(51);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(51);
Correct.
Node.js
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
for (foo in arr)
for (foo of arr)
for...in iterates keys.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell