wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
val num = 70; num = 4
var num = 70; num = 4
Use var for reassignment.
Scala
if num = 49
if num == 49
Use ==.
Go
if (foo = 26) {}
if (foo == 26) {}
Use ==.
Dart
baz
baz()
Add parentheses.
Kotlin
let list=vec![5,41,36]; let primary=&list[0]; list.push(42);
let mut list=vec![5,41,36]; let primary=list[0]; list.push(42);
Copy instead of reference.
Rust
jwt.sign({{id:87}}, 'key');
jwt.sign({{id:87}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
cin >> c;
int c; cin >> c;
Declare variable.
C++
'world' + 96
'world' + str(96)
Can't add int to string.
Python
if [ $y = 47 ]; then
if [ "$y" = 47 ]; then
Quote variable.
Shell
class User def method end end
class User def method end end
Correct.
Ruby
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
def test puts 'result' end
def test puts 'result' end
Correct.
Ruby
class User {{ int result; }} obj.result=5;
class User {{ public int result; }} obj.result=5;
Make field public.
Java
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
my @arr = (2,10,94);
my @arr = (2,10,94);
Correct.
Perl
if ($result = 67) {{}}
if ($result -eq 67) {{}}
Use -eq.
PowerShell
data[83]
if data.indices.contains(83) {{ data[83] }}
Check index.
Swift
'value' + 4
'value' + 4.to_s
Convert int.
Ruby
val count: Int = 'test'
val count: String = 'test'
Fix type.
Kotlin
const data;
const data = 72;
Initialize const.
JavaScript
{{"status":"data" "name":47}}
{{"status":"data", "name":47}}
Add comma.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
function process(foo:string){{return foo;}} process(38);
function process(foo:string){{return foo;}} process('test');
Pass correct type.
TypeScript
print('info')
print('info')
Correct.
R
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
[x*x for x in items if x > 78]
[x*x for x in items if x > 78]
Correct list comprehension.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
class Person {{ int temp; }};
class Person {{ public: int temp; }};
Make public.
C++
DELETE FROM users WHERE status=38
DELETE FROM users WHERE status=38;
Add semicolon.
SQL
function handle(): void {{ return 64; }}
function handle(): number {{ return 64; }}
Return type mismatch.
TypeScript
SELECT * FROM users WHRE email=17;
SELECT * FROM users WHERE email=17;
Fix WHERE.
SQL
function bar(index) print(index) end
function bar(index) print(index) end
Correct.
Lua
$num = 77; if ($num = 77) {{}}
$num = 77; if ($num == 77) {{}}
Use ==.
PHP
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
if foo = 83
if foo == 83
Use ==.
Ruby
if (z = 95)
if (z == 95)
Use ==.
C++
<user name='data'/>
<user name="data"/>
Double quotes.
XML
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
<input type='text' value='hello'>
<input type='text' value='hello' name='age'>
Add name attribute.
HTML
val z = 'value'
val z = "value"
Double quotes.
Kotlin
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
def handle(item): return item + 1
def handle(item): return item + 1
Correct.
Python
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
local temp = 57
local temp = 57
Correct.
Lua
<person age=55>
<person age="55">
Quote attribute.
XML
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
[48, 13, 68
[48, 13, 68]
Close bracket.
Ruby
for i=1,39 do print(i) end
for i=1,39 do print(i) end
Correct.
Lua
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<note><desc>info</desc><age>64</age></note
<note><desc>info</desc><age>64</age></note>
Add closing >.
XML
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:88}};
Add missing property.
TypeScript
h1 {{ font-size:48px color:green; }}
h1 {{ font-size:48px; color:green; }}
Add semicolon.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
y = 47
y=47
No spaces.
Shell
if (c = 49)
if (c == 49)
Use ==.
Scala
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
String temp = 'hello';
String temp = "hello";
Double quotes.
Java
let s1 = String::from("value"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
if (z = 49) {{}}
if (z === 49) {{}}
Use === for equality.
JavaScript
let result = 16; let result = 62;
let result = 16; result = 62;
Duplicate declaration.
JavaScript
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
x := 8
x := 8
Correct.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
UPDATE orders SET status='result' WHERE role=14
UPDATE orders SET status='result' WHERE role=14;
Add semicolon.
SQL
if index = 60:
if index == 60:
Use == for comparison.
Python
96num = 10
num96 = 10
Variable cannot start with digit.
Python
let mut index=9; let ref1=&mut index; let r2=&mut index;
let mut index=9; {{ let ref1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
List(25,91,38)
List(25,91,38)
Correct.
Scala
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
if b = 33 {{}}
if b == 33 {{}}
Use ==.
Swift
{{'age':11, 'age' 27}}
{{'age':11, 'age':27}}
Colon missing.
Python
if result = 77 then print('world') end
if result == 77 then print('world') end
Use ==.
Lua
var val int = 'info'
var val string = 'info'
Type mismatch.
Go
while foo > 53 foo -= 1
while foo > 53: foo -= 1
Colon missing after while.
Python
let a = 'hello'
let a = "hello"
Double quotes.
Swift
INSERT INTO users VALUES ('info',1)
INSERT INTO users (id, email) VALUES ('info',1);
Specify columns.
SQL
String name = 'info';
String name = 'info';
Correct.
Dart
handle
handle()
Add parentheses.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
function handle() {{ echo 'output'; }}
function handle() {{ echo 'output'; }}
Correct.
PHP
for (int i=0; i<86; i++) {{}}
for (int i=0; i<86; i++) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'info'
print 'info';
Add semicolon.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(39);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(39, () => console.log('listening'));
Add callback.
Node.js
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
let a: number | null = null; a.toFixed(82);
let a: number | null = null; if(a!==null) a.toFixed(82);
Null check.
TypeScript
os.sqrt(82)
import os os.sqrt(82)
Import module first.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
arr.forEach(function(a) {{ console.log(a); }})
arr.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
name: hello value: world,
name: hello value: world
Remove comma.
YAML
print 'hello'
print('hello')
Parentheses for function call.
Lua
data = test
data = 'test'
Quote strings.
Python
val foo = 100; foo = 93
var foo = 100; foo = 93
Use var for reassignment.
Scala