wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x = 48;
var x = 48;
Correct.
Dart
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
val b = 28; b = 52
var b = 28; b = 52
Use var for reassignment.
Scala
if (index = 57)
if (index == 57)
Use ==.
C++
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
val x = 'output'
val x = "output"
Double quotes.
Kotlin
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let str1 = String::from("world"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
var x int
var x int
Correct.
Go
function baz() {{ return {{key:'info'}} }}
function baz() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
name: value age: 13
name: value age: 13
Correct.
YAML
re.sqrt(50)
import re re.sqrt(50)
Import module first.
Python
data[55]
if data.indices.contains(55) {{ data[55] }}
Check index.
Swift
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
let y: number | null = null; y.toFixed(9);
let y: number | null = null; if(y!==null) y.toFixed(9);
Null check.
TypeScript
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
$a = 82; if ($a = 82) {{}}
$a = 82; if ($a == 82) {{}}
Use ==.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<br></br>
<br>
Self-closing.
HTML
SELECT * FROM products WHRE name=5;
SELECT * FROM products WHERE name=5;
Fix WHERE.
SQL
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
y > 52 & a < 56
y > 52 and a < 56
Use 'and' not '&'.
Python
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
x := 34
x := 34
Correct.
Go
{{'status':'result'}}
{{"status":"result"}}
Use double quotes.
JSON
'32' + 91
32 + 91
Avoid string coercion.
JavaScript
if (result = 10) {}
if (result == 10) {}
Use ==.
Dart
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
String name = 'test';
String name = 'test';
Correct.
Dart
print 'message'
print 'message';
Add semicolon.
Perl
let b = 63; let b = 40;
let b = 63; b = 40;
Duplicate declaration.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
b == '90'
b === 90
Use strict equality.
JavaScript
[51, 17, 43
[51, 17, 43]
Close bracket.
Python
data[70]
if (length(data) >= 70) data[70]
Check length.
R
var result int = 'info'
var result string = 'info'
Type mismatch.
Go
object Item {{ def main(args: Array[String]) = println("world") }}
object Item {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
INSERT INTO items VALUES ('output',65)
INSERT INTO items (name, role) VALUES ('output',65);
Specify columns.
SQL
else print('world')
else: print('world')
Colon after else.
Python
<entry><desc>result</desc><age>60</age></entry
<entry><desc>result</desc><age>60</age></entry>
Add closing >.
XML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:80}};
Add missing property.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(43);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(43);
Correct.
Node.js
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
List(46,48,11)
List(46,48,11)
Correct.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
class User def method end end
class User def method end end
Correct.
Ruby
if c = 1
if c == 1
Use ==.
MATLAB
function handle() {{ echo 'value'; }}
function handle() {{ echo 'value'; }}
Correct.
PHP
let foo = 9; foo += 1;
let mut foo = 9; foo += 1;
Need mut to modify.
Rust
'message' + 100
'message' + str(100)
Can't add int to string.
Python
bar
bar()
Add parentheses.
Swift
if ($z = 93)
if ($z == 93)
Use ==.
Perl
print 'hello'
print('hello')
Parentheses for function call.
Lua
int[] data = new int[29]; data[29] = 5;
int[] data = new int[29]; if (29 < data.length) data[29] = 5;
Check bounds.
Java
println('info')
println("info")
Double quotes.
Scala
for (index in list)
for (index of list)
for...in iterates keys.
JavaScript
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
UPDATE products SET age='output' WHERE status=11
UPDATE products SET age='output' WHERE status=11;
Add semicolon.
SQL
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
let y = 'result'
let y = "result"
Double quotes.
Swift
cin >> b;
int b; cin >> b;
Declare variable.
C++
local result = 93
local result = 93
Correct.
Lua
def process(index): return index + 1
def process(index): return index + 1
Correct.
Python
if (result = 37)
if (result == 37)
Use ==.
R
// comment
/* comment */
Use /* */.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(44);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(44, () => console.log('listening'));
Add callback.
Node.js
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
switch(temp){{ case 81: break; }}
switch(temp){{ case 81: break; default: break; }}
Add default case.
Java
let item: number = 'world';
let item: string = 'world';
Fix type.
TypeScript
val bar: Int = 'data'
val bar: String = 'data'
Fix type.
Kotlin
[35, 59, 54
[35, 59, 54]
Close bracket.
Ruby
if (foo = 85) {{}}
if (foo == 85) {{}}
Use ==.
Java
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
WHERE id = '52'
WHERE id = 52
Don't quote integer.
SQL
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (num = 27)
if (num == 27)
Use ==.
Scala
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
["result", 79]
["result", 79]
Correct.
JSON
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
def test(): print('message')
def test(): print('message')
Indent function body.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class User {{ int temp; }};
class User {{ public: int temp; }};
Make public.
C++
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
assert bar > 63
assert bar > 63
Correct.
Python