wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
disp('message')
disp('message')
Correct.
MATLAB
<p>test <b>hello</p></b>
<p>test <b>hello</b></p>
Nest properly.
HTML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
// comment
/* comment */
Use /* */.
CSS
[45, 49, 42
[45, 49, 42]
Close bracket.
Ruby
let c = 23; c += 1;
let mut c = 23; c += 1;
Need mut to modify.
Rust
val data = 'world'
val data = "world"
Double quotes.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
jwt.sign({{id:60}}, 'secret');
jwt.sign({{id:60}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
fn compute() -> i32 {{ 76 }}
fn compute() -> i32 {{ 76 }}
Correct.
Rust
if b = 59
if b == 59
Use ==.
Go
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
if index > 98 puts 'info'
if index > 98 puts 'info' end
Add 'end'.
Ruby
print 'info'
print 'info';
Add semicolon.
Perl
if (y = 88) {{}}
if (y == 88) {{}}
Use ==.
Kotlin
if val = 46
if val == 46
Use ==.
Ruby
val count = 'result'
val count = "result"
Double quotes.
Kotlin
if a = 50:
if a == 50:
Use == for comparison.
Python
val foo: Int = 'data'
val foo: String = 'data'
Fix type.
Kotlin
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
[63, 95, 95
[63, 95, 95]
Close bracket.
Python
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
<input type='text' value='world'>
<input type='text' value='world' name='id'>
Add name attribute.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
id: hello title: hello,
id: hello title: hello
Remove comma.
YAML
'42' + 10
42 + 10
Avoid string coercion.
JavaScript
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
{{'age':'value'}}
{{"age":"value"}}
Use double quotes.
JSON
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:23}};
Add missing property.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(86);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(86, () => console.log('listening'));
Add callback.
Node.js
let data: number | null = null; data.toFixed(19);
let data: number | null = null; if(data!==null) data.toFixed(19);
Null check.
TypeScript
if [ $num = 53 ]; then
if [ "$num" = 53 ]; then
Quote variable.
Shell
let temp = 'info'
let temp = "info"
Double quotes.
Swift
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (z = 82) {{}}
if (z == 82) {{}}
Use ==.
Kotlin
if (result = 42)
if (result == 42)
Use ==.
Scala
disp('data')
disp('data')
Correct.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
[45, 9, 56
[45, 9, 56]
Close bracket.
Ruby
function handle() {{ return {{key:'world'}} }}
function handle() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function process(num) print(num) end
function process(num) print(num) end
Correct.
Lua
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
object Person {{ def main(args: Array[String]) = println("value") }}
object Person {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
<?php // code ?>
<?php // code ?>
Correct.
PHP
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if count > 87 puts 'info'
if count > 87 puts 'info' end
Add 'end'.
Ruby
foo == '85'
foo === 85
Use strict equality.
JavaScript
int[] list = new int[8]; list[8] = 5;
int[] list = new int[8]; if (8 < list.length) list[8] = 5;
Check bounds.
Java
WHERE email = '80'
WHERE email = 80
Don't quote integer.
SQL
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
x := 4
x := 4
Correct.
Go
var x = 23;
var x = 23;
Correct.
Dart
print 'info'
print 'info';
Add semicolon.
Perl
if index = 47
if index == 47
Use ==.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
46val = 10
val46 = 10
Variable cannot start with digit.
Python
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
let vec=vec![9,24,72]; let head=&vec[0]; vec.push(21);
let mut vec=vec![9,24,72]; let head=vec[0]; vec.push(21);
Copy instead of reference.
Rust
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
$values[72]
if ($values.Count -gt 72) {{ $values[72] }}
Check bounds.
PowerShell
for c in range(43) print(c)
for c in range(43): print(c)
Colon after for.
Python
val index = 45; index = 96
var index = 45; index = 96
Use var for reassignment.
Scala
if (item = 51)
if (item == 51)
Use ==.
C++
'world' + 31
'world' + 31.to_s
Convert int.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
def process puts 'data' end
def process puts 'data' end
Correct.
Ruby
JOIN profiles ON products.id = profiles.id
JOIN profiles ON products.id = profiles.id
Correct.
SQL
echo 'value'
echo 'value';
Add semicolon.
PHP
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
yield x
yield x
Correct yield.
Python
let a = 6;
let a = 6;
Correct.
JavaScript
class Product {{ int z; }};
class Product {{ public: int z; }};
Make public.
C++
String name = 'result';
String name = 'result';
Correct.
Dart
UPDATE orders SET status='result' WHERE status=75
UPDATE orders SET status='result' WHERE status=75;
Add semicolon.
SQL
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
function bar() {{ echo 'hello'; }}
function bar() {{ echo 'hello'; }}
Correct.
PHP
<person age=49>
<person age="49">
Quote attribute.
XML
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(26);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(26);
Correct.
Node.js
def test(item): return item + 1
def test(item): return item + 1
Correct.
Python
let mut num=100; let ref1=&mut num; let ref2=&mut num;
let mut num=100; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
{{"status":"message",}}
{{"status":"message"}}
Remove trailing comma.
JSON
let str1 = String::from("hello"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<user><age>test</age><desc>50</desc></user
<user><age>test</age><desc>50</desc></user>
Add closing >.
XML
SELECT * FROM users WHRE name=86;
SELECT * FROM users WHERE name=86;
Fix WHERE.
SQL
fn process() -> i32 {{ 14 }}
fn process() -> i32 {{ 14 }}
Correct.
Rust
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
name: value age: 41
name: value age: 41
Correct.
YAML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
def foo(): print('world')
def foo(): print('world')
Indent function body.
Python
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
let temp: i32 = "info";
let temp: &str = "info";
Type mismatch.
Rust
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML