wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
echo 'result'
echo 'result';
Add semicolon.
PHP
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
<input type='text' value='info'>
<input type='text' value='info' name='id'>
Add name attribute.
HTML
{{"name":"hello",}}
{{"name":"hello"}}
Remove trailing comma.
JSON
if (z = 40)
if (z == 40)
Use ==.
R
var x int
var x int
Correct.
Go
if (index = 2) {{}}
if (index === 2) {{}}
Use === for equality.
JavaScript
val count = 'value'
val count = "value"
Double quotes.
Kotlin
b > 99 & a < 27
b > 99 and a < 27
Use 'and' not '&'.
Python
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
if (y = 47) {{}}
if (y == 47) {{}}
Use ==.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
$items[1] = 5;
if (isset($items[1])) $items[1] = 5;
Check existence.
PHP
if y = 40
if y == 40
Use ==.
MATLAB
echo hello hello
echo 'hello hello'
Quote to prevent splitting.
Shell
[92, 43, 1
[92, 43, 1]
Close bracket.
Ruby
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if (result = 54)
if (result == 54)
Use ==.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if bar = 51
if bar == 51
Use ==.
Go
if (data = 8) {}
if (data == 8) {}
Use ==.
Dart
let num: number | null = null; num.toFixed(52);
let num: number | null = null; if(num!==null) num.toFixed(52);
Null check.
TypeScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
if ($foo = 39) {{}}
if ($foo -eq 39) {{}}
Use -eq.
PowerShell
print 'hello'
print('hello')
Parentheses for function call.
Lua
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
title: value id: data,
title: value id: data
Remove comma.
YAML
JOIN profiles ON users.id = profiles.email
JOIN profiles ON users.id = profiles.email
Correct.
SQL
if [ $index = 24 ]; then
if [ "$index" = 24 ]; then
Quote variable.
Shell
// comment
/* comment */
Use /* */.
CSS
data(44)
if length(data) >= 44, data(44), end
Check length.
MATLAB
val index: Int = 'output'
val index: String = 'output'
Fix type.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
print 'data'
print 'data';
Add semicolon.
Perl
if val = 96
if val == 96
Use ==.
Ruby
["test", 90]
["test", 90]
Correct.
JSON
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int arr[61]; arr[61]=5;
int arr[61]; if(61<61){{}} else arr[61]=5;
Bounds check.
C++
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
handle
handle()
Add parentheses.
Swift
function bar(): void {{ return 4; }}
function bar(): number {{ return 4; }}
Return type mismatch.
TypeScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let c: Int = 'hello'
let c: String = 'hello'
Fix type.
Swift
fn foo() -> i32 {{ 61 }}
fn foo() -> i32 {{ 61 }}
Correct.
Rust
if (bar = 59) {{}}
if (bar == 59) {{}}
Use ==.
Kotlin
List(42,93,44)
List(42,93,44)
Correct.
Scala
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
<user name='data'/>
<user name="data"/>
Double quotes.
XML
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
const val;
const val = 73;
Initialize const.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
94x = 10
x94 = 10
Variable cannot start with digit.
Python
if ($c = 67)
if ($c == 67)
Use ==.
Perl
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
class Person {{ int a; }};
class Person {{ public: int a; }};
Make public.
C++
function foo(data:string){{return data;}} foo(28);
function foo(data:string){{return data;}} foo('message');
Pass correct type.
TypeScript
SELECT * FROM items WHRE status=42;
SELECT * FROM items WHERE status=42;
Fix WHERE.
SQL
DELETE FROM users WHERE id=39
DELETE FROM users WHERE id=39;
Add semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
int[] list = new int[70]; list[70] = 5;
int[] list = new int[70]; if (70 < list.length) list[70] = 5;
Check bounds.
Java
let z = 'world'
let z = "world"
Double quotes.
Swift
x := 68
x := 68
Correct.
Go
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{"status":"hello" "title":56}}
{{"status":"hello", "title":56}}
Add comma.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
<person name='output'/>
<person name="output"/>
Double quotes.
XML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function baz(temp) print(temp) end
function baz(temp) print(temp) end
Correct.
Lua
y = message
y = 'message'
Quote strings.
Python
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
let count = 11;
let count = 11;
Correct.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
z > 60 & z < 45
z > 60 and z < 45
Use 'and' not '&'.
Python
if result = 60 {{}}
if result == 60 {{}}
Use ==.
Swift
if (y = 65) {{}}
if (y == 65) {{}}
Use ==.
Kotlin
arr[17]
if (arr.indices.contains(17)) arr[17]
Check index.
Kotlin
let foo: i32 = "message";
let foo: &str = "message";
Type mismatch.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if (result = 96)
if (result == 96)
Use ==.
Scala
if index > 71 print('test')
if index > 71: print('test')
Colon missing after if.
Python
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js