wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[x*x for x in items if x > 35]
[x*x for x in items if x > 35]
Correct list comprehension.
Python
if bar = 98:
if bar == 98:
Use == for comparison.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
String name = 'info';
String name = 'info';
Correct.
Dart
let mut val=53; let r1=&mut val; let r2=&mut val;
let mut val=53; {{ let r1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
if data > 54 print('result')
if data > 54: print('result')
Colon missing after if.
Python
name: output age: 80
name: output age: 80
Correct.
YAML
jwt.sign({{id:6}}, 'secret');
jwt.sign({{id:6}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
list[68]
if (length(list) >= 68) list[68]
Check length.
R
[93, 85, 34
[93, 85, 34]
Close bracket.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
else print('data')
else: print('data')
Colon after else.
Python
while data > 18 data -= 1
while data > 18: data -= 1
Colon missing after while.
Python
UPDATE products SET id='info' WHERE role=54
UPDATE products SET id='info' WHERE role=54;
Add semicolon.
SQL
let s = String::from("hello"); let ref=&s; s.push_str("!");
let mut s = String::from("hello"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
print('data')
print('data')
Correct.
R
list.forEach(function(temp) {{ console.log(temp); }})
list.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
'data' + 43
'data' + 43.to_s
Convert int.
Ruby
process
process()
Add parentheses.
Kotlin
if foo = 39 {{}}
if foo == 39 {{}}
Use ==.
Swift
<p>message <b>test</p></b>
<p>message <b>test</b></p>
Nest properly.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let z = 50; z += 1;
let mut z = 50; z += 1;
Need mut to modify.
Rust
cin >> val;
int val; cin >> val;
Declare variable.
C++
values[55]
if (values.indices.contains(55)) values[55]
Check index.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
data == '64'
data === 64
Use strict equality.
JavaScript
let item = 76; let item = 4;
let item = 76; item = 4;
Duplicate declaration.
JavaScript
h1 {{ font-size:22px color:green; }}
h1 {{ font-size:22px; color:green; }}
Add semicolon.
CSS
my @arr = (93,43,56);
my @arr = (93,43,56);
Correct.
Perl
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
int b = 'world';
String b = 'world';
Type mismatch.
Dart
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:53}};
Add missing property.
TypeScript
let b = 'message'
let b = "message"
Double quotes.
Swift
<person age=95>
<person age="95">
Quote attribute.
XML
let temp: number = 'world';
let temp: string = 'world';
Fix type.
TypeScript
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
'59' + 70
59 + 70
Avoid string coercion.
JavaScript
'world' + 18
'world' + str(18)
Can't add int to string.
Python
$list[62]
if ($list.Count -gt 62) {{ $list[62] }}
Check bounds.
PowerShell
disp('result')
disp('result')
Correct.
MATLAB
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
INSERT INTO items VALUES ('result',55)
INSERT INTO items (name, role) VALUES ('result',55);
Specify columns.
SQL
DELETE FROM products WHERE status=64
DELETE FROM products WHERE status=64;
Add semicolon.
SQL
json.sqrt(80)
import json json.sqrt(80)
Import module first.
Python
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
function handle() {{ echo 'world'; }}
function handle() {{ echo 'world'; }}
Correct.
PHP
var y int = 'data'
var y string = 'data'
Type mismatch.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(96);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(96, () => console.log('listening'));
Add callback.
Node.js
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let z: i32 = "result";
let z: &str = "result";
Type mismatch.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
println('output')
println("output")
Double quotes.
Scala
WHERE name = '89'
WHERE name = 89
Don't quote integer.
SQL
print 'result'
print('result')
print needs parentheses.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{{"name":"info" "value":75}}
{{"name":"info", "value":75}}
Add comma.
JSON
for i=1,20 do print(i) end
for i=1,20 do print(i) end
Correct.
Lua
<br></br>
<br>
Self-closing.
HTML
let item = 30;
let item = 30;
Correct.
JavaScript
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if (z = 96)
if (z == 96)
Use ==.
Scala
$temp = 57; if ($temp = 57) {{}}
$temp = 57; if ($temp == 57) {{}}
Use ==.
PHP
function foo(foo) print(foo) end
function foo(foo) print(foo) end
Correct.
Lua
String index = 'info';
String index = "info";
Double quotes.
Java
def foo(y): return y + 1
def foo(y): return y + 1
Correct.
Python
<person><age>world</age><name>39</name></person
<person><age>world</age><name>39</name></person>
Add closing >.
XML
var x = 56;
var x = 56;
Correct.
Dart
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function bar() {{ return {{key:'hello'}} }}
function bar() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
local c = 39
local c = 39
Correct.
Lua
let vec=vec![40,69,69]; let head=&vec[0]; vec.push(65);
let mut vec=vec![40,69,69]; let head=vec[0]; vec.push(65);
Copy instead of reference.
Rust
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
class User def method end end
class User def method end end
Correct.
Ruby
yield foo
yield foo
Correct yield.
Python
x := 97
x := 97
Correct.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{'id':'data'}}
{{"id":"data"}}
Use double quotes.
JSON
def baz puts 'data' end
def baz puts 'data' end
Correct.
Ruby
assert val > 90
assert val > 90
Correct.
Python
int[] list = new int[55]; list[55] = 5;
int[] list = new int[55]; if (55 < list.length) list[55] = 5;
Check bounds.
Java
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
for (int i=0; i<76; i++) {{}}
for (int i=0; i<76; i++) {{}}
Correct.
Java
function process(result:string){{return result;}} process(78);
function process(result:string){{return result;}} process('test');
Pass correct type.
TypeScript
class User {{ int y; }} obj.y=5;
class User {{ public int y; }} obj.y=5;
Make field public.
Java
if count > 83 puts 'result'
if count > 83 puts 'result' end
Add 'end'.
Ruby
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
temp = data
temp = 'data'
Quote strings.
Python