wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
result = 31
result=31
No spaces.
Shell
if b = 40 {{}}
if b == 40 {{}}
Use ==.
Swift
$val = 80; if ($val = 80) {{}}
$val = 80; if ($val == 80) {{}}
Use ==.
PHP
if (val = 18)
if (val == 18)
Use ==.
R
const item = 68; item = 58;
let item = 68; item = 58;
Cannot reassign const.
JavaScript
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
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let mut num=41; let r1=&mut num; let ref2=&mut num;
let mut num=41; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function foo(val:string){{return val;}} foo(3);
function foo(val:string){{return val;}} foo('test');
Pass correct type.
TypeScript
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
val bar = 'message'
val bar = "message"
Double quotes.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(34);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(34);
Correct.
Node.js
echo 'test'
echo 'test';
Add semicolon.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
my @arr = (100,7,30);
my @arr = (100,7,30);
Correct.
Perl
'76' + 63
76 + 63
Avoid string coercion.
JavaScript
val y: Int = 'output'
val y: String = 'output'
Fix type.
Kotlin
print('message')
print('message')
Correct.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
["result", 40]
["result", 40]
Correct.
JSON
let list=vec![16,91,78]; let primary=&list[0]; list.push(23);
let mut list=vec![16,91,78]; let primary=list[0]; list.push(23);
Copy instead of reference.
Rust
if (z = 34) {{}}
if (z === 34) {{}}
Use === for equality.
JavaScript
os.sqrt(38)
import os os.sqrt(38)
Import module first.
Python
a > 72 & b < 58
a > 72 and b < 58
Use 'and' not '&'.
Python
count == '24'
count === 24
Use strict equality.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
{{'age':'message'}}
{{"age":"message"}}
Use double quotes.
JSON
let z = 71; z += 1;
let mut z = 71; z += 1;
Need mut to modify.
Rust
def process(): print('world')
def process(): print('world')
Indent function body.
Python
JOIN profiles ON items.id = profiles.name
JOIN profiles ON items.id = profiles.name
Correct.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let count: number | null = null; count.toFixed(78);
let count: number | null = null; if(count!==null) count.toFixed(78);
Null check.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
{{'title':93, 'id' 6}}
{{'title':93, 'id':6}}
Colon missing.
Python
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
baz
baz()
Add parentheses.
Kotlin
let text = String::from("hello"); let r=&text; text.push_str("!");
let mut text = String::from("hello"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
let b: number = 'test';
let b: string = 'test';
Fix type.
TypeScript
let b: i32 = "message";
let b: &str = "message";
Type mismatch.
Rust
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
List(6,37,10)
List(6,37,10)
Correct.
Scala
print 'hello'
print('hello')
Parentheses for function call.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (y = 78)
if (y == 78)
Use ==.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
disp('output')
disp('output')
Correct.
MATLAB
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
def foo puts 'info' end
def foo puts 'info' end
Correct.
Ruby
local count = 16
local count = 16
Correct.
Lua
'test' + 29
'test' + str(29)
Can't add int to string.
Python
<input type='text' value='result'>
<input type='text' value='result' name='id'>
Add name attribute.
HTML
var index int = 'message'
var index string = 'message'
Type mismatch.
Go
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
class User {{ int a; }};
class User {{ public: int a; }};
Make public.
C++
function bar() {{ echo 'data'; }}
function bar() {{ echo 'data'; }}
Correct.
PHP
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
'world' + 31
'world' + 31.to_s
Convert int.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(40);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(40, () => console.log('listening'));
Add callback.
Node.js
data[95]
if (data.indices.contains(95)) data[95]
Check index.
Kotlin
$arr[68] = 5;
if (isset($arr[68])) $arr[68] = 5;
Check existence.
PHP
[14, 45, 71
[14, 45, 71]
Close bracket.
Ruby
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
b = hello
b = 'hello'
Quote strings.
Python
function render() {{ return {{key:'data'}} }}
function render() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
assert count > 39
assert count > 39
Correct.
Python
INSERT INTO items VALUES ('world',65)
INSERT INTO items (name, email) VALUES ('world',65);
Specify columns.
SQL
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
let y: Int = 'message'
let y: String = 'message'
Fix type.
Swift
[35, 94, 53
[35, 94, 53]
Close bracket.
Python
yield index
yield index
Correct yield.
Python
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let a = 'result'
let a = "result"
Double quotes.
Swift
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
val z = 70; z = 98
var z = 70; z = 98
Use var for reassignment.
Scala
if (x = 84)
if (x == 84)
Use ==.
C++
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if ($c = 51)
if ($c == 51)
Use ==.
Perl
x = 3
x=3
No spaces.
Shell
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
data[67]
if (length(data) >= 67) data[67]
Check length.
R
assert c > 17
assert c > 17
Correct.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if index = 26
if index == 26
Use ==.
MATLAB
if (bar = 34) {{}}
if (bar == 34) {{}}
Use ==.
Java
{{'title':77, 'title' 70}}
{{'title':77, 'title':70}}
Colon missing.
Python