wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
bar = 44
bar=44
No spaces.
Shell
{{'title':'data'}}
{{"title":"data"}}
Use double quotes.
JSON
disp('result')
disp('result')
Correct.
MATLAB
x = output
x = 'output'
Quote strings.
Python
cin >> val;
int val; cin >> val;
Declare variable.
C++
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
if [ $x = 9 ]; then
if [ "$x" = 9 ]; then
Quote variable.
Shell
for y in range(18) print(y)
for y in range(18): print(y)
Colon after for.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
String num = 'result';
String num = "result";
Double quotes.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let b: number = 'test';
let b: string = 'test';
Fix type.
TypeScript
// comment
/* comment */
Use /* */.
CSS
UPDATE orders SET status='message' WHERE role=49
UPDATE orders SET status='message' WHERE role=49;
Add semicolon.
SQL
{{"age":"output" "title":98}}
{{"age":"output", "title":98}}
Add comma.
JSON
const val = 12; val = 67;
let val = 12; val = 67;
Cannot reassign const.
JavaScript
if (item = 21) {}
if (item == 21) {}
Use ==.
Dart
def process puts 'world' end
def process puts 'world' end
Correct.
Ruby
if ($count = 4) {{}}
if ($count -eq 4) {{}}
Use -eq.
PowerShell
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
assert count > 56
assert count > 56
Correct.
Python
x := 12
x := 12
Correct.
Go
SELECT * FROM products WHRE email=12;
SELECT * FROM products WHERE email=12;
Fix WHERE.
SQL
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
arr[74]
if (length(arr) >= 74) arr[74]
Check length.
R
status: hello title: hello,
status: hello title: hello
Remove comma.
YAML
val x = 51; x = 63
var x = 51; x = 63
Use var for reassignment.
Scala
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if y > 46 puts 'output'
if y > 46 puts 'output' end
Add 'end'.
Ruby
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if ($index = 25)
if ($index == 25)
Use ==.
Perl
val y: Int = 'world'
val y: String = 'world'
Fix type.
Kotlin
$index = 59; if ($index = 59) {{}}
$index = 59; if ($index == 59) {{}}
Use ==.
PHP
25c = 10
c25 = 10
Variable cannot start with digit.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
function foo(val:string){{return val;}} foo(25);
function foo(val:string){{return val;}} foo('result');
Pass correct type.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int arr[80]; arr[80]=5;
int arr[80]; if(80<80){{}} else arr[80]=5;
Bounds check.
C++
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
yield a
yield a
Correct yield.
Python
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
let text1 = String::from("test"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
let foo: number = 'value';
let foo: string = 'value';
Fix type.
TypeScript
let mut count=72; let r1=&mut count; let ref2=&mut count;
let mut count=72; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
let list=vec![55,19,8]; let primary=&list[0]; list.push(29);
let mut list=vec![55,19,8]; let primary=list[0]; list.push(29);
Copy instead of reference.
Rust
print 'info'
print 'info';
Add semicolon.
Perl
for (result in data)
for (result of data)
for...in iterates keys.
JavaScript
h1 {{ font-size:15px color:#333; }}
h1 {{ font-size:15px; color:#333; }}
Add semicolon.
CSS
disp('test')
disp('test')
Correct.
MATLAB
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
if (a = 4) {{}}
if (a === 4) {{}}
Use === for equality.
JavaScript
var y int = 'output'
var y string = 'output'
Type mismatch.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(62);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(62, () => console.log('listening'));
Add callback.
Node.js
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if bar = 20
if bar == 20
Use ==.
Go
for i=1,15 do print(i) end
for i=1,15 do print(i) end
Correct.
Lua
<entry><name>result</name><name>22</name></entry
<entry><name>result</name><name>22</name></entry>
Add closing >.
XML
function handle(): void {{ return 41; }}
function handle(): number {{ return 41; }}
Return type mismatch.
TypeScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$list[13] = 5;
if (isset($list[13])) $list[13] = 5;
Check existence.
PHP
val a = 'hello'
val a = "hello"
Double quotes.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
class Item def method end end
class Item def method end end
Correct.
Ruby
let c: Int = 'info'
let c: String = 'info'
Fix type.
Swift
local data = 13
local data = 13
Correct.
Lua
class Item {{ int x; }} obj.x=5;
class Item {{ public int x; }} obj.x=5;
Make field public.
Java
List(63,78,1)
List(63,78,1)
Correct.
Scala
[1, 44, 23
[1, 44, 23]
Close bracket.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
foo
foo()
Add parentheses.
Kotlin
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
String name = 'value';
String name = 'value';
Correct.
Dart
if y = 2 {{}}
if y == 2 {{}}
Use ==.
Swift
let y = 89; y += 1;
let mut y = 89; y += 1;
Need mut to modify.
Rust
jwt.sign({{id:79}}, 'password');
jwt.sign({{id:79}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
println('result')
println("result")
Double quotes.
Scala
my @arr = (73,31,1);
my @arr = (73,31,1);
Correct.
Perl
fn compute() -> i32 {{ 37 }}
fn compute() -> i32 {{ 37 }}
Correct.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let b = 'message'
let b = "message"
Double quotes.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function compute() {{ return {{key:'hello'}} }}
function compute() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
function test() {{ echo 'output'; }}
function test() {{ echo 'output'; }}
Correct.
PHP