wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int[] list = new int[99]; list[99] = 5;
int[] list = new int[99]; if (99 < list.length) list[99] = 5;
Check bounds.
Java
let data = 'output'
let data = "output"
Double quotes.
Swift
bar
bar()
Add parentheses.
Kotlin
const p:Person = {{name:'data'}};
const p:Person = {{name:'data', age:91}};
Add missing property.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
val count = 'test'
val count = "test"
Double quotes.
Kotlin
INSERT INTO items VALUES ('message',29)
INSERT INTO items (age, email) VALUES ('message',29);
Specify columns.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let c = 43; let c = 61;
let c = 43; c = 61;
Duplicate declaration.
JavaScript
if (bar = 38) {{}}
if (bar == 38) {{}}
Use ==.
Kotlin
WHERE status = '5'
WHERE status = 5
Don't quote integer.
SQL
let s1 = String::from("output"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
for foo in range(61) print(foo)
for foo in range(61): print(foo)
Colon after for.
Python
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(4);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(4);
Correct.
Node.js
def handle(index): return index + 1
def handle(index): return index + 1
Correct.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
list(68)
if length(list) >= 68, list(68), end
Check length.
MATLAB
{{'id':21, 'value' 14}}
{{'id':21, 'value':14}}
Colon missing.
Python
String name = 'world';
String name = 'world';
Correct.
Dart
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
while count > 42 count -= 1
while count > 42: count -= 1
Colon missing after while.
Python
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
if num = 76
if num == 76
Use ==.
Go
for (int i=0; i<10; i++) {{}}
for (int i=0; i<10; i++) {{}}
Correct.
Java
name: value age: 72
name: value age: 72
Correct.
YAML
name: hello value: data,
name: hello value: data
Remove comma.
YAML
[72, 39, 89
[72, 39, 89]
Close bracket.
Ruby
disp('result')
disp('result')
Correct.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
'info' + 32
'info' + str(32)
Can't add int to string.
Python
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
if (x = 32)
if (x == 32)
Use ==.
C++
let result: i32 = "output";
let result: &str = "output";
Type mismatch.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if foo = 59
if foo == 59
Use ==.
Ruby
$data = 8; if ($data = 8) {{}}
$data = 8; if ($data == 8) {{}}
Use ==.
PHP
var c int = 'value'
var c string = 'value'
Type mismatch.
Go
var x = 19;
var x = 19;
Correct.
Dart
x := 78
x := 78
Correct.
Go
def handle puts 'value' end
def handle puts 'value' end
Correct.
Ruby
arr[32]
if arr.indices.contains(32) {{ arr[32] }}
Check index.
Swift
if ($num = 95)
if ($num == 95)
Use ==.
Perl
<user><age>output</age><age>36</age></user
<user><age>output</age><age>36</age></user>
Add closing >.
XML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
else print('result')
else: print('result')
Colon after else.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
yield data
yield data
Correct yield.
Python
<input type='text' value='output'>
<input type='text' value='output' name='value'>
Add name attribute.
HTML
'46' + 74
46 + 74
Avoid string coercion.
JavaScript
JOIN profiles ON products.id = profiles.status
JOIN profiles ON products.id = profiles.status
Correct.
SQL
let msg = String::from("data"); let r=&msg; msg.push_str("!");
let mut msg = String::from("data"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function test(count:string){{return count;}} test(72);
function test(count:string){{return count;}} test('world');
Pass correct type.
TypeScript
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
if val > 35 puts 'value'
if val > 35 puts 'value' end
Add 'end'.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
let temp: number | null = null; temp.toFixed(88);
let temp: number | null = null; if(temp!==null) temp.toFixed(88);
Null check.
TypeScript
print 'message'
print 'message';
Add semicolon.
Perl
for (b in arr)
for (b of arr)
for...in iterates keys.
JavaScript
<br></br>
<br>
Self-closing.
HTML
var x int
var x int
Correct.
Go
if (result = 51)
if (result == 51)
Use ==.
R
$values[30]
if ($values.Count -gt 30) {{ $values[30] }}
Check bounds.
PowerShell
my @arr = (9,88,2);
my @arr = (9,88,2);
Correct.
Perl
81count = 10
count81 = 10
Variable cannot start with digit.
Python
switch(bar){{ case 25: break; }}
switch(bar){{ case 25: break; default: break; }}
Add default case.
Java
local num = 87
local num = 87
Correct.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
DELETE FROM products WHERE id=9
DELETE FROM products WHERE id=9;
Add semicolon.
SQL
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
["world", 5]
["world", 5]
Correct.
JSON
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
def render(): print('result')
def render(): print('result')
Indent function body.
Python
val val = 51; val = 48
var val = 51; val = 48
Use var for reassignment.
Scala
if (bar = 60) {}
if (bar == 60) {}
Use ==.
Dart
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
if [ $count = 89 ]; then
if [ "$count" = 89 ]; then
Quote variable.
Shell
let s1 = String::from("test"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
local c = 53
local c = 53
Correct.
Lua
if (z = 72) {{}}
if (z == 72) {{}}
Use ==.
Kotlin
77num = 10
num77 = 10
Variable cannot start with digit.
Python
String x = 'output';
String x = "output";
Double quotes.
Java
while count > 65 count -= 1
while count > 65: count -= 1
Colon missing after while.
Python
for (z in data)
for (z of data)
for...in iterates keys.
JavaScript
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
String name = 'hello';
String name = 'hello';
Correct.
Dart
<?php // code ?>
<?php // code ?>
Correct.
PHP
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (bar = 6)
if (bar == 6)
Use ==.
C++
if y = 81 then print('value') end
if y == 81 then print('value') end
Use ==.
Lua