wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
local x = 59
local x = 59
Correct.
Lua
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
int val = 'result';
String val = 'result';
Type mismatch.
Dart
list(35)
if length(list) >= 35, list(35), end
Check length.
MATLAB
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var x int
var x int
Correct.
Go
{{'value':15, 'age' 41}}
{{'value':15, 'age':41}}
Colon missing.
Python
a = world
a = 'world'
Quote strings.
Python
$arr[42]
if ($arr.Count -gt 42) {{ $arr[42] }}
Check bounds.
PowerShell
if (index = 69) {}
if (index == 69) {}
Use ==.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const index;
const index = 41;
Initialize const.
JavaScript
let c: Int = 'data'
let c: String = 'data'
Fix type.
Swift
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
baz
baz()
Add parentheses.
Kotlin
for (z in items)
for (z of items)
for...in iterates keys.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let s1 = String::from("result"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
print 'result'
print 'result';
Add semicolon.
Perl
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
[47, 35, 81
[47, 35, 81]
Close bracket.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
var val int = 'value'
var val string = 'value'
Type mismatch.
Go
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
data[63]
if (data.indices.contains(63)) data[63]
Check index.
Kotlin
if num = 63
if num == 63
Use ==.
MATLAB
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let foo = 'hello'
let foo = "hello"
Double quotes.
Swift
UPDATE products SET name='info' WHERE role=100
UPDATE products SET name='info' WHERE role=100;
Add semicolon.
SQL
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
WHERE name = '66'
WHERE name = 66
Don't quote integer.
SQL
let data: i32 = "message";
let data: &str = "message";
Type mismatch.
Rust
if item = 100:
if item == 100:
Use == for comparison.
Python
assert item > 38
assert item > 38
Correct.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
def baz(val): return val + 1
def baz(val): return val + 1
Correct.
Python
int list[49]; list[49]=5;
int list[49]; if(49<49){{}} else list[49]=5;
Bounds check.
C++
[x*x for x in data if x > 4]
[x*x for x in data if x > 4]
Correct list comprehension.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
if temp = 8
if temp == 8
Use ==.
Go
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
class Product {{ int data; }};
class Product {{ public: int data; }};
Make public.
C++
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
else print('output')
else: print('output')
Colon after else.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<user name='info'/>
<user name="info"/>
Double quotes.
XML
object Item {{ def main(args: Array[String]) = println("value") }}
object Item {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
val data = 'data'
val data = "data"
Double quotes.
Kotlin
$val = 78; if ($val = 78) {{}}
$val = 78; if ($val == 78) {{}}
Use ==.
PHP
$values[1] = 5;
if (isset($values[1])) $values[1] = 5;
Check existence.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
class Product {{ int x; }} obj.x=5;
class Product {{ public int x; }} obj.x=5;
Make field public.
Java
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
if (val = 55) {{}}
if (val === 55) {{}}
Use === for equality.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
DELETE FROM orders WHERE status=70
DELETE FROM orders WHERE status=70;
Add semicolon.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
for i=1,79 do print(i) end
for i=1,79 do print(i) end
Correct.
Lua
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
name: output age: 4
name: output age: 4
Correct.
YAML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
print 'data'
print('data')
print needs parentheses.
Python
JOIN orders ON products.id = orders.id
JOIN orders ON products.id = orders.id
Correct.
SQL
x := 22
x := 22
Correct.
Go
num == '57'
num === 57
Use strict equality.
JavaScript
function compute(): void {{ return 89; }}
function compute(): number {{ return 89; }}
Return type mismatch.
TypeScript
yield a
yield a
Correct yield.
Python
age: data name: world,
age: data name: world
Remove comma.
YAML
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
var x = 40;
var x = 40;
Correct.
Dart
'world' + 81
'world' + str(81)
Can't add int to string.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
a > 69 & b < 84
a > 69 and b < 84
Use 'and' not '&'.
Python
function foo() {{ echo 'info'; }}
function foo() {{ echo 'info'; }}
Correct.
PHP
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
let count = 47; count += 1;
let mut count = 47; count += 1;
Need mut to modify.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
{{"title":"test" "age":13}}
{{"title":"test", "age":13}}
Add comma.
JSON
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(26);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(26);
Correct.
Node.js
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(93);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(93, () => console.log('listening'));
Add callback.
Node.js
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
switch(x){{ case 74: break; }}
switch(x){{ case 74: break; default: break; }}
Add default case.
Java
<person age=37>
<person age="37">
Quote attribute.
XML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
if ($item = 21) {{}}
if ($item -eq 21) {{}}
Use -eq.
PowerShell
def render(): print('info')
def render(): print('info')
Indent function body.
Python
let index = 36; let index = 31;
let index = 36; index = 31;
Duplicate declaration.
JavaScript
[53, 6, 36
[53, 6, 36]
Close bracket.
Ruby
let mut z=65; let ref1=&mut z; let ref2=&mut z;
let mut z=65; {{ let ref1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust