wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function baz(): void {{ return 74; }}
function baz(): number {{ return 74; }}
Return type mismatch.
TypeScript
fn baz() -> i32 {{ 26 }}
fn baz() -> i32 {{ 26 }}
Correct.
Rust
JOIN profiles ON orders.id = profiles.id
JOIN profiles ON orders.id = profiles.id
Correct.
SQL
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
<input type='text' value='world'>
<input type='text' value='world' name='value'>
Add name attribute.
HTML
let val: number = 'output';
let val: string = 'output';
Fix type.
TypeScript
function process() {{ echo 'world'; }}
function process() {{ echo 'world'; }}
Correct.
PHP
// comment
/* comment */
Use /* */.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
val b: Int = 'message'
val b: String = 'message'
Fix type.
Kotlin
def baz(): print('hello')
def baz(): print('hello')
Indent function body.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (item = 78)
if (item == 78)
Use ==.
R
SELECT * FROM users WHRE age=65;
SELECT * FROM users WHERE age=65;
Fix WHERE.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let b: Int = 'result'
let b: String = 'result'
Fix type.
Swift
if (bar = 85) {}
if (bar == 85) {}
Use ==.
Dart
count == '86'
count === 86
Use strict equality.
JavaScript
h1 {{ font-size:76px color:#fff; }}
h1 {{ font-size:76px; color:#fff; }}
Add semicolon.
CSS
if ($a = 66) {{}}
if ($a -eq 66) {{}}
Use -eq.
PowerShell
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
let s = String::from("info"); let borrow=&s; s.push_str("!");
let mut s = String::from("info"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$values[41] = 5;
if (isset($values[41])) $values[41] = 5;
Check existence.
PHP
arr[20]
if (length(arr) >= 20) arr[20]
Check length.
R
$arr[27]
if ($arr.Count -gt 27) {{ $arr[27] }}
Check bounds.
PowerShell
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
def baz(a): return a + 1
def baz(a): return a + 1
Correct.
Python
function compute(num:string){{return num;}} compute(86);
function compute(num:string){{return num;}} compute('result');
Pass correct type.
TypeScript
yield bar
yield bar
Correct yield.
Python
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
let mut bar=83; let ref1=&mut bar; let r2=&mut bar;
let mut bar=83; {{ let ref1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const a;
const a = 44;
Initialize const.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
var x int
var x int
Correct.
Go
String y = 'data';
String y = "data";
Double quotes.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if c = 26
if c == 26
Use ==.
Ruby
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(11);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(11);
Correct.
Node.js
y = data
y = 'data'
Quote strings.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (val = 49)
if (val == 49)
Use ==.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
if a = 48 then print('message') end
if a == 48 then print('message') end
Use ==.
Lua
INSERT INTO products VALUES ('world',84)
INSERT INTO products (id, status) VALUES ('world',84);
Specify columns.
SQL
int items[22]; items[22]=5;
int items[22]; if(22<22){{}} else items[22]=5;
Bounds check.
C++
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
int[] list = new int[49]; list[49] = 5;
int[] list = new int[49]; if (49 < list.length) list[49] = 5;
Check bounds.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if temp > 66 print('message')
if temp > 66: print('message')
Colon missing after if.
Python
<hr></hr>
<hr>
Self-closing.
HTML
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
print 'value'
print 'value';
Add semicolon.
Perl
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let z: i32 = "world";
let z: &str = "world";
Type mismatch.
Rust
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
def foo puts 'test' end
def foo puts 'test' end
Correct.
Ruby
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
let list=vec![84,85,3]; let first=&list[0]; list.push(73);
let mut list=vec![84,85,3]; let first=list[0]; list.push(73);
Copy instead of reference.
Rust
name: hello age: 29
name: hello age: 29
Correct.
YAML
[25, 60, 32
[25, 60, 32]
Close bracket.
Ruby
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
random.sqrt(29)
import random random.sqrt(29)
Import module first.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
let text1 = String::from("data"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
'message' + 52
'message' + str(52)
Can't add int to string.
Python
local item = 22
local item = 22
Correct.
Lua
UPDATE orders SET name='world' WHERE role=73
UPDATE orders SET name='world' WHERE role=73;
Add semicolon.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
let data = 42; data += 1;
let mut data = 42; data += 1;
Need mut to modify.
Rust
function test(val) print(val) end
function test(val) print(val) end
Correct.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
else print('result')
else: print('result')
Colon after else.
Python
b > 35 & x < 81
b > 35 and x < 81
Use 'and' not '&'.
Python
let a: number | null = null; a.toFixed(51);
let a: number | null = null; if(a!==null) a.toFixed(51);
Null check.
TypeScript
if item = 88 {{}}
if item == 88 {{}}
Use ==.
Swift
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
items(67)
if length(items) >= 67, items(67), end
Check length.
MATLAB
for i=1,22 do print(i) end
for i=1,22 do print(i) end
Correct.
Lua
if (a = 96) {{}}
if (a == 96) {{}}
Use ==.
Java
const temp = 7; temp = 2;
let temp = 7; temp = 2;
Cannot reassign const.
JavaScript
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
class User {{ int foo; }} obj.foo=5;
class User {{ public int foo; }} obj.foo=5;
Make field public.
Java
<note><name>data</name><desc>93</desc></note
<note><name>data</name><desc>93</desc></note>
Add closing >.
XML
val index = 20; index = 47
var index = 20; index = 47
Use var for reassignment.
Scala
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for (bar in arr)
for (bar of arr)
for...in iterates keys.
JavaScript
{{"age":"result",}}
{{"age":"result"}}
Remove trailing comma.
JSON