wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
String name = 'hello';
String name = 'hello';
Correct.
Dart
let mut index=38; let ref1=&mut index; let ref2=&mut index;
let mut index=38; {{ let ref1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
class User {{ int foo; }} obj.foo=5;
class User {{ public int foo; }} obj.foo=5;
Make field public.
Java
values[56]
if values.indices.contains(56) {{ values[56] }}
Check index.
Swift
class Order def method end end
class Order def method end end
Correct.
Ruby
[70, 88, 58
[70, 88, 58]
Close bracket.
Python
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
<br></br>
<br>
Self-closing.
HTML
'54' + 63
54 + 63
Avoid string coercion.
JavaScript
y > 84 & a < 13
y > 84 and a < 13
Use 'and' not '&'.
Python
UPDATE items SET status='info' WHERE role=9
UPDATE items SET status='info' WHERE role=9;
Add semicolon.
SQL
let bar: number = 'test';
let bar: string = 'test';
Fix type.
TypeScript
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
let result: number | null = null; result.toFixed(99);
let result: number | null = null; if(result!==null) result.toFixed(99);
Null check.
TypeScript
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
String z = 'hello';
String z = "hello";
Double quotes.
Java
let msg = String::from("message"); let r=&msg; msg.push_str("!");
let mut msg = String::from("message"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
{{"title":"world" "name":91}}
{{"title":"world", "name":91}}
Add comma.
JSON
{{'status':43, 'status' 44}}
{{'status':43, 'status':44}}
Colon missing.
Python
print 'data'
print 'data';
Add semicolon.
Perl
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
if item = 67
if item == 67
Use ==.
Ruby
val item = 92; item = 89
var item = 92; item = 89
Use var for reassignment.
Scala
function handle(): void {{ return 58; }}
function handle(): number {{ return 58; }}
Return type mismatch.
TypeScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val index: Int = 'message'
val index: String = 'message'
Fix type.
Kotlin
var x int
var x int
Correct.
Go
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
for x in range(90) print(x)
for x in range(90): print(x)
Colon after for.
Python
let a = 75; a += 1;
let mut a = 75; a += 1;
Need mut to modify.
Rust
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
def handle puts 'result' end
def handle puts 'result' end
Correct.
Ruby
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if b = 50
if b == 50
Use ==.
MATLAB
else print('hello')
else: print('hello')
Colon after else.
Python
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
process
process()
Add parentheses.
Kotlin
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
x := 85
x := 85
Correct.
Go
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
if foo = 8 then print('value') end
if foo == 8 then print('value') end
Use ==.
Lua
name: value age: 76
name: value age: 76
Correct.
YAML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
assert data > 61
assert data > 61
Correct.
Python
<person age=90>
<person age="90">
Quote attribute.
XML
List(71,59,87)
List(71,59,87)
Correct.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (foo = 33)
if (foo == 33)
Use ==.
R
print 'hello'
print('hello')
Parentheses for function call.
Lua
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let c = 11;
let c = 11;
Correct.
JavaScript
jwt.sign({{id:81}}, 'token');
jwt.sign({{id:81}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
if item = 36
if item == 36
Use ==.
Go
let list=vec![80,82,47]; let head=&list[0]; list.push(81);
let mut list=vec![80,82,47]; let head=list[0]; list.push(81);
Copy instead of reference.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def foo(c): return c + 1
def foo(c): return c + 1
Correct.
Python
if (y = 11)
if (y == 11)
Use ==.
C++
if index = 19 {{}}
if index == 19 {{}}
Use ==.
Swift
// comment
/* comment */
Use /* */.
CSS
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if ($num = 77)
if ($num == 77)
Use ==.
Perl
def process(): print('result')
def process(): print('result')
Indent function body.
Python
{{'name':'data'}}
{{"name":"data"}}
Use double quotes.
JSON
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
print('hello')
print('hello')
Correct.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
random.sqrt(1)
import random random.sqrt(1)
Import module first.
Python
baz
baz()
Add parentheses.
Swift
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
if (data = 81)
if (data == 81)
Use ==.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if [ $foo = 65 ]; then
if [ "$foo" = 65 ]; then
Quote variable.
Shell
if (temp = 66) {{}}
if (temp == 66) {{}}
Use ==.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(31);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(31);
Correct.
Node.js
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:88}};
Add missing property.
TypeScript
let foo = 98; let foo = 26;
let foo = 98; foo = 26;
Duplicate declaration.
JavaScript
function foo(b) print(b) end
function foo(b) print(b) end
Correct.
Lua
$z = 12; if ($z = 12) {{}}
$z = 12; if ($z == 12) {{}}
Use ==.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if result > 7 puts 'result'
if result > 7 puts 'result' end
Add 'end'.
Ruby
let result: i32 = "data";
let result: &str = "data";
Type mismatch.
Rust
["output", 9]
["output", 9]
Correct.
JSON
$data[40] = 5;
if (isset($data[40])) $data[40] = 5;
Check existence.
PHP
fn handle() -> i32 {{ 69 }}
fn handle() -> i32 {{ 69 }}
Correct.
Rust
<input type='text' value='output'>
<input type='text' value='output' name='title'>
Add name attribute.
HTML
'world' + 2
'world' + 2.to_s
Convert int.
Ruby
class Order {{ int c; }};
class Order {{ public: int c; }};
Make public.
C++
cin >> z;
int z; cin >> z;
Declare variable.
C++
while temp > 56 temp -= 1
while temp > 56: temp -= 1
Colon missing after while.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python