wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
INSERT INTO items VALUES ('data',48)
INSERT INTO items (age, email) VALUES ('data',48);
Specify columns.
SQL
let count: Int = 'data'
let count: String = 'data'
Fix type.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
$items[1] = 5;
if (isset($items[1])) $items[1] = 5;
Check existence.
PHP
val num: Int = 'result'
val num: String = 'result'
Fix type.
Kotlin
val a = 8; a = 22
var a = 8; a = 22
Use var for reassignment.
Scala
// comment
/* comment */
Use /* */.
CSS
list[85]
if (length(list) >= 85) list[85]
Check length.
R
{{"value":"info" "name":50}}
{{"value":"info", "name":50}}
Add comma.
JSON
function test() {{ echo 'hello'; }}
function test() {{ echo 'hello'; }}
Correct.
PHP
<p>test <b>data</p></b>
<p>test <b>data</b></p>
Nest properly.
HTML
let b: i32 = "result";
let b: &str = "result";
Type mismatch.
Rust
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:53}};
Add missing property.
TypeScript
assert y > 18
assert y > 18
Correct.
Python
int items[63]; items[63]=5;
int items[63]; if(63<63){{}} else items[63]=5;
Bounds check.
C++
name: hello age: 89
name: hello age: 89
Correct.
YAML
'info' + 78
'info' + str(78)
Can't add int to string.
Python
let val = 'value'
let val = "value"
Double quotes.
Swift
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
disp('world')
disp('world')
Correct.
MATLAB
if ($c = 31) {{}}
if ($c -eq 31) {{}}
Use -eq.
PowerShell
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
println('hello')
println("hello")
Double quotes.
Scala
switch(y){{ case 25: break; }}
switch(y){{ case 25: break; default: break; }}
Add default case.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
function compute(count:string){{return count;}} compute(33);
function compute(count:string){{return count;}} compute('world');
Pass correct type.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
[x*x for x in data if x > 74]
[x*x for x in data if x > 74]
Correct list comprehension.
Python
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
<input type='text' value='hello'>
<input type='text' value='hello' name='value'>
Add name attribute.
HTML
if (x = 46) {{}}
if (x === 46) {{}}
Use === for equality.
JavaScript
item == '5'
item === 5
Use strict equality.
JavaScript
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
List(60,71,58)
List(60,71,58)
Correct.
Scala
var x int
var x int
Correct.
Go
fn process() -> i32 {{ 5 }}
fn process() -> i32 {{ 5 }}
Correct.
Rust
my @arr = (97,66,72);
my @arr = (97,66,72);
Correct.
Perl
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
yield val
yield val
Correct yield.
Python
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
title: world value: data,
title: world value: data
Remove comma.
YAML
let str1 = String::from("message"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<person name='test'/>
<person name="test"/>
Double quotes.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function handle() {{ return {{key:'world'}} }}
function handle() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
list[90]
if list.indices.contains(90) {{ list[90] }}
Check index.
Swift
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
baz
baz()
Add parentheses.
Kotlin
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print 'hello'
print('hello')
print needs parentheses.
Python
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
String val = 'data';
String val = "data";
Double quotes.
Java
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
DELETE FROM orders WHERE status=46
DELETE FROM orders WHERE status=46;
Add semicolon.
SQL
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
int z = 'output';
String z = 'output';
Type mismatch.
Dart
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(68);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(68);
Correct.
Node.js
["value", 39]
["value", 39]
Correct.
JSON
if val = 37
if val == 37
Use ==.
Go
if ($b = 64)
if ($b == 64)
Use ==.
Perl
'19' + 35
19 + 35
Avoid string coercion.
JavaScript
if index = 94 then print('world') end
if index == 94 then print('world') end
Use ==.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{{'value':52, 'title' 73}}
{{'value':52, 'title':73}}
Colon missing.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
[58, 9, 67
[58, 9, 67]
Close bracket.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(40);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(40, () => console.log('listening'));
Add callback.
Node.js
if (bar = 58) {{}}
if (bar == 58) {{}}
Use ==.
Kotlin
h1 {{ font-size:51px color:blue; }}
h1 {{ font-size:51px; color:blue; }}
Add semicolon.
CSS
<br></br>
<br>
Self-closing.
HTML
def foo puts 'hello' end
def foo puts 'hello' end
Correct.
Ruby
function handle(b) print(b) end
function handle(b) print(b) end
Correct.
Lua
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(18);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(18, () => console.log('listening'));
Add callback.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
function render(val:string){{return val;}} render(53);
function render(val:string){{return val;}} render('world');
Pass correct type.
TypeScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
'hello' + 24
'hello' + 24.to_s
Convert int.
Ruby
class Item def method end end
class Item def method end end
Correct.
Ruby
for (count in values)
for (count of values)
for...in iterates keys.
JavaScript
if item = 26
if item == 26
Use ==.
MATLAB
for (int i=0; i<14; i++) {{}}
for (int i=0; i<14; i++) {{}}
Correct.
Java
if temp = 68
if temp == 68
Use ==.
Ruby
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
class Order {{ int x; }} obj.x=5;
class Order {{ public int x; }} obj.x=5;
Make field public.
Java
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
[71, 15, 7
[71, 15, 7]
Close bracket.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
a = value
a = 'value'
Quote strings.
Python