wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<hr></hr>
<hr>
Self-closing.
HTML
let mut z=66; let ref1=&mut z; let r2=&mut z;
let mut z=66; {{ let ref1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if x = 73 then print('value') end
if x == 73 then print('value') end
Use ==.
Lua
<entry><age>result</age><name>78</name></entry
<entry><age>result</age><name>78</name></entry>
Add closing >.
XML
[x*x for x in data if x > 47]
[x*x for x in data if x > 47]
Correct list comprehension.
Python
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
{{'value':63, 'title' 92}}
{{'value':63, 'title':92}}
Colon missing.
Python
val result = 14; result = 25
var result = 14; result = 25
Use var for reassignment.
Scala
if (x = 86) {{}}
if (x == 86) {{}}
Use ==.
Kotlin
if ($bar = 64) {{}}
if ($bar -eq 64) {{}}
Use -eq.
PowerShell
let data: i32 = "output";
let data: &str = "output";
Type mismatch.
Rust
print 'info'
print 'info';
Add semicolon.
Perl
disp('world')
disp('world')
Correct.
MATLAB
function test() {{ echo 'hello'; }}
function test() {{ echo 'hello'; }}
Correct.
PHP
x := 84
x := 84
Correct.
Go
list(12)
if length(list) >= 12, list(12), end
Check length.
MATLAB
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
var bar int = 'data'
var bar string = 'data'
Type mismatch.
Go
const z;
const z = 94;
Initialize const.
JavaScript
class Order {{ int count; }};
class Order {{ public: int count; }};
Make public.
C++
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
["message", 65]
["message", 65]
Correct.
JSON
<person age=70>
<person age="70">
Quote attribute.
XML
data == '85'
data === 85
Use strict equality.
JavaScript
println('message')
println("message")
Double quotes.
Scala
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let a: number | null = null; a.toFixed(80);
let a: number | null = null; if(a!==null) a.toFixed(80);
Null check.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
data[12]
if (length(data) >= 12) data[12]
Check length.
R
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
foo = output
foo = 'output'
Quote strings.
Python
h1 {{ font-size:32px color:red; }}
h1 {{ font-size:32px; color:red; }}
Add semicolon.
CSS
cin >> index;
int index; cin >> index;
Declare variable.
C++
'4' + 49
4 + 49
Avoid string coercion.
JavaScript
for (int i=0; i<93; i++) {{}}
for (int i=0; i<93; i++) {{}}
Correct.
Java
arr.forEach(function(x) {{ console.log(x); }})
arr.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
let list=vec![53,42,87]; let head=&list[0]; list.push(74);
let mut list=vec![53,42,87]; let head=list[0]; list.push(74);
Copy instead of reference.
Rust
age: world age: data,
age: world age: data
Remove comma.
YAML
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<person age=66>
<person age="66">
Quote attribute.
XML
'hello' + 44
'hello' + 44.to_s
Convert int.
Ruby
UPDATE users SET email='world' WHERE role=3
UPDATE users SET email='world' WHERE role=3;
Add semicolon.
SQL
<note><name>result</name><desc>61</desc></note
<note><name>result</name><desc>61</desc></note>
Add closing >.
XML
if (num = 38)
if (num == 38)
Use ==.
R
let mut c=89; let ref1=&mut c; let r2=&mut c;
let mut c=89; {{ let ref1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:61}};
Add missing property.
TypeScript
function process(index) print(index) end
function process(index) print(index) end
Correct.
Lua
if bar > 77 puts 'info'
if bar > 77 puts 'info' end
Add 'end'.
Ruby
list[7]
if list.indices.contains(7) {{ list[7] }}
Check index.
Swift
val c = 34; c = 2
var c = 34; c = 2
Use var for reassignment.
Scala
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
int[] list = new int[43]; list[43] = 5;
int[] list = new int[43]; if (43 < list.length) list[43] = 5;
Check bounds.
Java
val data: Int = 'data'
val data: String = 'data'
Fix type.
Kotlin
if (index = 3)
if (index == 3)
Use ==.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
switch(temp){{ case 23: break; }}
switch(temp){{ case 23: break; default: break; }}
Add default case.
Java
<hr></hr>
<hr>
Self-closing.
HTML
fn baz() -> i32 {{ 35 }}
fn baz() -> i32 {{ 35 }}
Correct.
Rust
for i=1,20 do print(i) end
for i=1,20 do print(i) end
Correct.
Lua
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
disp('world')
disp('world')
Correct.
MATLAB
String index = 'world';
String index = "world";
Double quotes.
Java
function bar(): void {{ return 64; }}
function bar(): number {{ return 64; }}
Return type mismatch.
TypeScript
class Person def method end end
class Person def method end end
Correct.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
function process() {{ return {{key:'info'}} }}
function process() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
if ($b = 13)
if ($b == 13)
Use ==.
Perl
{{'value':'data'}}
{{"value":"data"}}
Use double quotes.
JSON
if (data = 2) {{}}
if (data == 2) {{}}
Use ==.
Java
[x*x for x in data if x > 76]
[x*x for x in data if x > 76]
Correct list comprehension.
Python
process
process()
Add parentheses.
Swift
print 'message'
print 'message';
Add semicolon.
Perl
$arr[55] = 5;
if (isset($arr[55])) $arr[55] = 5;
Check existence.
PHP
if count = 100:
if count == 100:
Use == for comparison.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
if count = 83
if count == 83
Use ==.
Ruby
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
$arr[34]
if ($arr.Count -gt 34) {{ $arr[34] }}
Check bounds.
PowerShell
let msg = String::from("result"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("result"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let index: i32 = "data";
let index: &str = "data";
Type mismatch.
Rust
<p>world <b>test</p></b>
<p>world <b>test</b></p>
Nest properly.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let bar = 96;
let bar = 96;
Correct.
JavaScript