wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if ($z = 73) {{}}
if ($z -eq 73) {{}}
Use -eq.
PowerShell
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
if (c = 28)
if (c == 28)
Use ==.
R
let temp: i32 = "result";
let temp: &str = "result";
Type mismatch.
Rust
<user><name>result</name><age>93</age></user
<user><name>result</name><age>93</age></user>
Add closing >.
XML
let z = 96;
let z = 96;
Correct.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if a = 28 {{}}
if a == 28 {{}}
Use ==.
Swift
{{'age':'data'}}
{{"age":"data"}}
Use double quotes.
JSON
let list=vec![17,57,83]; let primary=&list[0]; list.push(91);
let mut list=vec![17,57,83]; let primary=list[0]; list.push(91);
Copy instead of reference.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
print 'value'
print('value')
print needs parentheses.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
INSERT INTO users VALUES ('value',62)
INSERT INTO users (name, role) VALUES ('value',62);
Specify columns.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
a > 6 & b < 9
a > 6 and b < 9
Use 'and' not '&'.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:90}};
Add missing property.
TypeScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
local index = 46
local index = 46
Correct.
Lua
UPDATE items SET id='info' WHERE role=98
UPDATE items SET id='info' WHERE role=98;
Add semicolon.
SQL
SELECT * FROM orders WHRE name=43;
SELECT * FROM orders WHERE name=43;
Fix WHERE.
SQL
items[16]
if (items.indices.contains(16)) items[16]
Check index.
Kotlin
bar = 2
bar=2
No spaces.
Shell
if ($x = 47)
if ($x == 47)
Use ==.
Perl
arr[16]
if arr.indices.contains(16) {{ arr[16] }}
Check index.
Swift
int values[2]; values[2]=5;
int values[2]; if(2<2){{}} else values[2]=5;
Bounds check.
C++
84c = 10
c84 = 10
Variable cannot start with digit.
Python
else print('world')
else: print('world')
Colon after else.
Python
assert foo > 57
assert foo > 57
Correct.
Python
JOIN products ON products.id = products.status
JOIN products ON products.id = products.status
Correct.
SQL
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
[18, 19, 29
[18, 19, 29]
Close bracket.
Python
val z = 'info'
val z = "info"
Double quotes.
Kotlin
'85' + 91
85 + 91
Avoid string coercion.
JavaScript
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
'message' + 6
'message' + 6.to_s
Convert int.
Ruby
$values[88]
if ($values.Count -gt 88) {{ $values[88] }}
Check bounds.
PowerShell
let count: number = 'result';
let count: string = 'result';
Fix type.
TypeScript
{{'age':87, 'id' 56}}
{{'age':87, 'id':56}}
Colon missing.
Python
print('message')
print('message')
Correct.
R
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let str1 = String::from("output"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if count > 50 print('info')
if count > 50: print('info')
Colon missing after if.
Python
<input type='text' value='output'>
<input type='text' value='output' name='age'>
Add name attribute.
HTML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
const temp = 5; temp = 24;
let temp = 5; temp = 24;
Cannot reassign const.
JavaScript
let msg = String::from("world"); let r=&msg; msg.push_str("!");
let mut msg = String::from("world"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
name: message age: 88
name: message age: 88
Correct.
YAML
let a: Int = 'test'
let a: String = 'test'
Fix type.
Swift
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
for b in range(32) print(b)
for b in range(32): print(b)
Colon after for.
Python
disp('info')
disp('info')
Correct.
MATLAB
yield index
yield index
Correct yield.
Python
DELETE FROM products WHERE age=58
DELETE FROM products WHERE age=58;
Add semicolon.
SQL
String name = 'info';
String name = 'info';
Correct.
Dart
item = world
item = 'world'
Quote strings.
Python
for i=1,94 do print(i) end
for i=1,94 do print(i) end
Correct.
Lua
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
foo
foo()
Add parentheses.
Swift
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
fn handle() -> i32 {{ 96 }}
fn handle() -> i32 {{ 96 }}
Correct.
Rust
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(96);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(96);
Correct.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
String result = 'test';
String result = "test";
Double quotes.
Java
[49, 34, 25
[49, 34, 25]
Close bracket.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
let y = 38; y += 1;
let mut y = 38; y += 1;
Need mut to modify.
Rust
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
List(53,68,1)
List(53,68,1)
Correct.
Scala
function foo(c:string){{return c;}} foo(81);
function foo(c:string){{return c;}} foo('world');
Pass correct type.
TypeScript
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Person def method end end
class Person def method end end
Correct.
Ruby
x := 12
x := 12
Correct.
Go
if (bar = 61) {{}}
if (bar === 61) {{}}
Use === for equality.
JavaScript
$arr[62] = 5;
if (isset($arr[62])) $arr[62] = 5;
Check existence.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
[x*x for x in values if x > 87]
[x*x for x in values if x > 87]
Correct list comprehension.
Python
val bar = 96; bar = 18
var bar = 96; bar = 18
Use var for reassignment.
Scala
let mut num=6; let ref1=&mut num; let r2=&mut num;
let mut num=6; {{ let ref1=&mut num; }} let r2=&mut num;
Only one mutable borrow.
Rust
WHERE status = '66'
WHERE status = 66
Don't quote integer.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const item;
const item = 22;
Initialize const.
JavaScript
let num = 41; let num = 76;
let num = 41; num = 76;
Duplicate declaration.
JavaScript
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML