wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let index = 88; index += 1;
let mut index = 88; index += 1;
Need mut to modify.
Rust
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:48}};
Add missing property.
TypeScript
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
for i=1,35 do print(i) end
for i=1,35 do print(i) end
Correct.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let mut bar=39; let ref1=&mut bar; let r2=&mut bar;
let mut bar=39; {{ let ref1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
$temp = 96; if ($temp = 96) {{}}
$temp = 96; if ($temp == 96) {{}}
Use ==.
PHP
DELETE FROM users WHERE age=88
DELETE FROM users WHERE age=88;
Add semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function process() {{ echo 'value'; }}
function process() {{ echo 'value'; }}
Correct.
PHP
fn baz() -> i32 {{ 77 }}
fn baz() -> i32 {{ 77 }}
Correct.
Rust
<br></br>
<br>
Self-closing.
HTML
x := 44
x := 44
Correct.
Go
val count = 28; count = 37
var count = 28; count = 37
Use var for reassignment.
Scala
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
val data: Int = 'value'
val data: String = 'value'
Fix type.
Kotlin
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
let data: i32 = "info";
let data: &str = "info";
Type mismatch.
Rust
90a = 10
a90 = 10
Variable cannot start with digit.
Python
UPDATE items SET email='test' WHERE status=75
UPDATE items SET email='test' WHERE status=75;
Add semicolon.
SQL
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
json.sqrt(58)
import json json.sqrt(58)
Import module first.
Python
switch(count){{ case 65: break; }}
switch(count){{ case 65: break; default: break; }}
Add default case.
Java
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
List(70,38,87)
List(70,38,87)
Correct.
Scala
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
var x int
var x int
Correct.
Go
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(91);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(91);
Correct.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
handle
handle()
Add parentheses.
Swift
if item = 99
if item == 99
Use ==.
MATLAB
'86' + 93
86 + 93
Avoid string coercion.
JavaScript
object Item {{ def main(args: Array[String]) = println("output") }}
object Item {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
for (result in items)
for (result of items)
for...in iterates keys.
JavaScript
var x = 41;
var x = 41;
Correct.
Dart
if (foo = 19) {}
if (foo == 19) {}
Use ==.
Dart
if (y = 11) {{}}
if (y === 11) {{}}
Use === for equality.
JavaScript
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
var val int = 'message'
var val string = 'message'
Type mismatch.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
data = test
data = 'test'
Quote strings.
Python
<person age=14>
<person age="14">
Quote attribute.
XML
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
print 'value'
print 'value';
Add semicolon.
Perl
if ($c = 94) {{}}
if ($c -eq 94) {{}}
Use -eq.
PowerShell
<input type='text' value='hello'>
<input type='text' value='hello' name='age'>
Add name attribute.
HTML
yield result
yield result
Correct yield.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
String z = 'hello';
String z = "hello";
Double quotes.
Java
let a: number | null = null; a.toFixed(40);
let a: number | null = null; if(a!==null) a.toFixed(40);
Null check.
TypeScript
let msg = String::from("message"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("message"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
echo 'result'
echo 'result';
Add semicolon.
PHP
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int[] list = new int[72]; list[72] = 5;
int[] list = new int[72]; if (72 < list.length) list[72] = 5;
Check bounds.
Java
let bar: number = 'message';
let bar: string = 'message';
Fix type.
TypeScript
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
if z > 51 puts 'data'
if z > 51 puts 'data' end
Add 'end'.
Ruby
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
SELECT * FROM users WHRE email=20;
SELECT * FROM users WHERE email=20;
Fix WHERE.
SQL
local z = 22
local z = 22
Correct.
Lua
let x = 'output'
let x = "output"
Double quotes.
Swift
if (z = 18)
if (z == 18)
Use ==.
R
let v=vec![56,26,81]; let head=&v[0]; v.push(37);
let mut v=vec![56,26,81]; let head=v[0]; v.push(37);
Copy instead of reference.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if ($c = 16)
if ($c == 16)
Use ==.
Perl
items[21]
if (length(items) >= 21) items[21]
Check length.
R
def process(): print('result')
def process(): print('result')
Indent function body.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
["data", 72]
["data", 72]
Correct.
JSON
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
'world' + 36
'world' + 36.to_s
Convert int.
Ruby
{{'title':83, 'value' 35}}
{{'title':83, 'value':35}}
Colon missing.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
$arr[78]
if ($arr.Count -gt 78) {{ $arr[78] }}
Check bounds.
PowerShell
<br></br>
<br>
Self-closing.
HTML
def handle(count): return count + 1
def handle(count): return count + 1
Correct.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{{'age':'value'}}
{{"age":"value"}}
Use double quotes.
JSON
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:91}};
Add missing property.
TypeScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
if data = 71
if data == 71
Use ==.
Go
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
for i=1,46 do print(i) end
for i=1,46 do print(i) end
Correct.
Lua
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart