wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
c == '98'
c === 98
Use strict equality.
JavaScript
let y = 84;
let y = 84;
Correct.
JavaScript
println('world')
println("world")
Double quotes.
Scala
let x: number = 'test';
let x: string = 'test';
Fix type.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
val foo: Int = 'world'
val foo: String = 'world'
Fix type.
Kotlin
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
let a: i32 = "output";
let a: &str = "output";
Type mismatch.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
'result' + 92
'result' + str(92)
Can't add int to string.
Python
let c = 'message'
let c = "message"
Double quotes.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
["hello", 3]
["hello", 3]
Correct.
JSON
print 'value'
print 'value';
Add semicolon.
Perl
if (a = 78)
if (a == 78)
Use ==.
R
if (z = 82) {{}}
if (z == 82) {{}}
Use ==.
Java
name: data age: 1
name: data age: 1
Correct.
YAML
if (result = 33)
if (result == 33)
Use ==.
C++
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def test puts 'result' end
def test puts 'result' end
Correct.
Ruby
var x = 8;
var x = 8;
Correct.
Dart
String name = 'value';
String name = 'value';
Correct.
Dart
let item = 4; item += 1;
let mut item = 4; item += 1;
Need mut to modify.
Rust
if result = 85
if result == 85
Use ==.
MATLAB
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
class Order {{ int c; }} obj.c=5;
class Order {{ public int c; }} obj.c=5;
Make field public.
Java
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if (a = 77)
if (a == 77)
Use ==.
Scala
WHERE email = '53'
WHERE email = 53
Don't quote integer.
SQL
data[6]
if (data.indices.contains(6)) data[6]
Check index.
Kotlin
def baz(): print('message')
def baz(): print('message')
Indent function body.
Python
for (result in items)
for (result of items)
for...in iterates keys.
JavaScript
DELETE FROM orders WHERE id=32
DELETE FROM orders WHERE id=32;
Add semicolon.
SQL
List(47,17,37)
List(47,17,37)
Correct.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
var x int
var x int
Correct.
Go
if count > 2 print('world')
if count > 2: print('world')
Colon missing after if.
Python
if (result = 80) {{}}
if (result === 80) {{}}
Use === for equality.
JavaScript
'info' + 87
'info' + 87.to_s
Convert int.
Ruby
h1 {{ font-size:62px color:green; }}
h1 {{ font-size:62px; color:green; }}
Add semicolon.
CSS
function compute(): void {{ return 79; }}
function compute(): number {{ return 79; }}
Return type mismatch.
TypeScript
if bar = 100
if bar == 100
Use ==.
Go
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
function render() {{ return {{key:'hello'}} }}
function render() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
let count: i32 = "message";
let count: &str = "message";
Type mismatch.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let bar: number = 'output';
let bar: string = 'output';
Fix type.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
'value' + 7
'value' + str(7)
Can't add int to string.
Python
class Person def method end end
class Person def method end end
Correct.
Ruby
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(86);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(86);
Correct.
Node.js
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
name: message title: test,
name: message title: test
Remove comma.
YAML
const result;
const result = 47;
Initialize const.
JavaScript
object Item {{ def main(args: Array[String]) = println("test") }}
object Item {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let temp: Int = 'world'
let temp: String = 'world'
Fix type.
Swift
let z = 34;
let z = 34;
Correct.
JavaScript
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
int arr[80]; arr[80]=5;
int arr[80]; if(80<80){{}} else arr[80]=5;
Bounds check.
C++
// comment
/* comment */
Use /* */.
CSS
let foo: number | null = null; foo.toFixed(25);
let foo: number | null = null; if(foo!==null) foo.toFixed(25);
Null check.
TypeScript
print 'hello'
print('hello')
print needs parentheses.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
if val = 85:
if val == 85:
Use == for comparison.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
'15' + 73
15 + 73
Avoid string coercion.
JavaScript
UPDATE users SET id='output' WHERE role=77
UPDATE users SET id='output' WHERE role=77;
Add semicolon.
SQL
bar == '25'
bar === 25
Use strict equality.
JavaScript
{{'status':87, 'age' 98}}
{{'status':87, 'age':98}}
Colon missing.
Python
function foo(z) print(z) end
function foo(z) print(z) end
Correct.
Lua
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if a > 14 puts 'result'
if a > 14 puts 'result' end
Add 'end'.
Ruby
if ($data = 72) {{}}
if ($data -eq 72) {{}}
Use -eq.
PowerShell
if num = 80 then print('info') end
if num == 80 then print('info') end
Use ==.
Lua
SELECT * FROM items WHRE status=13;
SELECT * FROM items WHERE status=13;
Fix WHERE.
SQL
if (bar = 2) {{}}
if (bar == 2) {{}}
Use ==.
Kotlin
def render(data): return data + 1
def render(data): return data + 1
Correct.
Python
var bar int = 'world'
var bar string = 'world'
Type mismatch.
Go
let a = 'info'
let a = "info"
Double quotes.
Swift
<br></br>
<br>
Self-closing.
HTML
yield num
yield num
Correct yield.
Python
INSERT INTO orders VALUES ('hello',26)
INSERT INTO orders (name, email) VALUES ('hello',26);
Specify columns.
SQL
{{"status":"message",}}
{{"status":"message"}}
Remove trailing comma.
JSON
disp('message')
disp('message')
Correct.
MATLAB
int[] list = new int[1]; list[1] = 5;
int[] list = new int[1]; if (1 < list.length) list[1] = 5;
Check bounds.
Java
JOIN orders ON items.id = orders.age
JOIN orders ON items.id = orders.age
Correct.
SQL
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:17}};
Add missing property.
TypeScript