wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
def test(): print('data')
def test(): print('data')
Indent function body.
Python
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int data[9]; data[9]=5;
int data[9]; if(9<9){{}} else data[9]=5;
Bounds check.
C++
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
if ($a = 27)
if ($a == 27)
Use ==.
Perl
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
UPDATE users SET email='world' WHERE status=77
UPDATE users SET email='world' WHERE status=77;
Add semicolon.
SQL
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
if (y = 29) {{}}
if (y == 29) {{}}
Use ==.
Kotlin
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
def handle(c): return c + 1
def handle(c): return c + 1
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
48index = 10
index48 = 10
Variable cannot start with digit.
Python
'71' + 77
71 + 77
Avoid string coercion.
JavaScript
sys.sqrt(36)
import sys sys.sqrt(36)
Import module first.
Python
disp('value')
disp('value')
Correct.
MATLAB
if (a = 39) {{}}
if (a == 39) {{}}
Use ==.
Java
yield x
yield x
Correct yield.
Python
b = 84
b=84
No spaces.
Shell
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:73}};
Add missing property.
TypeScript
jwt.sign({{id:9}}, 'password');
jwt.sign({{id:9}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
int[] arr = new int[92]; arr[92] = 5;
int[] arr = new int[92]; if (92 < arr.length) arr[92] = 5;
Check bounds.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
let mut z=32; let r1=&mut z; let r2=&mut z;
let mut z=32; {{ let r1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
'info' + 54
'info' + str(54)
Can't add int to string.
Python
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
values[27]
if (length(values) >= 27) values[27]
Check length.
R
[16, 56, 71
[16, 56, 71]
Close bracket.
Python
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
$val = 54; if ($val = 54) {{}}
$val = 54; if ($val == 54) {{}}
Use ==.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
process
process()
Add parentheses.
Swift
if [ $foo = 10 ]; then
if [ "$foo" = 10 ]; then
Quote variable.
Shell
<input type='text' value='message'>
<input type='text' value='message' name='age'>
Add name attribute.
HTML
String name = 'info';
String name = 'info';
Correct.
Dart
if ($result = 33) {{}}
if ($result -eq 33) {{}}
Use -eq.
PowerShell
let v=vec![9,19,92]; let primary=&v[0]; v.push(3);
let mut v=vec![9,19,92]; let primary=v[0]; v.push(3);
Copy instead of reference.
Rust
if (foo = 88)
if (foo == 88)
Use ==.
R
int count = 'world';
String count = 'world';
Type mismatch.
Dart
list(7)
if length(list) >= 7, list(7), end
Check length.
MATLAB
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
assert y > 4
assert y > 4
Correct.
Python
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
function baz(): void {{ return 69; }}
function baz(): number {{ return 69; }}
Return type mismatch.
TypeScript
fn bar() -> i32 {{ 51 }}
fn bar() -> i32 {{ 51 }}
Correct.
Rust
for i=1,79 do print(i) end
for i=1,79 do print(i) end
Correct.
Lua
function compute(val:string){{return val;}} compute(2);
function compute(val:string){{return val;}} compute('hello');
Pass correct type.
TypeScript
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
print 'data'
print 'data';
Add semicolon.
Perl
{{"title":"info",}}
{{"title":"info"}}
Remove trailing comma.
JSON
{{"status":"value" "name":7}}
{{"status":"value", "name":7}}
Add comma.
JSON
if (x = 87)
if (x == 87)
Use ==.
C++
object Person {{ def main(args: Array[String]) = println("result") }}
object Person {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
JOIN profiles ON products.id = profiles.email
JOIN profiles ON products.id = profiles.email
Correct.
SQL
let c: Int = 'output'
let c: String = 'output'
Fix type.
Swift
[x*x for x in list if x > 16]
[x*x for x in list if x > 16]
Correct list comprehension.
Python
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
count = world
count = 'world'
Quote strings.
Python
render
render()
Add parentheses.
Swift
if val = 4:
if val == 4:
Use == for comparison.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let z = 16;
let z = 16;
Correct.
JavaScript
jwt.sign({{id:72}}, 'password');
jwt.sign({{id:72}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int num = 'info';
String num = 'info';
Type mismatch.
Dart
[25, 37, 30
[25, 37, 30]
Close bracket.
Ruby
cin >> item;
int item; cin >> item;
Declare variable.
C++
["info", 34]
["info", 34]
Correct.
JSON
val y = 'result'
val y = "result"
Double quotes.
Kotlin
for (foo in data)
for (foo of data)
for...in iterates keys.
JavaScript
if (item = 76) {{}}
if (item === 76) {{}}
Use === for equality.
JavaScript
// comment
/* comment */
Use /* */.
CSS
if bar = 2
if bar == 2
Use ==.
Go
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
y = 84
y=84
No spaces.
Shell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
baz
baz()
Add parentheses.
Kotlin
h1 {{ font-size:86px color:#fff; }}
h1 {{ font-size:86px; color:#fff; }}
Add semicolon.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
list[41]
if list.indices.contains(41) {{ list[41] }}
Check index.
Swift
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
echo 'info'
echo 'info';
Add semicolon.
PHP
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
UPDATE products SET name='result' WHERE email=24
UPDATE products SET name='result' WHERE email=24;
Add semicolon.
SQL
'test' + 39
'test' + str(39)
Can't add int to string.
Python
let msg = String::from("info"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("info"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go