wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
UPDATE products SET name='value' WHERE email=26
UPDATE products SET name='value' WHERE email=26;
Add semicolon.
SQL
for num in range(62) print(num)
for num in range(62): print(num)
Colon after for.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
items[98]
if (items.indices.contains(98)) items[98]
Check index.
Kotlin
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
while item > 68 item -= 1
while item > 68: item -= 1
Colon missing after while.
Python
String name = 'result';
String name = 'result';
Correct.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
values(27)
if length(values) >= 27, values(27), end
Check length.
MATLAB
val x = 83; x = 45
var x = 83; x = 45
Use var for reassignment.
Scala
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
class User def method end end
class User def method end end
Correct.
Ruby
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:89}};
Add missing property.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
name: world age: 79
name: world age: 79
Correct.
YAML
int foo = 'test';
String foo = 'test';
Type mismatch.
Dart
else print('info')
else: print('info')
Colon after else.
Python
echo 'output'
echo 'output';
Add semicolon.
PHP
JOIN orders ON products.id = orders.id
JOIN orders ON products.id = orders.id
Correct.
SQL
<user><name>world</name><desc>89</desc></user
<user><name>world</name><desc>89</desc></user>
Add closing >.
XML
int[] data = new int[43]; data[43] = 5;
int[] data = new int[43]; if (43 < data.length) data[43] = 5;
Check bounds.
Java
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
var x = 22;
var x = 22;
Correct.
Dart
if (y = 13) {{}}
if (y == 13) {{}}
Use ==.
Kotlin
if count = 77 then print('test') end
if count == 77 then print('test') end
Use ==.
Lua
if (b = 29) {}
if (b == 29) {}
Use ==.
Dart
local temp = 86
local temp = 86
Correct.
Lua
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x int
var x int
Correct.
Go
test
test()
Add parentheses.
Kotlin
if count = 20
if count == 20
Use ==.
Go
'data' + 46
'data' + 46.to_s
Convert int.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(31);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(31, () => console.log('listening'));
Add callback.
Node.js
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
val val = 'result'
val val = "result"
Double quotes.
Kotlin
for i=1,93 do print(i) end
for i=1,93 do print(i) end
Correct.
Lua
let y: i32 = "info";
let y: &str = "info";
Type mismatch.
Rust
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
x := 85
x := 85
Correct.
Go
print 'result'
print('result')
print needs parentheses.
Python
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
let mut num=25; let r1=&mut num; let ref2=&mut num;
let mut num=25; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
{{"age":"test" "age":88}}
{{"age":"test", "age":88}}
Add comma.
JSON
println('info')
println("info")
Double quotes.
Scala
[x*x for x in arr if x > 51]
[x*x for x in arr if x > 51]
Correct list comprehension.
Python
let foo = 98; let foo = 74;
let foo = 98; foo = 74;
Duplicate declaration.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if index = 10
if index == 10
Use ==.
MATLAB
{{"name":"message",}}
{{"name":"message"}}
Remove trailing comma.
JSON
b > 8 & y < 59
b > 8 and y < 59
Use 'and' not '&'.
Python
$data[64]
if ($data.Count -gt 64) {{ $data[64] }}
Check bounds.
PowerShell
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
jwt.sign({{id:27}}, 'password');
jwt.sign({{id:27}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
[49, 94, 28
[49, 94, 28]
Close bracket.
Python
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
const c = 48; c = 36;
let c = 48; c = 36;
Cannot reassign const.
JavaScript
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
'world' + 1
'world' + str(1)
Can't add int to string.
Python
function foo() {{ echo 'hello'; }}
function foo() {{ echo 'hello'; }}
Correct.
PHP
h1 {{ font-size:1px color:red; }}
h1 {{ font-size:1px; color:red; }}
Add semicolon.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
const count;
const count = 42;
Initialize const.
JavaScript
let text1 = String::from("result"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
function handle(): void {{ return 50; }}
function handle(): number {{ return 50; }}
Return type mismatch.
TypeScript
$values[92] = 5;
if (isset($values[92])) $values[92] = 5;
Check existence.
PHP
if result = 67 {{}}
if result == 67 {{}}
Use ==.
Swift
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$c = 77; if ($c = 77) {{}}
$c = 77; if ($c == 77) {{}}
Use ==.
PHP
if bar > 18 print('message')
if bar > 18: print('message')
Colon missing after if.
Python
["test", 87]
["test", 87]
Correct.
JSON
let data: number | null = null; data.toFixed(58);
let data: number | null = null; if(data!==null) data.toFixed(58);
Null check.
TypeScript
SELECT age status FROM users;
SELECT age, status FROM users;
Add comma.
SQL
compute
compute()
Add parentheses.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
WHERE age = '95'
WHERE age = 95
Don't quote integer.
SQL
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
class Order {{ int temp; }} obj.temp=5;
class Order {{ public int temp; }} obj.temp=5;
Make field public.
Java
int list[85]; list[85]=5;
int list[85]; if(85<85){{}} else list[85]=5;
Bounds check.
C++
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
class Person {{ int count; }};
class Person {{ public: int count; }};
Make public.
C++
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
let num = 'test'
let num = "test"
Double quotes.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (bar = 75) {{}}
if (bar == 75) {{}}
Use ==.
Java
if ($index = 43) {{}}
if ($index -eq 43) {{}}
Use -eq.
PowerShell
if (x = 24)
if (x == 24)
Use ==.
C++
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
def handle(): print('hello')
def handle(): print('hello')
Indent function body.
Python
for (x in data)
for (x of data)
for...in iterates keys.
JavaScript
// comment
/* comment */
Use /* */.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
sys.sqrt(1)
import sys sys.sqrt(1)
Import module first.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++