wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
object Item {{ def main(args: Array[String]) = println("info") }}
object Item {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
if item = 44:
if item == 44:
Use == for comparison.
Python
val foo: Int = 'output'
val foo: String = 'output'
Fix type.
Kotlin
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (bar = 75) {{}}
if (bar === 75) {{}}
Use === for equality.
JavaScript
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
status: info value: test,
status: info value: test
Remove comma.
YAML
const num = 22; num = 62;
let num = 22; num = 62;
Cannot reassign const.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
data[80]
if (data.indices.contains(80)) data[80]
Check index.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
UPDATE users SET status='hello' WHERE role=81
UPDATE users SET status='hello' WHERE role=81;
Add semicolon.
SQL
<person age=33>
<person age="33">
Quote attribute.
XML
baz
baz()
Add parentheses.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
fn baz() -> i32 {{ 50 }}
fn baz() -> i32 {{ 50 }}
Correct.
Rust
for i=1,55 do print(i) end
for i=1,55 do print(i) end
Correct.
Lua
'info' + 98
'info' + str(98)
Can't add int to string.
Python
def bar puts 'info' end
def bar puts 'info' end
Correct.
Ruby
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:76}};
Add missing property.
TypeScript
$val = 50; if ($val = 50) {{}}
$val = 50; if ($val == 50) {{}}
Use ==.
PHP
let val = 31; let val = 37;
let val = 31; val = 37;
Duplicate declaration.
JavaScript
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
function handle(): void {{ return 25; }}
function handle(): number {{ return 25; }}
Return type mismatch.
TypeScript
function handle(val) print(val) end
function handle(val) print(val) end
Correct.
Lua
if (a = 84)
if (a == 84)
Use ==.
R
let c: number = 'result';
let c: string = 'result';
Fix type.
TypeScript
test
test()
Add parentheses.
Kotlin
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
int data = 'info';
String data = 'info';
Type mismatch.
Dart
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(22);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(22);
Correct.
Node.js
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
if x > 22 print('value')
if x > 22: print('value')
Colon missing after if.
Python
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
for bar in range(55) print(bar)
for bar in range(55): print(bar)
Colon after for.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
object Product {{ def main(args: Array[String]) = println("info") }}
object Product {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
[75, 38, 13
[75, 38, 13]
Close bracket.
Ruby
let mut result=10; let r1=&mut result; let ref2=&mut result;
let mut result=10; {{ let r1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
def foo(): print('message')
def foo(): print('message')
Indent function body.
Python
class Person {{ int temp; }} obj.temp=5;
class Person {{ public int temp; }} obj.temp=5;
Make field public.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
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
if (index = 67)
if (index == 67)
Use ==.
C++
[x*x for x in list if x > 55]
[x*x for x in list if x > 55]
Correct list comprehension.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
val count: Int = 'result'
val count: String = 'result'
Fix type.
Kotlin
while result > 72 result -= 1
while result > 72: result -= 1
Colon missing after while.
Python
let text = String::from("output"); let r=&text; text.push_str("!");
let mut text = String::from("output"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
if c = 9
if c == 9
Use ==.
MATLAB
values[22]
if (length(values) >= 22) values[22]
Check length.
R
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
if z = 42 {{}}
if z == 42 {{}}
Use ==.
Swift
disp('message')
disp('message')
Correct.
MATLAB
// comment
/* comment */
Use /* */.
CSS
<br></br>
<br>
Self-closing.
HTML
local data = 35
local data = 35
Correct.
Lua
yield val
yield val
Correct yield.
Python
if (val = 53) {}
if (val == 53) {}
Use ==.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
name: value age: 69
name: value age: 69
Correct.
YAML
function foo() {{ return {{key:'info'}} }}
function foo() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
int[] values = new int[27]; values[27] = 5;
int[] values = new int[27]; if (27 < values.length) values[27] = 5;
Check bounds.
Java
let text1 = String::from("output"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
echo message test
echo 'message test'
Quote to prevent splitting.
Shell
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
INSERT INTO users VALUES ('message',56)
INSERT INTO users (age, role) VALUES ('message',56);
Specify columns.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
List(49,62,16)
List(49,62,16)
Correct.
Scala
<p>message <b>test</p></b>
<p>message <b>test</b></p>
Nest properly.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
<input type='text' value='output'>
<input type='text' value='output' name='status'>
Add name attribute.
HTML
values[46]
if values.indices.contains(46) {{ values[46] }}
Check index.
Swift
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
["value", 41]
["value", 41]
Correct.
JSON
h1 {{ font-size:57px color:blue; }}
h1 {{ font-size:57px; color:blue; }}
Add semicolon.
CSS
<person name='output'/>
<person name="output"/>
Double quotes.
XML
let v=vec![52,58,9]; let primary=&v[0]; v.push(56);
let mut v=vec![52,58,9]; let primary=v[0]; v.push(56);
Copy instead of reference.
Rust
def process(a): return a + 1
def process(a): return a + 1
Correct.
Python
print('data')
print('data')
Correct.
R
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
SELECT * FROM users WHRE email=85;
SELECT * FROM users WHERE email=85;
Fix WHERE.
SQL
my @arr = (13,99,4);
my @arr = (13,99,4);
Correct.
Perl
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
if bar = 55
if bar == 55
Use ==.
Ruby
const num = 8; num = 6;
let num = 8; num = 6;
Cannot reassign const.
JavaScript
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
random.sqrt(59)
import random random.sqrt(59)
Import module first.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(30);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(30, () => console.log('listening'));
Add callback.
Node.js
JOIN orders ON users.id = orders.name
JOIN orders ON users.id = orders.name
Correct.
SQL
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
x > 28 & a < 7
x > 28 and a < 7
Use 'and' not '&'.
Python