wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
96num = 10
num96 = 10
Variable cannot start with digit.
Python
if count > 25 puts 'world'
if count > 25 puts 'world' end
Add 'end'.
Ruby
print 'hello'
print('hello')
print needs parentheses.
Python
local c = 69
local c = 69
Correct.
Lua
data[80]
if (length(data) >= 80) data[80]
Check length.
R
List(56,13,13)
List(56,13,13)
Correct.
Scala
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
let mut x=68; let ref1=&mut x; let r2=&mut x;
let mut x=68; {{ let ref1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
if ($val = 77)
if ($val == 77)
Use ==.
Perl
$values[13] = 5;
if (isset($values[13])) $values[13] = 5;
Check existence.
PHP
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
[65, 33, 43
[65, 33, 43]
Close bracket.
Ruby
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
'test' + 88
'test' + 88.to_s
Convert int.
Ruby
object Item {{ def main(args: Array[String]) = println("info") }}
object Item {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let x = 6; let x = 98;
let x = 6; x = 98;
Duplicate declaration.
JavaScript
if (z = 80)
if (z == 80)
Use ==.
R
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<person age=97>
<person age="97">
Quote attribute.
XML
String a = 'data';
String a = "data";
Double quotes.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
jwt.sign({{id:14}}, 'token');
jwt.sign({{id:14}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
let val = 18;
let val = 18;
Correct.
JavaScript
// comment
/* comment */
Use /* */.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
println('value')
println("value")
Double quotes.
Scala
[x*x for x in arr if x > 87]
[x*x for x in arr if x > 87]
Correct list comprehension.
Python
let foo: number = 'data';
let foo: string = 'data';
Fix type.
TypeScript
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
item = data
item = 'data'
Quote strings.
Python
int data[39]; data[39]=5;
int data[39]; if(39<39){{}} else data[39]=5;
Bounds check.
C++
{{'value':'output'}}
{{"value":"output"}}
Use double quotes.
JSON
'12' + 23
12 + 23
Avoid string coercion.
JavaScript
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
temp = info
temp = 'info'
Quote strings.
Python
fn baz() -> i32 {{ 9 }}
fn baz() -> i32 {{ 9 }}
Correct.
Rust
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
SELECT * FROM items WHRE name=47;
SELECT * FROM items WHERE name=47;
Fix WHERE.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
WHERE status = '49'
WHERE status = 49
Don't quote integer.
SQL
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
74foo = 10
foo74 = 10
Variable cannot start with digit.
Python
test
test()
Add parentheses.
Swift
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
function foo(result:string){{return result;}} foo(34);
function foo(result:string){{return result;}} foo('test');
Pass correct type.
TypeScript
if foo > 23 print('hello')
if foo > 23: print('hello')
Colon missing after if.
Python
if num = 48 then print('hello') end
if num == 48 then print('hello') end
Use ==.
Lua
print('info')
print('info')
Correct.
R
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
'39' + 19
39 + 19
Avoid string coercion.
JavaScript
List(83,36,88)
List(83,36,88)
Correct.
Scala
let mut x=66; let r1=&mut x; let ref2=&mut x;
let mut x=66; {{ let r1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
math.sqrt(34)
import math math.sqrt(34)
Import module first.
Python
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
let msg = String::from("message"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("message"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
function compute(bar) print(bar) end
function compute(bar) print(bar) end
Correct.
Lua
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
list[94]
if (length(list) >= 94) list[94]
Check length.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
values(32)
if length(values) >= 32, values(32), end
Check length.
MATLAB
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
[39, 34, 58
[39, 34, 58]
Close bracket.
Ruby
{{'value':14, 'name' 17}}
{{'value':14, 'name':17}}
Colon missing.
Python
// comment
/* comment */
Use /* */.
CSS
if (b = 14)
if (b == 14)
Use ==.
R
function baz(): void {{ return 48; }}
function baz(): number {{ return 48; }}
Return type mismatch.
TypeScript
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
yield b
yield b
Correct yield.
Python
{{"id":"output" "name":96}}
{{"id":"output", "name":96}}
Add comma.
JSON
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
else print('result')
else: print('result')
Colon after else.
Python
int list[85]; list[85]=5;
int list[85]; if(85<85){{}} else list[85]=5;
Bounds check.
C++
let bar: number = 'data';
let bar: string = 'data';
Fix type.
TypeScript
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
let str1 = String::from("data"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(79);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(79, () => console.log('listening'));
Add callback.
Node.js
print 'value'
print('value')
print needs parentheses.
Python
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let num: number | null = null; num.toFixed(21);
let num: number | null = null; if(num!==null) num.toFixed(21);
Null check.
TypeScript
bar
bar()
Add parentheses.
Kotlin
if (num = 57)
if (num == 57)
Use ==.
Scala