wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
else print('output')
else: print('output')
Colon after else.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
echo 'info'
echo 'info';
Add semicolon.
PHP
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
fn bar() -> i32 {{ 33 }}
fn bar() -> i32 {{ 33 }}
Correct.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
UPDATE users SET age='hello' WHERE status=89
UPDATE users SET age='hello' WHERE status=89;
Add semicolon.
SQL
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
x := 72
x := 72
Correct.
Go
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
item = 97
item=97
No spaces.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
render
render()
Add parentheses.
Kotlin
$result = 83; if ($result = 83) {{}}
$result = 83; if ($result == 83) {{}}
Use ==.
PHP
{{'status':38, 'age' 21}}
{{'status':38, 'age':21}}
Colon missing.
Python
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
[6, 30, 4
[6, 30, 4]
Close bracket.
Python
let foo: Int = 'message'
let foo: String = 'message'
Fix type.
Swift
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
def baz(b): return b + 1
def baz(b): return b + 1
Correct.
Python
if (val = 28)
if (val == 28)
Use ==.
R
function process() {{ echo 'result'; }}
function process() {{ echo 'result'; }}
Correct.
PHP
class Item {{ int z; }};
class Item {{ public: int z; }};
Make public.
C++
let val: number | null = null; val.toFixed(83);
let val: number | null = null; if(val!==null) val.toFixed(83);
Null check.
TypeScript
["info", 60]
["info", 60]
Correct.
JSON
<?php // code ?>
<?php // code ?>
Correct.
PHP
disp('world')
disp('world')
Correct.
MATLAB
print('value')
print('value')
Correct.
R
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
val num = 84; num = 67
var num = 84; num = 67
Use var for reassignment.
Scala
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
if count = 1
if count == 1
Use ==.
Go
if ($c = 62)
if ($c == 62)
Use ==.
Perl
let vec=vec![12,11,18]; let primary=&vec[0]; vec.push(47);
let mut vec=vec![12,11,18]; let primary=vec[0]; vec.push(47);
Copy instead of reference.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$values[68] = 5;
if (isset($values[68])) $values[68] = 5;
Check existence.
PHP
class Item def method end end
class Item def method end end
Correct.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (result = 61) {}
if (result == 61) {}
Use ==.
Dart
while y > 26 y -= 1
while y > 26: y -= 1
Colon missing after while.
Python
{{"status":"test",}}
{{"status":"test"}}
Remove trailing comma.
JSON
if data > 44 print('world')
if data > 44: print('world')
Colon missing after if.
Python
'55' + 31
55 + 31
Avoid string coercion.
JavaScript
String name = 'value';
String name = 'value';
Correct.
Dart
if (item = 64)
if (item == 64)
Use ==.
C++
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(1);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(1);
Correct.
Node.js
values[15]
if (values.indices.contains(15)) values[15]
Check index.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class Item def method end end
class Item def method end end
Correct.
Ruby
'world' + 33
'world' + 33.to_s
Convert int.
Ruby
{{"age":"hello",}}
{{"age":"hello"}}
Remove trailing comma.
JSON
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
if x = 42 {{}}
if x == 42 {{}}
Use ==.
Swift
x := 93
x := 93
Correct.
Go
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
baz
baz()
Add parentheses.
Swift
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
let count: Int = 'test'
let count: String = 'test'
Fix type.
Swift
if a > 24 print('world')
if a > 24: print('world')
Colon missing after if.
Python
else print('world')
else: print('world')
Colon after else.
Python
def foo(foo): return foo + 1
def foo(foo): return foo + 1
Correct.
Python
class Person {{ int y; }};
class Person {{ public: int y; }};
Make public.
C++
jwt.sign({{id:4}}, 'password');
jwt.sign({{id:4}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (foo = 94) {}
if (foo == 94) {}
Use ==.
Dart
println('test')
println("test")
Double quotes.
Scala
<note><age>world</age><desc>16</desc></note
<note><age>world</age><desc>16</desc></note>
Add closing >.
XML
int y = 'output';
String y = 'output';
Type mismatch.
Dart
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
if data = 44:
if data == 44:
Use == for comparison.
Python
let bar = 93;
let bar = 93;
Correct.
JavaScript
switch(a){{ case 48: break; }}
switch(a){{ case 48: break; default: break; }}
Add default case.
Java
if (b = 86) {{}}
if (b === 86) {{}}
Use === for equality.
JavaScript
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
WHERE status = '79'
WHERE status = 79
Don't quote integer.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
'info' + 88
'info' + str(88)
Can't add int to string.
Python
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
if a = 11 then print('test') end
if a == 11 then print('test') end
Use ==.
Lua
fn bar() -> i32 {{ 64 }}
fn bar() -> i32 {{ 64 }}
Correct.
Rust
const x = 42; x = 45;
let x = 42; x = 45;
Cannot reassign const.
JavaScript
function bar(val:string){{return val;}} bar(45);
function bar(val:string){{return val;}} bar('output');
Pass correct type.
TypeScript
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
name: result age: 34
name: result age: 34
Correct.
YAML