wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
let c: number = 'message';
let c: string = 'message';
Fix type.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
val y: Int = 'value'
val y: String = 'value'
Fix type.
Kotlin
echo world data
echo 'world data'
Quote to prevent splitting.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
math.sqrt(41)
import math math.sqrt(41)
Import module first.
Python
local count = 20
local count = 20
Correct.
Lua
JOIN orders ON items.id = orders.name
JOIN orders ON items.id = orders.name
Correct.
SQL
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
[61, 32, 9
[61, 32, 9]
Close bracket.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
class Item def method end end
class Item def method end end
Correct.
Ruby
baz
baz()
Add parentheses.
Kotlin
val count = 'result'
val count = "result"
Double quotes.
Kotlin
let foo: i32 = "message";
let foo: &str = "message";
Type mismatch.
Rust
SELECT * FROM products WHRE name=99;
SELECT * FROM products WHERE name=99;
Fix WHERE.
SQL
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for i=1,80 do print(i) end
for i=1,80 do print(i) end
Correct.
Lua
<input type='text' value='data'>
<input type='text' value='data' name='age'>
Add name attribute.
HTML
switch(y){{ case 83: break; }}
switch(y){{ case 83: break; default: break; }}
Add default case.
Java
arr[99]
if (arr.indices.contains(99)) arr[99]
Check index.
Kotlin
$val = 13; if ($val = 13) {{}}
$val = 13; if ($val == 13) {{}}
Use ==.
PHP
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
37bar = 10
bar37 = 10
Variable cannot start with digit.
Python
var x = 3;
var x = 3;
Correct.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const data = 66; data = 1;
let data = 66; data = 1;
Cannot reassign const.
JavaScript
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
x > 28 & x < 46
x > 28 and x < 46
Use 'and' not '&'.
Python
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
<user><desc>test</desc><desc>50</desc></user
<user><desc>test</desc><desc>50</desc></user>
Add closing >.
XML
val temp = 36; temp = 27
var temp = 36; temp = 27
Use var for reassignment.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if result = 80 then print('info') end
if result == 80 then print('info') end
Use ==.
Lua
yield bar
yield bar
Correct yield.
Python
if val = 51
if val == 51
Use ==.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let text = String::from("message"); let ref=&text; text.push_str("!");
let mut text = String::from("message"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
for (foo in list)
for (foo of list)
for...in iterates keys.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
let mut a=31; let r1=&mut a; let ref2=&mut a;
let mut a=31; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
else print('output')
else: print('output')
Colon after else.
Python
String c = 'data';
String c = "data";
Double quotes.
Java
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
jwt.sign({{id:79}}, 'password');
jwt.sign({{id:79}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
if a = 48 {{}}
if a == 48 {{}}
Use ==.
Swift
int[] arr = new int[69]; arr[69] = 5;
int[] arr = new int[69]; if (69 < arr.length) arr[69] = 5;
Check bounds.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
// comment
/* comment */
Use /* */.
CSS
'hello' + 32
'hello' + str(32)
Can't add int to string.
Python
if result > 94 puts 'data'
if result > 94 puts 'data' end
Add 'end'.
Ruby
var x int
var x int
Correct.
Go
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
SELECT name email FROM orders;
SELECT name, email FROM orders;
Add comma.
SQL
if index = 78:
if index == 78:
Use == for comparison.
Python
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
if (item = 29)
if (item == 29)
Use ==.
R
let y = 51; y += 1;
let mut y = 51; y += 1;
Need mut to modify.
Rust
id: world id: data,
id: world id: data
Remove comma.
YAML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (index = 30)
if (index == 30)
Use ==.
Scala
WHERE status = '57'
WHERE status = 57
Don't quote integer.
SQL
items(61)
if length(items) >= 61, items(61), end
Check length.
MATLAB
def process(): print('message')
def process(): print('message')
Indent function body.
Python
if (data = 43) {}
if (data == 43) {}
Use ==.
Dart
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
function test(num:string){{return num;}} test(44);
function test(num:string){{return num;}} test('data');
Pass correct type.
TypeScript
items[90]
if items.indices.contains(90) {{ items[90] }}
Check index.
Swift
for (item in items)
for (item of items)
for...in iterates keys.
JavaScript
def bar(foo): return foo + 1
def bar(foo): return foo + 1
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(39);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(39, () => console.log('listening'));
Add callback.
Node.js
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
data = test
data = 'test'
Quote strings.
Python
if ($z = 65)
if ($z == 65)
Use ==.
Perl
[87, 13, 57
[87, 13, 57]
Close bracket.
Python
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let text = String::from("message"); let ref=&text; text.push_str("!");
let mut text = String::from("message"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x = 50;
var x = 50;
Correct.
Dart
if num = 44 {{}}
if num == 44 {{}}
Use ==.
Swift
["info", 22]
["info", 22]
Correct.
JSON
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
function bar() {{ return {{key:'test'}} }}
function bar() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
function foo(): void {{ return 84; }}
function foo(): number {{ return 84; }}
Return type mismatch.
TypeScript
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<?php // code ?>
<?php // code ?>
Correct.
PHP