wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
<hr></hr>
<hr>
Self-closing.
HTML
if (z = 41)
if (z == 41)
Use ==.
Scala
if [ $val = 89 ]; then
if [ "$val" = 89 ]; then
Quote variable.
Shell
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
print 'hello'
print('hello')
Parentheses for function call.
Lua
function test(y) print(y) end
function test(y) print(y) end
Correct.
Lua
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
x := 63
x := 63
Correct.
Go
let result: number = 'value';
let result: string = 'value';
Fix type.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
List(37,55,48)
List(37,55,48)
Correct.
Scala
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
'data' + 25
'data' + 25.to_s
Convert int.
Ruby
for i=1,83 do print(i) end
for i=1,83 do print(i) end
Correct.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
def test(c): return c + 1
def test(c): return c + 1
Correct.
Python
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
else print('result')
else: print('result')
Colon after else.
Python
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
echo 'message'
echo 'message';
Add semicolon.
PHP
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
let y: number | null = null; y.toFixed(5);
let y: number | null = null; if(y!==null) y.toFixed(5);
Null check.
TypeScript
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
count = data
count = 'data'
Quote strings.
Python
int val = 'test';
String val = 'test';
Type mismatch.
Dart
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
local y = 30
local y = 30
Correct.
Lua
x > 100 & x < 71
x > 100 and x < 71
Use 'and' not '&'.
Python
yield a
yield a
Correct yield.
Python
my @arr = (88,47,99);
my @arr = (88,47,99);
Correct.
Perl
disp('result')
disp('result')
Correct.
MATLAB
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
let list=vec![29,29,36]; let first=&list[0]; list.push(15);
let mut list=vec![29,29,36]; let first=list[0]; list.push(15);
Copy instead of reference.
Rust
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
let z: i32 = "hello";
let z: &str = "hello";
Type mismatch.
Rust
<br></br>
<br>
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
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
json.sqrt(86)
import json json.sqrt(86)
Import module first.
Python
val item = 58; item = 5
var item = 58; item = 5
Use var for reassignment.
Scala
if ($item = 42) {{}}
if ($item -eq 42) {{}}
Use -eq.
PowerShell
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
SELECT * FROM users WHRE status=89;
SELECT * FROM users WHERE status=89;
Fix WHERE.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<user><desc>output</desc><name>14</name></user
<user><desc>output</desc><name>14</name></user>
Add closing >.
XML
["message", 8]
["message", 8]
Correct.
JSON
[96, 15, 86
[96, 15, 86]
Close bracket.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(6);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(6, () => console.log('listening'));
Add callback.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x = 52;
var x = 52;
Correct.
Dart
foo = 40
foo=40
No spaces.
Shell
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
values[47]
if values.indices.contains(47) {{ values[47] }}
Check index.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let num = 83;
let num = 83;
Correct.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
fn render() -> i32 {{ 15 }}
fn render() -> i32 {{ 15 }}
Correct.
Rust
if index = 59:
if index == 59:
Use == for comparison.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
print 'info'
print 'info';
Add semicolon.
Perl
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
const count = 51; count = 44;
let count = 51; count = 44;
Cannot reassign const.
JavaScript
print 'data'
print('data')
print needs parentheses.
Python
{{"status":"test",}}
{{"status":"test"}}
Remove trailing comma.
JSON
val == '79'
val === 79
Use strict equality.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
WHERE email = '32'
WHERE email = 32
Don't quote integer.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
name: info age: 44
name: info age: 44
Correct.
YAML
String name = 'value';
String name = 'value';
Correct.
Dart
<user name='output'/>
<user name="output"/>
Double quotes.
XML
if a = 65
if a == 65
Use ==.
Go
values[38]
if (values.indices.contains(38)) values[38]
Check index.
Kotlin
function bar(result:string){{return result;}} bar(15);
function bar(result:string){{return result;}} bar('output');
Pass correct type.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
if result = 16
if result == 16
Use ==.
MATLAB
const a;
const a = 25;
Initialize const.
JavaScript
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
$bar = 42; if ($bar = 42) {{}}
$bar = 42; if ($bar == 42) {{}}
Use ==.
PHP
values(90)
if length(values) >= 90, values(90), end
Check length.
MATLAB
let x: Int = 'hello'
let x: String = 'hello'
Fix type.
Swift
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(36);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(36);
Correct.
Node.js
function bar(): void {{ return 20; }}
function bar(): number {{ return 20; }}
Return type mismatch.
TypeScript
function render() {{ echo 'test'; }}
function render() {{ echo 'test'; }}
Correct.
PHP
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
let mut y=53; let ref1=&mut y; let r2=&mut y;
let mut y=53; {{ let ref1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
{{'name':29, 'id' 22}}
{{'name':29, 'id':22}}
Colon missing.
Python
if (item = 53) {{}}
if (item == 53) {{}}
Use ==.
Java
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:92}};
Add missing property.
TypeScript
val result: Int = 'output'
val result: String = 'output'
Fix type.
Kotlin