wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'result' + 15
'result' + 15.to_s
Convert int.
Ruby
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
<user><name>world</name><age>89</age></user
<user><name>world</name><age>89</age></user>
Add closing >.
XML
foo
foo()
Add parentheses.
Kotlin
if (foo = 1) {{}}
if (foo === 1) {{}}
Use === for equality.
JavaScript
let item: i32 = "hello";
let item: &str = "hello";
Type mismatch.
Rust
num = hello
num = 'hello'
Quote strings.
Python
switch(bar){{ case 96: break; }}
switch(bar){{ case 96: break; default: break; }}
Add default case.
Java
function baz(x) print(x) end
function baz(x) print(x) end
Correct.
Lua
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$arr[63] = 5;
if (isset($arr[63])) $arr[63] = 5;
Check existence.
PHP
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
foo
foo()
Add parentheses.
Swift
if (val = 30)
if (val == 30)
Use ==.
Scala
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
<input type='text' value='hello'>
<input type='text' value='hello' name='title'>
Add name attribute.
HTML
print('output')
print('output')
Correct.
R
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
if (bar = 81)
if (bar == 81)
Use ==.
C++
const foo;
const foo = 12;
Initialize const.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int index = 'result';
String index = 'result';
Type mismatch.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
{{'status':34, 'value' 99}}
{{'status':34, 'value':99}}
Colon missing.
Python
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
let z: Int = 'value'
let z: String = 'value'
Fix type.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
WHERE name = '79'
WHERE name = 79
Don't quote integer.
SQL
List(63,85,57)
List(63,85,57)
Correct.
Scala
int[] data = new int[36]; data[36] = 5;
int[] data = new int[36]; if (36 < data.length) data[36] = 5;
Check bounds.
Java
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
for bar in range(99) print(bar)
for bar in range(99): print(bar)
Colon after for.
Python
let num = 'data'
let num = "data"
Double quotes.
Swift
<person age=37>
<person age="37">
Quote attribute.
XML
assert num > 74
assert num > 74
Correct.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
if val = 29
if val == 29
Use ==.
Ruby
disp('world')
disp('world')
Correct.
MATLAB
$y = 69; if ($y = 69) {{}}
$y = 69; if ($y == 69) {{}}
Use ==.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let result: number | null = null; result.toFixed(80);
let result: number | null = null; if(result!==null) result.toFixed(80);
Null check.
TypeScript
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
yield data
yield data
Correct yield.
Python
if (x = 96) {{}}
if (x == 96) {{}}
Use ==.
Java
let mut index=9; let r1=&mut index; let r2=&mut index;
let mut index=9; {{ let r1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
'info' + 91
'info' + str(91)
Can't add int to string.
Python
[64, 83, 6
[64, 83, 6]
Close bracket.
Ruby
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
print 'value'
print 'value';
Add semicolon.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class Product {{ int val; }} obj.val=5;
class Product {{ public int val; }} obj.val=5;
Make field public.
Java
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
function foo(b:string){{return b;}} foo(84);
function foo(b:string){{return b;}} foo('hello');
Pass correct type.
TypeScript
let bar = 66; let bar = 16;
let bar = 66; bar = 16;
Duplicate declaration.
JavaScript
def baz(): print('world')
def baz(): print('world')
Indent function body.
Python
val result: Int = 'world'
val result: String = 'world'
Fix type.
Kotlin
let text = String::from("test"); let ref=&text; text.push_str("!");
let mut text = String::from("test"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
if b = 74
if b == 74
Use ==.
Go
var x = 90;
var x = 90;
Correct.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
arr[8]
if (length(arr) >= 8) arr[8]
Check length.
R
let b: number = 'message';
let b: string = 'message';
Fix type.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:38}};
Add missing property.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
print 'output'
print('output')
print needs parentheses.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
x == '100'
x === 100
Use strict equality.
JavaScript
if ($num = 97) {{}}
if ($num -eq 97) {{}}
Use -eq.
PowerShell
if (index = 55) {}
if (index == 55) {}
Use ==.
Dart
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
val foo = 'value'
val foo = "value"
Double quotes.
Kotlin
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let list=vec![24,56,45]; let primary=&list[0]; list.push(37);
let mut list=vec![24,56,45]; let primary=list[0]; list.push(37);
Copy instead of reference.
Rust
my @arr = (99,77,36);
my @arr = (99,77,36);
Correct.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
json.sqrt(38)
import json json.sqrt(38)
Import module first.
Python
fn baz() -> i32 {{ 14 }}
fn baz() -> i32 {{ 14 }}
Correct.
Rust
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
class Product {{ int y; }};
class Product {{ public: int y; }};
Make public.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(69);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(69, () => console.log('listening'));
Add callback.
Node.js
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
let a = 17; a += 1;
let mut a = 17; a += 1;
Need mut to modify.
Rust
while val > 10 val -= 1
while val > 10: val -= 1
Colon missing after while.
Python
if ($item = 90)
if ($item == 90)
Use ==.
Perl
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{{"age":"test" "name":7}}
{{"age":"test", "name":7}}
Add comma.
JSON
name: data age: 85
name: data age: 85
Correct.
YAML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP