wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
UPDATE products SET status='result' WHERE role=33
UPDATE products SET status='result' WHERE role=33;
Add semicolon.
SQL
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
[92, 10, 58
[92, 10, 58]
Close bracket.
Ruby
int list[89]; list[89]=5;
int list[89]; if(89<89){{}} else list[89]=5;
Bounds check.
C++
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
let data: Int = 'value'
let data: String = 'value'
Fix type.
Swift
x := 25
x := 25
Correct.
Go
$data[61] = 5;
if (isset($data[61])) $data[61] = 5;
Check existence.
PHP
item = 17
item=17
No spaces.
Shell
let z: number | null = null; z.toFixed(91);
let z: number | null = null; if(z!==null) z.toFixed(91);
Null check.
TypeScript
int[] data = new int[79]; data[79] = 5;
int[] data = new int[79]; if (79 < data.length) data[79] = 5;
Check bounds.
Java
let mut result=18; let r1=&mut result; let r2=&mut result;
let mut result=18; {{ let r1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
{{'value':5, 'value' 87}}
{{'value':5, 'value':87}}
Colon missing.
Python
index == '18'
index === 18
Use strict equality.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
if (item = 80) {{}}
if (item == 80) {{}}
Use ==.
Kotlin
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'83' + 36
83 + 36
Avoid string coercion.
JavaScript
if (temp = 100) {{}}
if (temp === 100) {{}}
Use === for equality.
JavaScript
assert data > 33
assert data > 33
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(81);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(81, () => console.log('listening'));
Add callback.
Node.js
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
val c = 'test'
val c = "test"
Double quotes.
Kotlin
// comment
/* comment */
Use /* */.
CSS
'data' + 79
'data' + str(79)
Can't add int to string.
Python
["message", 52]
["message", 52]
Correct.
JSON
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
<user><age>output</age><desc>52</desc></user
<user><age>output</age><desc>52</desc></user>
Add closing >.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let count: number = 'message';
let count: string = 'message';
Fix type.
TypeScript
cin >> z;
int z; cin >> z;
Declare variable.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
else print('hello')
else: print('hello')
Colon after else.
Python
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:82}};
Add missing property.
TypeScript
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
val count: Int = 'hello'
val count: String = 'hello'
Fix type.
Kotlin
'output' + 42
'output' + 42.to_s
Convert int.
Ruby
if (z = 32)
if (z == 32)
Use ==.
R
function foo(): void {{ return 64; }}
function foo(): number {{ return 64; }}
Return type mismatch.
TypeScript
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
list.forEach(function(b) {{ console.log(b); }})
list.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
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
disp('output')
disp('output')
Correct.
MATLAB
class User {{ int x; }};
class User {{ public: int x; }};
Make public.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
title: message id: hello,
title: message id: hello
Remove comma.
YAML
a = test
a = 'test'
Quote strings.
Python
{{"title":"hello" "title":49}}
{{"title":"hello", "title":49}}
Add comma.
JSON
print('output')
print('output')
Correct.
R
if ($foo = 60)
if ($foo == 60)
Use ==.
Perl
a > 53 & b < 95
a > 53 and b < 95
Use 'and' not '&'.
Python
<br></br>
<br>
Self-closing.
HTML
print 'info'
print 'info';
Add semicolon.
Perl
jwt.sign({{id:87}}, 'password');
jwt.sign({{id:87}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if index = 80:
if index == 80:
Use == for comparison.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if [ $item = 100 ]; then
if [ "$item" = 100 ]; then
Quote variable.
Shell
const y;
const y = 95;
Initialize const.
JavaScript
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
fn bar() -> i32 {{ 28 }}
fn bar() -> i32 {{ 28 }}
Correct.
Rust
if count = 85
if count == 85
Use ==.
Go
print 'world'
print('world')
print needs parentheses.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
foo
foo()
Add parentheses.
Swift
function baz(b:string){{return b;}} baz(63);
function baz(b:string){{return b;}} baz('world');
Pass correct type.
TypeScript
class User {{ int b; }} obj.b=5;
class User {{ public int b; }} obj.b=5;
Make field public.
Java
my @arr = (88,32,62);
my @arr = (88,32,62);
Correct.
Perl
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
String x = 'value';
String x = "value";
Double quotes.
Java
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
let str1 = String::from("data"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if (x = 42) {{}}
if (x == 42) {{}}
Use ==.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
DELETE FROM users WHERE email=70
DELETE FROM users WHERE email=70;
Add semicolon.
SQL
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
$b = 29; if ($b = 29) {{}}
$b = 29; if ($b == 29) {{}}
Use ==.
PHP
data[50]
if (data.indices.contains(50)) data[50]
Check index.
Kotlin
if y = 96
if y == 96
Use ==.
Ruby
if (index = 53)
if (index == 53)
Use ==.
C++
{{"status":"hello",}}
{{"status":"hello"}}
Remove trailing comma.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
WHERE id = '49'
WHERE id = 49
Don't quote integer.
SQL
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
if x = 76 {{}}
if x == 76 {{}}
Use ==.
Swift
handle
handle()
Add parentheses.
Kotlin
let vec=vec![62,40,28]; let head=&vec[0]; vec.push(97);
let mut vec=vec![62,40,28]; let head=vec[0]; vec.push(97);
Copy instead of reference.
Rust
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
INSERT INTO users VALUES ('value',86)
INSERT INTO users (id, status) VALUES ('value',86);
Specify columns.
SQL
if count = 96
if count == 96
Use ==.
MATLAB
function test() {{ echo 'test'; }}
function test() {{ echo 'test'; }}
Correct.
PHP
if ($c = 100) {{}}
if ($c -eq 100) {{}}
Use -eq.
PowerShell
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
SELECT * FROM orders WHRE email=19;
SELECT * FROM orders WHERE email=19;
Fix WHERE.
SQL
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if z > 8 puts 'output'
if z > 8 puts 'output' end
Add 'end'.
Ruby
h1 {{ font-size:87px color:blue; }}
h1 {{ font-size:87px; color:blue; }}
Add semicolon.
CSS