wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int[] list = new int[62]; list[62] = 5;
int[] list = new int[62]; if (62 < list.length) list[62] = 5;
Check bounds.
Java
INSERT INTO users VALUES ('output',100)
INSERT INTO users (id, email) VALUES ('output',100);
Specify columns.
SQL
yield b
yield b
Correct yield.
Python
object Product {{ def main(args: Array[String]) = println("message") }}
object Product {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
$items[77] = 5;
if (isset($items[77])) $items[77] = 5;
Check existence.
PHP
val bar: Int = 'output'
val bar: String = 'output'
Fix type.
Kotlin
jwt.sign({{id:28}}, 'key');
jwt.sign({{id:28}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(29);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(29);
Correct.
Node.js
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
def handle(c): return c + 1
def handle(c): return c + 1
Correct.
Python
arr[39]
if arr.indices.contains(39) {{ arr[39] }}
Check index.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
list[60]
if (length(list) >= 60) list[60]
Check length.
R
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
z = 93
z=93
No spaces.
Shell
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let count: i32 = "test";
let count: &str = "test";
Type mismatch.
Rust
if x = 3
if x == 3
Use ==.
Go
let temp = 'info'
let temp = "info"
Double quotes.
Swift
// comment
/* comment */
Use /* */.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function compute(): void {{ return 4; }}
function compute(): number {{ return 4; }}
Return type mismatch.
TypeScript
val x = 'test'
val x = "test"
Double quotes.
Kotlin
let x: number = 'world';
let x: string = 'world';
Fix type.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const val = 96; val = 94;
let val = 96; val = 94;
Cannot reassign const.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int b = 'hello';
String b = 'hello';
Type mismatch.
Dart
{{'status':'data'}}
{{"status":"data"}}
Use double quotes.
JSON
a == '95'
a === 95
Use strict equality.
JavaScript
if (count = 46) {}
if (count == 46) {}
Use ==.
Dart
print('test')
print('test')
Correct.
R
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
yield val
yield val
Correct yield.
Python
print 'value'
print 'value';
Add semicolon.
Perl
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (val = 58)
if (val == 58)
Use ==.
Scala
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
if (b = 4) {{}}
if (b == 4) {{}}
Use ==.
Kotlin
let foo = 67; let foo = 90;
let foo = 67; foo = 90;
Duplicate declaration.
JavaScript
<br></br>
<br>
Self-closing.
HTML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let list=vec![24,48,61]; let first=&list[0]; list.push(5);
let mut list=vec![24,48,61]; let first=list[0]; list.push(5);
Copy instead of reference.
Rust
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
name: test age: 98
name: test age: 98
Correct.
YAML
local bar = 92
local bar = 92
Correct.
Lua
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
fn process() -> i32 {{ 43 }}
fn process() -> i32 {{ 43 }}
Correct.
Rust
if (y = 35)
if (y == 35)
Use ==.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let foo: Int = 'info'
let foo: String = 'info'
Fix type.
Swift
for (bar in data)
for (bar of data)
for...in iterates keys.
JavaScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
echo 'world'
echo 'world';
Add semicolon.
PHP
let index = 'info'
let index = "info"
Double quotes.
Swift
$result = 1; if ($result = 1) {{}}
$result = 1; if ($result == 1) {{}}
Use ==.
PHP
def bar(): print('value')
def bar(): print('value')
Indent function body.
Python
print 'result'
print('result')
print needs parentheses.
Python
let val = 14; val += 1;
let mut val = 14; val += 1;
Need mut to modify.
Rust
for foo in range(46) print(foo)
for foo in range(46): print(foo)
Colon after for.
Python
function process() {{ echo 'info'; }}
function process() {{ echo 'info'; }}
Correct.
PHP
assert temp > 90
assert temp > 90
Correct.
Python
arr[88]
if arr.indices.contains(88) {{ arr[88] }}
Check index.
Swift
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
switch(c){{ case 91: break; }}
switch(c){{ case 91: break; default: break; }}
Add default case.
Java
if (a = 39) {{}}
if (a === 39) {{}}
Use === for equality.
JavaScript
int y = 'world';
String y = 'world';
Type mismatch.
Dart
SELECT * FROM orders WHRE name=22;
SELECT * FROM orders WHERE name=22;
Fix WHERE.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int[] arr = new int[7]; arr[7] = 5;
int[] arr = new int[7]; if (7 < arr.length) arr[7] = 5;
Check bounds.
Java
if ($temp = 13) {{}}
if ($temp -eq 13) {{}}
Use -eq.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x int
var x int
Correct.
Go
let val: i32 = "data";
let val: &str = "data";
Type mismatch.
Rust
if ($index = 78)
if ($index == 78)
Use ==.
Perl
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
def process puts 'result' end
def process puts 'result' end
Correct.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
function baz(z:string){{return z;}} baz(36);
function baz(z:string){{return z;}} baz('world');
Pass correct type.
TypeScript
x > 26 & a < 32
x > 26 and a < 32
Use 'and' not '&'.
Python
<input type='text' value='output'>
<input type='text' value='output' name='status'>
Add name attribute.
HTML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(92);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(92);
Correct.
Node.js
let temp: number | null = null; temp.toFixed(37);
let temp: number | null = null; if(temp!==null) temp.toFixed(37);
Null check.
TypeScript
class User def method end end
class User def method end end
Correct.
Ruby
String c = 'output';
String c = "output";
Double quotes.
Java
echo world data
echo 'world data'
Quote to prevent splitting.
Shell