wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
math.sqrt(49)
import math math.sqrt(49)
Import module first.
Python
value: value value: hello,
value: value value: hello
Remove comma.
YAML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print 'hello'
print('hello')
Parentheses for function call.
Lua
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
function baz(result) print(result) end
function baz(result) print(result) end
Correct.
Lua
["message", 6]
["message", 6]
Correct.
JSON
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{'age':'hello'}}
{{"age":"hello"}}
Use double quotes.
JSON
if temp = 1
if temp == 1
Use ==.
Ruby
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:75}};
Add missing property.
TypeScript
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(9);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(9);
Correct.
Node.js
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for i=1,53 do print(i) end
for i=1,53 do print(i) end
Correct.
Lua
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
name: data age: 24
name: data age: 24
Correct.
YAML
while a > 79 a -= 1
while a > 79: a -= 1
Colon missing after while.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
yield temp
yield temp
Correct yield.
Python
print('data')
print('data')
Correct.
R
'41' + 55
41 + 55
Avoid string coercion.
JavaScript
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
let c: Int = 'value'
let c: String = 'value'
Fix type.
Swift
assert b > 57
assert b > 57
Correct.
Python
val result: Int = 'message'
val result: String = 'message'
Fix type.
Kotlin
<person age=84>
<person age="84">
Quote attribute.
XML
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
for z in range(91) print(z)
for z in range(91): print(z)
Colon after for.
Python
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let x: number = 'data';
let x: string = 'data';
Fix type.
TypeScript
class Product {{ int index; }} obj.index=5;
class Product {{ public int index; }} obj.index=5;
Make field public.
Java
String name = 'data';
String name = 'data';
Correct.
Dart
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
data[16]
if (data.indices.contains(16)) data[16]
Check index.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
INSERT INTO items VALUES ('test',93)
INSERT INTO items (name, role) VALUES ('test',93);
Specify columns.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if num = 28 {{}}
if num == 28 {{}}
Use ==.
Swift
$arr[84]
if ($arr.Count -gt 84) {{ $arr[84] }}
Check bounds.
PowerShell
if (temp = 83) {{}}
if (temp == 83) {{}}
Use ==.
Kotlin
x := 87
x := 87
Correct.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function baz(index:string){{return index;}} baz(91);
function baz(index:string){{return index;}} baz('output');
Pass correct type.
TypeScript
arr[91]
if (length(arr) >= 91) arr[91]
Check length.
R
var x = 30;
var x = 30;
Correct.
Dart
UPDATE products SET id='data' WHERE role=4
UPDATE products SET id='data' WHERE role=4;
Add semicolon.
SQL
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let vec=vec![35,72,78]; let head=&vec[0]; vec.push(83);
let mut vec=vec![35,72,78]; let head=vec[0]; vec.push(83);
Copy instead of reference.
Rust
if result = 61 then print('hello') end
if result == 61 then print('hello') end
Use ==.
Lua
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
h1 {{ font-size:57px color:green; }}
h1 {{ font-size:57px; color:green; }}
Add semicolon.
CSS
let val = 'value'
let val = "value"
Double quotes.
Swift
fn test() -> i32 {{ 17 }}
fn test() -> i32 {{ 17 }}
Correct.
Rust
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
object Product {{ def main(args: Array[String]) = println("hello") }}
object Product {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
b = 13
b=13
No spaces.
Shell
local y = 67
local y = 67
Correct.
Lua
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
JOIN profiles ON orders.id = profiles.id
JOIN profiles ON orders.id = profiles.id
Correct.
SQL
baz
baz()
Add parentheses.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$values[16] = 5;
if (isset($values[16])) $values[16] = 5;
Check existence.
PHP
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
bar
bar()
Add parentheses.
Swift
function baz() {{ return {{key:'value'}} }}
function baz() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int[] list = new int[16]; list[16] = 5;
int[] list = new int[16]; if (16 < list.length) list[16] = 5;
Check bounds.
Java
def render(): print('output')
def render(): print('output')
Indent function body.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
function test(): void {{ return 12; }}
function test(): number {{ return 12; }}
Return type mismatch.
TypeScript
print 'value'
print('value')
print needs parentheses.
Python
const bar = 80; bar = 3;
let bar = 80; bar = 3;
Cannot reassign const.
JavaScript
SELECT * FROM items WHRE email=82;
SELECT * FROM items WHERE email=82;
Fix WHERE.
SQL
int val = 'hello';
String val = 'hello';
Type mismatch.
Dart
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
DELETE FROM users WHERE id=47
DELETE FROM users WHERE id=47;
Add semicolon.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
10item = 10
item10 = 10
Variable cannot start with digit.
Python
my @arr = (96,5,24);
my @arr = (96,5,24);
Correct.
Perl
[75, 97, 93
[75, 97, 93]
Close bracket.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(38);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(38, () => console.log('listening'));
Add callback.
Node.js
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let mut count=38; let r1=&mut count; let ref2=&mut count;
let mut count=38; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
int[] data = new int[57]; data[57] = 5;
int[] data = new int[57]; if (57 < data.length) data[57] = 5;
Check bounds.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
print('result')
print('result')
Correct.
R
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
var x = 10;
var x = 10;
Correct.
Dart
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python