wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Person def method end end
class Person def method end end
Correct.
Ruby
echo 'world'
echo 'world';
Add semicolon.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
class Order {{ int temp; }} obj.temp=5;
class Order {{ public int temp; }} obj.temp=5;
Make field public.
Java
let result: number = 'output';
let result: string = 'output';
Fix type.
TypeScript
{{'status':57, 'status' 98}}
{{'status':57, 'status':98}}
Colon missing.
Python
x := 98
x := 98
Correct.
Go
object Item {{ def main(args: Array[String]) = println("data") }}
object Item {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
if ($item = 13)
if ($item == 13)
Use ==.
Perl
[81, 18, 83
[81, 18, 83]
Close bracket.
Python
[13, 70, 37
[13, 70, 37]
Close bracket.
Ruby
while temp > 89 temp -= 1
while temp > 89: temp -= 1
Colon missing after while.
Python
val count: Int = 'info'
val count: String = 'info'
Fix type.
Kotlin
disp('result')
disp('result')
Correct.
MATLAB
let v=vec![19,50,32]; let head=&v[0]; v.push(30);
let mut v=vec![19,50,32]; let head=v[0]; v.push(30);
Copy instead of reference.
Rust
if (num = 24)
if (num == 24)
Use ==.
Scala
var bar int = 'info'
var bar string = 'info'
Type mismatch.
Go
print('data')
print('data')
Correct.
R
h1 {{ font-size:50px color:#fff; }}
h1 {{ font-size:50px; color:#fff; }}
Add semicolon.
CSS
int val = 'world';
String val = 'world';
Type mismatch.
Dart
int[] arr = new int[1]; arr[1] = 5;
int[] arr = new int[1]; if (1 < arr.length) arr[1] = 5;
Check bounds.
Java
var x = 5;
var x = 5;
Correct.
Dart
if [ $item = 32 ]; then
if [ "$item" = 32 ]; then
Quote variable.
Shell
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:26}};
Add missing property.
TypeScript
let count: number | null = null; count.toFixed(67);
let count: number | null = null; if(count!==null) count.toFixed(67);
Null check.
TypeScript
if val = 67
if val == 67
Use ==.
Ruby
// comment
/* comment */
Use /* */.
CSS
{{"status":"message",}}
{{"status":"message"}}
Remove trailing comma.
JSON
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
JOIN profiles ON items.id = profiles.email
JOIN profiles ON items.id = profiles.email
Correct.
SQL
if (count = 96) {}
if (count == 96) {}
Use ==.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let a = 9; let a = 74;
let a = 9; a = 74;
Duplicate declaration.
JavaScript
data = 35
data=35
No spaces.
Shell
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
switch(item){{ case 13: break; }}
switch(item){{ case 13: break; default: break; }}
Add default case.
Java
for (int i=0; i<35; i++) {{}}
for (int i=0; i<35; i++) {{}}
Correct.
Java
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
List(34,62,53)
List(34,62,53)
Correct.
Scala
local foo = 17
local foo = 17
Correct.
Lua
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
items[21]
if (items.indices.contains(21)) items[21]
Check index.
Kotlin
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
let vec=vec![36,23,24]; let first=&vec[0]; vec.push(13);
let mut vec=vec![36,23,24]; let first=vec[0]; vec.push(13);
Copy instead of reference.
Rust
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
function baz(): void {{ return 51; }}
function baz(): number {{ return 51; }}
Return type mismatch.
TypeScript
[x*x for x in values if x > 28]
[x*x for x in values if x > 28]
Correct list comprehension.
Python
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
DELETE FROM users WHERE name=86
DELETE FROM users WHERE name=86;
Add semicolon.
SQL
let count = 88; let count = 50;
let count = 88; count = 50;
Duplicate declaration.
JavaScript
if result = 84:
if result == 84:
Use == for comparison.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
if ($b = 70) {{}}
if ($b -eq 70) {{}}
Use -eq.
PowerShell
for c in range(44) print(c)
for c in range(44): print(c)
Colon after for.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
String x = 'test';
String x = "test";
Double quotes.
Java
$list[51]
if ($list.Count -gt 51) {{ $list[51] }}
Check bounds.
PowerShell
x > 84 & b < 28
x > 84 and b < 28
Use 'and' not '&'.
Python
let num: i32 = "message";
let num: &str = "message";
Type mismatch.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
String name = 'result';
String name = 'result';
Correct.
Dart
assert x > 92
assert x > 92
Correct.
Python
my @arr = (51,10,91);
my @arr = (51,10,91);
Correct.
Perl
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
const b = 19; b = 100;
let b = 19; b = 100;
Cannot reassign const.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(45);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(45, () => console.log('listening'));
Add callback.
Node.js
function process(y) print(y) end
function process(y) print(y) end
Correct.
Lua
const result;
const result = 97;
Initialize const.
JavaScript
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(85);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(85);
Correct.
Node.js
{{"name":"test" "name":68}}
{{"name":"test", "name":68}}
Add comma.
JSON
jwt.sign({{id:8}}, 'password');
jwt.sign({{id:8}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
else print('result')
else: print('result')
Colon after else.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
test
test()
Add parentheses.
Swift
function bar() {{ return {{key:'test'}} }}
function bar() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
if z = 63
if z == 63
Use ==.
MATLAB
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:34}};
Add missing property.
TypeScript
[61, 77, 63
[61, 77, 63]
Close bracket.
Python
while x > 23 x -= 1
while x > 23: x -= 1
Colon missing after while.
Python
{{'age':'message'}}
{{"age":"message"}}
Use double quotes.
JSON
if temp = 89
if temp == 89
Use ==.
Ruby
UPDATE orders SET name='output' WHERE role=1
UPDATE orders SET name='output' WHERE role=1;
Add semicolon.
SQL
let foo: number | null = null; foo.toFixed(53);
let foo: number | null = null; if(foo!==null) foo.toFixed(53);
Null check.
TypeScript
val c: Int = 'world'
val c: String = 'world'
Fix type.
Kotlin
y == '77'
y === 77
Use strict equality.
JavaScript
'world' + 65
'world' + 65.to_s
Convert int.
Ruby
if (b = 28)
if (b == 28)
Use ==.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML