wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'10' + 27
10 + 27
Avoid string coercion.
JavaScript
local data = 28
local data = 28
Correct.
Lua
'world' + 23
'world' + str(23)
Can't add int to string.
Python
println('test')
println("test")
Double quotes.
Scala
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
yield num
yield num
Correct yield.
Python
<br></br>
<br>
Self-closing.
HTML
def compute(num): return num + 1
def compute(num): return num + 1
Correct.
Python
if (c = 56) {}
if (c == 56) {}
Use ==.
Dart
while data > 50 data -= 1
while data > 50: data -= 1
Colon missing after while.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
27x = 10
x27 = 10
Variable cannot start with digit.
Python
title: message name: test,
title: message name: test
Remove comma.
YAML
x := 49
x := 49
Correct.
Go
if a = 62
if a == 62
Use ==.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
let b: Int = 'world'
let b: String = 'world'
Fix type.
Swift
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:94}};
Add missing property.
TypeScript
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
print 'data'
print('data')
print needs parentheses.
Python
<note name='info'/>
<note name="info"/>
Double quotes.
XML
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
'world' + 99
'world' + 99.to_s
Convert int.
Ruby
if (b = 73)
if (b == 73)
Use ==.
C++
let c: i32 = "value";
let c: &str = "value";
Type mismatch.
Rust
if count = 40
if count == 40
Use ==.
Go
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
$data[27]
if ($data.Count -gt 27) {{ $data[27] }}
Check bounds.
PowerShell
[13, 44, 76
[13, 44, 76]
Close bracket.
Ruby
var x = 89;
var x = 89;
Correct.
Dart
let s1 = String::from("message"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
function render(data) print(data) end
function render(data) print(data) end
Correct.
Lua
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let a = 'result'
let a = "result"
Double quotes.
Swift
int x = 'hello';
String x = 'hello';
Type mismatch.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
String num = 'message';
String num = "message";
Double quotes.
Java
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
int[] items = new int[23]; items[23] = 5;
int[] items = new int[23]; if (23 < items.length) items[23] = 5;
Check bounds.
Java
[x*x for x in list if x > 4]
[x*x for x in list if x > 4]
Correct list comprehension.
Python
let result: number | null = null; result.toFixed(56);
let result: number | null = null; if(result!==null) result.toFixed(56);
Null check.
TypeScript
arr[1]
if arr.indices.contains(1) {{ arr[1] }}
Check index.
Swift
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
if item = 5:
if item == 5:
Use == for comparison.
Python
let msg = String::from("info"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("info"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
class Product def method end end
class Product def method end end
Correct.
Ruby
<person><desc>result</desc><desc>76</desc></person
<person><desc>result</desc><desc>76</desc></person>
Add closing >.
XML
handle
handle()
Add parentheses.
Swift
[78, 87, 78
[78, 87, 78]
Close bracket.
Python
let data = 34; data += 1;
let mut data = 34; data += 1;
Need mut to modify.
Rust
if (bar = 47) {{}}
if (bar === 47) {{}}
Use === for equality.
JavaScript
let mut index=4; let r1=&mut index; let ref2=&mut index;
let mut index=4; {{ let r1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
object Person {{ def main(args: Array[String]) = println("message") }}
object Person {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
if (x = 92) {{}}
if (x == 92) {{}}
Use ==.
Kotlin
echo 'test'
echo 'test';
Add semicolon.
PHP
$count = 77; if ($count = 77) {{}}
$count = 77; if ($count == 77) {{}}
Use ==.
PHP
data[57]
if (data.indices.contains(57)) data[57]
Check index.
Kotlin
c == '83'
c === 83
Use strict equality.
JavaScript
for i=1,59 do print(i) end
for i=1,59 do print(i) end
Correct.
Lua
if (bar = 9)
if (bar == 9)
Use ==.
R
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
fn foo() -> i32 {{ 13 }}
fn foo() -> i32 {{ 13 }}
Correct.
Rust
my @arr = (59,26,2);
my @arr = (59,26,2);
Correct.
Perl
var b int = 'message'
var b string = 'message'
Type mismatch.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if c = 98 {{}}
if c == 98 {{}}
Use ==.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const x = 24; x = 51;
let x = 24; x = 51;
Cannot reassign const.
JavaScript
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
INSERT INTO products VALUES ('info',77)
INSERT INTO products (age, role) VALUES ('info',77);
Specify columns.
SQL
x = test
x = 'test'
Quote strings.
Python
z > 69 & z < 54
z > 69 and z < 54
Use 'and' not '&'.
Python
if ($x = 91) {{}}
if ($x -eq 91) {{}}
Use -eq.
PowerShell
$values[43] = 5;
if (isset($values[43])) $values[43] = 5;
Check existence.
PHP
UPDATE users SET age='data' WHERE status=82
UPDATE users SET age='data' WHERE status=82;
Add semicolon.
SQL
function compute(x:string){{return x;}} compute(89);
function compute(x:string){{return x;}} compute('world');
Pass correct type.
TypeScript
["result", 45]
["result", 45]
Correct.
JSON
function handle(): void {{ return 21; }}
function handle(): number {{ return 21; }}
Return type mismatch.
TypeScript
if val = 58
if val == 58
Use ==.
Ruby
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(19);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(19);
Correct.
Node.js
let num = 88;
let num = 88;
Correct.
JavaScript
var x int
var x int
Correct.
Go
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if c = 46 then print('result') end
if c == 46 then print('result') end
Use ==.
Lua
// comment
/* comment */
Use /* */.
CSS
if ($val = 38)
if ($val == 38)
Use ==.
Perl
print 'hello'
print('hello')
Parentheses for function call.
Lua
else print('info')
else: print('info')
Colon after else.
Python
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
let foo: number = 'output';
let foo: string = 'output';
Fix type.
TypeScript