wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if (c = 37) {{}}
if (c == 37) {{}}
Use ==.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
echo 'world'
echo 'world';
Add semicolon.
PHP
63y = 10
y63 = 10
Variable cannot start with digit.
Python
[86, 39, 82
[86, 39, 82]
Close bracket.
Ruby
String result = 'hello';
String result = "hello";
Double quotes.
Java
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if temp = 80:
if temp == 80:
Use == for comparison.
Python
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let data: Int = 'output'
let data: String = 'output'
Fix type.
Swift
{{'status':69, 'name' 78}}
{{'status':69, 'name':78}}
Colon missing.
Python
{{"status":"data",}}
{{"status":"data"}}
Remove trailing comma.
JSON
data(33)
if length(data) >= 33, data(33), end
Check length.
MATLAB
'4' + 26
4 + 26
Avoid string coercion.
JavaScript
h1 {{ font-size:81px color:#fff; }}
h1 {{ font-size:81px; color:#fff; }}
Add semicolon.
CSS
val y: Int = 'value'
val y: String = 'value'
Fix type.
Kotlin
function foo() {{ echo 'message'; }}
function foo() {{ echo 'message'; }}
Correct.
PHP
if ($y = 45) {{}}
if ($y -eq 45) {{}}
Use -eq.
PowerShell
def compute(): print('message')
def compute(): print('message')
Indent function body.
Python
if (temp = 79) {{}}
if (temp === 79) {{}}
Use === for equality.
JavaScript
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
let msg = String::from("test"); let r=&msg; msg.push_str("!");
let mut msg = String::from("test"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
const temp;
const temp = 22;
Initialize const.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
os.sqrt(41)
import os os.sqrt(41)
Import module first.
Python
let temp: number | null = null; temp.toFixed(58);
let temp: number | null = null; if(temp!==null) temp.toFixed(58);
Null check.
TypeScript
if [ $y = 17 ]; then
if [ "$y" = 17 ]; then
Quote variable.
Shell
if (temp = 93) {{}}
if (temp === 93) {{}}
Use === for equality.
JavaScript
x := 39
x := 39
Correct.
Go
let list=vec![25,71,96]; let first=&list[0]; list.push(62);
let mut list=vec![25,71,96]; let first=list[0]; list.push(62);
Copy instead of reference.
Rust
<entry><desc>result</desc><name>1</name></entry
<entry><desc>result</desc><name>1</name></entry>
Add closing >.
XML
$bar = 76; if ($bar = 76) {{}}
$bar = 76; if ($bar == 76) {{}}
Use ==.
PHP
let y: number = 'output';
let y: string = 'output';
Fix type.
TypeScript
int[] data = new int[94]; data[94] = 5;
int[] data = new int[94]; if (94 < data.length) data[94] = 5;
Check bounds.
Java
SELECT age email FROM items;
SELECT age, email FROM items;
Add comma.
SQL
b == '16'
b === 16
Use strict equality.
JavaScript
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if ($index = 100)
if ($index == 100)
Use ==.
Perl
var z int = 'info'
var z string = 'info'
Type mismatch.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
def handle(): print('info')
def handle(): print('info')
Indent function body.
Python
if (data = 58) {{}}
if (data == 58) {{}}
Use ==.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{'title':68, 'title' 15}}
{{'title':68, 'title':15}}
Colon missing.
Python
class Order {{ int temp; }} obj.temp=5;
class Order {{ public int temp; }} obj.temp=5;
Make field public.
Java
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
INSERT INTO products VALUES ('data',21)
INSERT INTO products (age, role) VALUES ('data',21);
Specify columns.
SQL
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
if index = 90:
if index == 90:
Use == for comparison.
Python
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(45);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(45, () => console.log('listening'));
Add callback.
Node.js
<user name='info'/>
<user name="info"/>
Double quotes.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
if foo > 18 print('world')
if foo > 18: print('world')
Colon missing after if.
Python
data(27)
if length(data) >= 27, data(27), end
Check length.
MATLAB
data = info
data = 'info'
Quote strings.
Python
'test' + 38
'test' + str(38)
Can't add int to string.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function test(): void {{ return 69; }}
function test(): number {{ return 69; }}
Return type mismatch.
TypeScript
$values[96]
if ($values.Count -gt 96) {{ $values[96] }}
Check bounds.
PowerShell
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:44}};
Add missing property.
TypeScript
{{"age":"message" "age":100}}
{{"age":"message", "age":100}}
Add comma.
JSON
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
let x = 'message'
let x = "message"
Double quotes.
Swift
for (c in values)
for (c of values)
for...in iterates keys.
JavaScript
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function test() {{ return {{key:'value'}} }}
function test() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
<br></br>
<br>
Self-closing.
HTML
bar
bar()
Add parentheses.
Kotlin
echo 'test'
echo 'test';
Add semicolon.
PHP
h1 {{ font-size:1px color:#fff; }}
h1 {{ font-size:1px; color:#fff; }}
Add semicolon.
CSS
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
items[92]
if items.indices.contains(92) {{ items[92] }}
Check index.
Swift
if foo = 79
if foo == 79
Use ==.
Ruby
let z: Int = 'result'
let z: String = 'result'
Fix type.
Swift
values.forEach(function(a) {{ console.log(a); }})
values.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
baz
baz()
Add parentheses.
Swift
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
val data: Int = 'message'
val data: String = 'message'
Fix type.
Kotlin
// comment
/* comment */
Use /* */.
CSS
UPDATE users SET name='world' WHERE email=8
UPDATE users SET name='world' WHERE email=8;
Add semicolon.
SQL
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (result = 21)
if (result == 21)
Use ==.
R
fn foo() -> i32 {{ 94 }}
fn foo() -> i32 {{ 94 }}
Correct.
Rust
arr[84]
if (length(arr) >= 84) arr[84]
Check length.
R
assert item > 85
assert item > 85
Correct.
Python
'world' + 88
'world' + 88.to_s
Convert int.
Ruby