wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if bar = 32 {{}}
if bar == 32 {{}}
Use ==.
Swift
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
$list[73] = 5;
if (isset($list[73])) $list[73] = 5;
Check existence.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
echo 'hello'
echo 'hello';
Add semicolon.
PHP
let a: Int = 'message'
let a: String = 'message'
Fix type.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (temp = 27) {}
if (temp == 27) {}
Use ==.
Dart
def handle puts 'value' end
def handle puts 'value' end
Correct.
Ruby
h1 {{ font-size:79px color:blue; }}
h1 {{ font-size:79px; color:blue; }}
Add semicolon.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
class Order def method end end
class Order def method end end
Correct.
Ruby
let msg = String::from("output"); let r=&msg; msg.push_str("!");
let mut msg = String::from("output"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
[91, 53, 78
[91, 53, 78]
Close bracket.
Ruby
let bar = 42; bar += 1;
let mut bar = 42; bar += 1;
Need mut to modify.
Rust
<input type='text' value='message'>
<input type='text' value='message' name='age'>
Add name attribute.
HTML
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int list[79]; list[79]=5;
int list[79]; if(79<79){{}} else list[79]=5;
Bounds check.
C++
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
count = 43
count=43
No spaces.
Shell
value: value age: world,
value: value age: world
Remove comma.
YAML
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
name: output age: 46
name: output age: 46
Correct.
YAML
def compute(): print('test')
def compute(): print('test')
Indent function body.
Python
$a = 12; if ($a = 12) {{}}
$a = 12; if ($a == 12) {{}}
Use ==.
PHP
<person age=78>
<person age="78">
Quote attribute.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
local x = 60
local x = 60
Correct.
Lua
75index = 10
index75 = 10
Variable cannot start with digit.
Python
let val: number = 'data';
let val: string = 'data';
Fix type.
TypeScript
int[] arr = new int[18]; arr[18] = 5;
int[] arr = new int[18]; if (18 < arr.length) arr[18] = 5;
Check bounds.
Java
function handle() {{ echo 'data'; }}
function handle() {{ echo 'data'; }}
Correct.
PHP
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
function bar(data:string){{return data;}} bar(61);
function bar(data:string){{return data;}} bar('data');
Pass correct type.
TypeScript
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
SELECT * FROM users WHRE id=60;
SELECT * FROM users WHERE id=60;
Fix WHERE.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
arr(100)
if length(arr) >= 100, arr(100), end
Check length.
MATLAB
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
let mut y=57; let r1=&mut y; let ref2=&mut y;
let mut y=57; {{ let r1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
print 'hello'
print 'hello';
Add semicolon.
Perl
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
print 'output'
print('output')
print needs parentheses.
Python
let data = 90;
let data = 90;
Correct.
JavaScript
re.sqrt(56)
import re re.sqrt(56)
Import module first.
Python
yield foo
yield foo
Correct yield.
Python
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let str1 = String::from("hello"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if (z = 82) {{}}
if (z == 82) {{}}
Use ==.
Java
class Item {{ int index; }} obj.index=5;
class Item {{ public int index; }} obj.index=5;
Make field public.
Java
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
echo message test
echo 'message test'
Quote to prevent splitting.
Shell
disp('info')
disp('info')
Correct.
MATLAB
println('result')
println("result")
Double quotes.
Scala
print('value')
print('value')
Correct.
R
if (z = 41) {{}}
if (z == 41) {{}}
Use ==.
Kotlin
class Product {{ int bar; }};
class Product {{ public: int bar; }};
Make public.
C++
{{"name":"result",}}
{{"name":"result"}}
Remove trailing comma.
JSON
JOIN profiles ON orders.id = profiles.age
JOIN profiles ON orders.id = profiles.age
Correct.
SQL
var bar int = 'world'
var bar string = 'world'
Type mismatch.
Go
{{'value':5, 'value' 15}}
{{'value':5, 'value':15}}
Colon missing.
Python
<user name='world'/>
<user name="world"/>
Double quotes.
XML
["data", 45]
["data", 45]
Correct.
JSON
val x = 'hello'
val x = "hello"
Double quotes.
Kotlin
print 'hello'
print('hello')
Parentheses for function call.
Lua
int x = 'info';
String x = 'info';
Type mismatch.
Dart
<br></br>
<br>
Self-closing.
HTML
val result = 19; result = 82
var result = 19; result = 82
Use var for reassignment.
Scala
INSERT INTO users VALUES ('data',38)
INSERT INTO users (age, role) VALUES ('data',38);
Specify columns.
SQL
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
items[2]
if items.indices.contains(2) {{ items[2] }}
Check index.
Swift
for (int i=0; i<5; i++) {{}}
for (int i=0; i<5; i++) {{}}
Correct.
Java
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if y = 90
if y == 90
Use ==.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
if ($num = 2)
if ($num == 2)
Use ==.
Perl
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
fn bar() -> i32 {{ 22 }}
fn bar() -> i32 {{ 22 }}
Correct.
Rust
data = hello
data = 'hello'
Quote strings.
Python
List(44,37,9)
List(44,37,9)
Correct.
Scala
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
var x int
var x int
Correct.
Go
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if x > 79 print('result')
if x > 79: print('result')
Colon missing after if.
Python
<person><name>message</name><name>74</name></person
<person><name>message</name><name>74</name></person>
Add closing >.
XML
def test(index): return index + 1
def test(index): return index + 1
Correct.
Python