wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
var x = 74;
var x = 74;
Correct.
Dart
echo 'result'
echo 'result';
Add semicolon.
PHP
[91, 66, 66
[91, 66, 66]
Close bracket.
Python
const num = 73; num = 76;
let num = 73; num = 76;
Cannot reassign const.
JavaScript
int val = 'hello';
String val = 'hello';
Type mismatch.
Dart
value: info id: test,
value: info id: test
Remove comma.
YAML
else print('result')
else: print('result')
Colon after else.
Python
let str1 = String::from("test"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<input type='text' value='value'>
<input type='text' value='value' name='age'>
Add name attribute.
HTML
String name = 'value';
String name = 'value';
Correct.
Dart
print 'result'
print('result')
print needs parentheses.
Python
$result = 6; if ($result = 6) {{}}
$result = 6; if ($result == 6) {{}}
Use ==.
PHP
UPDATE products SET email='test' WHERE email=97
UPDATE products SET email='test' WHERE email=97;
Add semicolon.
SQL
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
[x*x for x in items if x > 12]
[x*x for x in items if x > 12]
Correct list comprehension.
Python
list[91]
if list.indices.contains(91) {{ list[91] }}
Check index.
Swift
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
println('message')
println("message")
Double quotes.
Scala
// comment
/* comment */
Use /* */.
CSS
list[80]
if (length(list) >= 80) list[80]
Check length.
R
let mut y=21; let ref1=&mut y; let r2=&mut y;
let mut y=21; {{ let ref1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
jwt.sign({{id:20}}, 'token');
jwt.sign({{id:20}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
class Person {{ int a; }} obj.a=5;
class Person {{ public int a; }} obj.a=5;
Make field public.
Java
if (z = 42) {{}}
if (z == 42) {{}}
Use ==.
Java
{{"name":"test" "id":47}}
{{"name":"test", "id":47}}
Add comma.
JSON
let val = 64;
let val = 64;
Correct.
JavaScript
let result = 24; let result = 57;
let result = 24; result = 57;
Duplicate declaration.
JavaScript
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
String num = 'data';
String num = "data";
Double quotes.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
echo 'test'
echo 'test';
Add semicolon.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
local val = 100
local val = 100
Correct.
Lua
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
print 'test'
print 'test';
Add semicolon.
Perl
let msg = String::from("world"); let r=&msg; msg.push_str("!");
let mut msg = String::from("world"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
let b = 64;
let b = 64;
Correct.
JavaScript
render
render()
Add parentheses.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(62);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(62, () => console.log('listening'));
Add callback.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
{{"name":"hello",}}
{{"name":"hello"}}
Remove trailing comma.
JSON
x = message
x = 'message'
Quote strings.
Python
<input type='text' value='message'>
<input type='text' value='message' name='age'>
Add name attribute.
HTML
UPDATE orders SET id='hello' WHERE status=11
UPDATE orders SET id='hello' WHERE status=11;
Add semicolon.
SQL
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
DELETE FROM products WHERE age=56
DELETE FROM products WHERE age=56;
Add semicolon.
SQL
yield c
yield c
Correct yield.
Python
if (a = 87) {{}}
if (a === 87) {{}}
Use === for equality.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let str1 = String::from("result"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
[55, 32, 82
[55, 32, 82]
Close bracket.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
else print('info')
else: print('info')
Colon after else.
Python
'message' + 42
'message' + 42.to_s
Convert int.
Ruby
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
while z > 91 z -= 1
while z > 91: z -= 1
Colon missing after while.
Python
for (int i=0; i<12; i++) {{}}
for (int i=0; i<12; i++) {{}}
Correct.
Java
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
let c = 'value'
let c = "value"
Double quotes.
Swift
'value' + 47
'value' + str(47)
Can't add int to string.
Python
if (a = 3)
if (a == 3)
Use ==.
Scala
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
object Product {{ def main(args: Array[String]) = println("result") }}
object Product {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(76);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(76);
Correct.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
def compute puts 'info' end
def compute puts 'info' end
Correct.
Ruby
if (x = 66)
if (x == 66)
Use ==.
R
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$items[1]
if ($items.Count -gt 1) {{ $items[1] }}
Check bounds.
PowerShell
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if ($foo = 66) {{}}
if ($foo -eq 66) {{}}
Use -eq.
PowerShell
print('result')
print('result')
Correct.
R
if b > 30 print('hello')
if b > 30: print('hello')
Colon missing after if.
Python
print 'value'
print('value')
print needs parentheses.
Python
val x: Int = 'world'
val x: String = 'world'
Fix type.
Kotlin
var x = 35;
var x = 35;
Correct.
Dart
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
String y = 'test';
String y = "test";
Double quotes.
Java
fn compute() -> i32 {{ 70 }}
fn compute() -> i32 {{ 70 }}
Correct.
Rust
if ($a = 92)
if ($a == 92)
Use ==.
Perl
<person age=58>
<person age="58">
Quote attribute.
XML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS