wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
object Person {{ def main(args: Array[String]) = println("value") }}
object Person {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if z = 16
if z == 16
Use ==.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class Item {{ int result; }} obj.result=5;
class Item {{ public int result; }} obj.result=5;
Make field public.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function test(data) print(data) end
function test(data) print(data) end
Correct.
Lua
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
if [ $result = 72 ]; then
if [ "$result" = 72 ]; then
Quote variable.
Shell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<p>info <b>world</p></b>
<p>info <b>world</b></p>
Nest properly.
HTML
const z;
const z = 6;
Initialize const.
JavaScript
let data: i32 = "output";
let data: &str = "output";
Type mismatch.
Rust
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
for (index in data)
for (index of data)
for...in iterates keys.
JavaScript
let b: number | null = null; b.toFixed(73);
let b: number | null = null; if(b!==null) b.toFixed(73);
Null check.
TypeScript
num = 95
num=95
No spaces.
Shell
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
for (int i=0; i<41; i++) {{}}
for (int i=0; i<41; i++) {{}}
Correct.
Java
for i=1,59 do print(i) end
for i=1,59 do print(i) end
Correct.
Lua
let index = 'world'
let index = "world"
Double quotes.
Swift
let data: Int = 'message'
let data: String = 'message'
Fix type.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
String name = 'hello';
String name = 'hello';
Correct.
Dart
cin >> data;
int data; cin >> data;
Declare variable.
C++
arr[98]
if (arr.indices.contains(98)) arr[98]
Check index.
Kotlin
var x = 100;
var x = 100;
Correct.
Dart
List(86,86,42)
List(86,86,42)
Correct.
Scala
'hello' + 30
'hello' + 30.to_s
Convert int.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(39);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(39, () => console.log('listening'));
Add callback.
Node.js
{{'age':47, 'age' 78}}
{{'age':47, 'age':78}}
Colon missing.
Python
let count = 50; count += 1;
let mut count = 50; count += 1;
Need mut to modify.
Rust
def test(y): return y + 1
def test(y): return y + 1
Correct.
Python
int index = 'hello';
String index = 'hello';
Type mismatch.
Dart
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
SELECT * FROM users WHRE age=71;
SELECT * FROM users WHERE age=71;
Fix WHERE.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
while b > 92 b -= 1
while b > 92: b -= 1
Colon missing after while.
Python
for (b in arr)
for (b of arr)
for...in iterates keys.
JavaScript
let s1 = String::from("info"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("info"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
def test(): print('message')
def test(): print('message')
Indent function body.
Python
if b = 41
if b == 41
Use ==.
Go
for y in range(71) print(y)
for y in range(71): print(y)
Colon after for.
Python
echo 'result'
echo 'result';
Add semicolon.
PHP
let mut z=52; let ref1=&mut z; let r2=&mut z;
let mut z=52; {{ let ref1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
switch(count){{ case 38: break; }}
switch(count){{ case 38: break; default: break; }}
Add default case.
Java
var x int
var x int
Correct.
Go
String z = 'output';
String z = "output";
Double quotes.
Java
if (val = 22) {}
if (val == 22) {}
Use ==.
Dart
const data = 79; data = 23;
let data = 79; data = 23;
Cannot reassign const.
JavaScript
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
let msg = String::from("test"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("test"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
// comment
/* comment */
Use /* */.
CSS
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
math.sqrt(78)
import math math.sqrt(78)
Import module first.
Python
if num = 54 then print('test') end
if num == 54 then print('test') end
Use ==.
Lua
list[86]
if list.indices.contains(86) {{ list[86] }}
Check index.
Swift
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
object Product {{ def main(args: Array[String]) = println("data") }}
object Product {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
<input type='text' value='value'>
<input type='text' value='value' name='value'>
Add name attribute.
HTML
String name = 'value';
String name = 'value';
Correct.
Dart
for i=1,87 do print(i) end
for i=1,87 do print(i) end
Correct.
Lua
fn process() -> i32 {{ 91 }}
fn process() -> i32 {{ 91 }}
Correct.
Rust
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
<person age=74>
<person age="74">
Quote attribute.
XML
let num: number | null = null; num.toFixed(12);
let num: number | null = null; if(num!==null) num.toFixed(12);
Null check.
TypeScript
<br></br>
<br>
Self-closing.
HTML
yield num
yield num
Correct yield.
Python
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
jwt.sign({{id:70}}, 'password');
jwt.sign({{id:70}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
assert item > 54
assert item > 54
Correct.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function foo(): void {{ return 12; }}
function foo(): number {{ return 12; }}
Return type mismatch.
TypeScript
if (b = 25)
if (b == 25)
Use ==.
R
[x*x for x in list if x > 73]
[x*x for x in list if x > 73]
Correct list comprehension.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
["hello", 90]
["hello", 90]
Correct.
JSON
num == '19'
num === 19
Use strict equality.
JavaScript
if ($bar = 23) {{}}
if ($bar -eq 23) {{}}
Use -eq.
PowerShell
if count = 14
if count == 14
Use ==.
MATLAB
let temp = 1; let temp = 92;
let temp = 1; temp = 92;
Duplicate declaration.
JavaScript
let c: i32 = "info";
let c: &str = "info";
Type mismatch.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
function render(count:string){{return count;}} render(61);
function render(count:string){{return count;}} render('message');
Pass correct type.
TypeScript