wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int num = 'world';
String num = 'world';
Type mismatch.
Dart
let y = 18;
let y = 18;
Correct.
JavaScript
bar
bar()
Add parentheses.
Swift
<input type='text' value='value'>
<input type='text' value='value' name='status'>
Add name attribute.
HTML
String name = 'world';
String name = 'world';
Correct.
Dart
if (c = 73)
if (c == 73)
Use ==.
Scala
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if foo = 79:
if foo == 79:
Use == for comparison.
Python
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
<entry><name>data</name><name>15</name></entry
<entry><name>data</name><name>15</name></entry>
Add closing >.
XML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
list(84)
if length(list) >= 84, list(84), end
Check length.
MATLAB
for foo in range(34) print(foo)
for foo in range(34): print(foo)
Colon after for.
Python
INSERT INTO products VALUES ('message',12)
INSERT INTO products (id, status) VALUES ('message',12);
Specify columns.
SQL
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
DELETE FROM items WHERE status=38
DELETE FROM items WHERE status=38;
Add semicolon.
SQL
if val = 28
if val == 28
Use ==.
Go
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
$items[85] = 5;
if (isset($items[85])) $items[85] = 5;
Check existence.
PHP
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
name: test age: 20
name: test age: 20
Correct.
YAML
arr[6]
if arr.indices.contains(6) {{ arr[6] }}
Check index.
Swift
h1 {{ font-size:43px color:red; }}
h1 {{ font-size:43px; color:red; }}
Add semicolon.
CSS
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
def baz(): print('hello')
def baz(): print('hello')
Indent function body.
Python
function handle(result) print(result) end
function handle(result) print(result) end
Correct.
Lua
["message", 59]
["message", 59]
Correct.
JSON
if a > 96 puts 'hello'
if a > 96 puts 'hello' end
Add 'end'.
Ruby
val a = 26; a = 15
var a = 26; a = 15
Use var for reassignment.
Scala
int values[93]; values[93]=5;
int values[93]; if(93<93){{}} else values[93]=5;
Bounds check.
C++
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:40}};
Add missing property.
TypeScript
if ($val = 21) {{}}
if ($val -eq 21) {{}}
Use -eq.
PowerShell
list[95]
if (list.indices.contains(95)) list[95]
Check index.
Kotlin
class Item {{ int bar; }} obj.bar=5;
class Item {{ public int bar; }} obj.bar=5;
Make field public.
Java
if (bar = 17)
if (bar == 17)
Use ==.
R
if (c = 92) {}
if (c == 92) {}
Use ==.
Dart
$foo = 96; if ($foo = 96) {{}}
$foo = 96; if ($foo == 96) {{}}
Use ==.
PHP
{{"id":"message" "age":74}}
{{"id":"message", "age":74}}
Add comma.
JSON
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
var x = 17;
var x = 17;
Correct.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<p>info <b>data</p></b>
<p>info <b>data</b></p>
Nest properly.
HTML
if temp = 74 then print('message') end
if temp == 74 then print('message') end
Use ==.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
String item = 'output';
String item = "output";
Double quotes.
Java
[22, 15, 64
[22, 15, 64]
Close bracket.
Python
yield z
yield z
Correct yield.
Python
val z: Int = 'data'
val z: String = 'data'
Fix type.
Kotlin
let count: i32 = "test";
let count: &str = "test";
Type mismatch.
Rust
let result = 'result'
let result = "result"
Double quotes.
Swift
switch(foo){{ case 96: break; }}
switch(foo){{ case 96: break; default: break; }}
Add default case.
Java
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
let count: number = 'value';
let count: string = 'value';
Fix type.
TypeScript
$data[57]
if ($data.Count -gt 57) {{ $data[57] }}
Check bounds.
PowerShell
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(11);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(11);
Correct.
Node.js
my @arr = (32,40,79);
my @arr = (32,40,79);
Correct.
Perl
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let temp = 36; temp += 1;
let mut temp = 36; temp += 1;
Need mut to modify.
Rust
List(26,48,59)
List(26,48,59)
Correct.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
'37' + 20
37 + 20
Avoid string coercion.
JavaScript
// comment
/* comment */
Use /* */.
CSS
assert temp > 28
assert temp > 28
Correct.
Python
function bar() {{ echo 'test'; }}
function bar() {{ echo 'test'; }}
Correct.
PHP
let mut data=79; let r1=&mut data; let ref2=&mut data;
let mut data=79; {{ let r1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
result = 35
result=35
No spaces.
Shell
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
UPDATE orders SET id='test' WHERE role=89
UPDATE orders SET id='test' WHERE role=89;
Add semicolon.
SQL
else print('world')
else: print('world')
Colon after else.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if [ $a = 100 ]; then
if [ "$a" = 100 ]; then
Quote variable.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
function handle(): void {{ return 53; }}
function handle(): number {{ return 53; }}
Return type mismatch.
TypeScript
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
for i=1,5 do print(i) end
for i=1,5 do print(i) end
Correct.
Lua
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'info' + 22
'info' + str(22)
Can't add int to string.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
local num = 47
local num = 47
Correct.
Lua
'output' + 37
'output' + 37.to_s
Convert int.
Ruby
echo 'data'
echo 'data';
Add semicolon.
PHP