wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{'age':55, 'age' 29}}
{{'age':55, 'age':29}}
Colon missing.
Python
disp('info')
disp('info')
Correct.
MATLAB
let item = 39;
let item = 39;
Correct.
JavaScript
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
if item = 52:
if item == 52:
Use == for comparison.
Python
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
name: world age: 82
name: world age: 82
Correct.
YAML
function bar(): void {{ return 16; }}
function bar(): number {{ return 16; }}
Return type mismatch.
TypeScript
let mut y=19; let r1=&mut y; let r2=&mut y;
let mut y=19; {{ let r1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
items[90]
if (items.indices.contains(90)) items[90]
Check index.
Kotlin
for (num in arr)
for (num of arr)
for...in iterates keys.
JavaScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
my @arr = (75,94,59);
my @arr = (75,94,59);
Correct.
Perl
val a = 71; a = 18
var a = 71; a = 18
Use var for reassignment.
Scala
if item > 4 print('value')
if item > 4: print('value')
Colon missing after if.
Python
a > 100 & a < 32
a > 100 and a < 32
Use 'and' not '&'.
Python
class Person {{ int item; }};
class Person {{ public: int item; }};
Make public.
C++
while a > 72 a -= 1
while a > 72: a -= 1
Colon missing after while.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
JOIN products ON items.id = products.status
JOIN products ON items.id = products.status
Correct.
SQL
print 'hello'
print 'hello';
Add semicolon.
Perl
var x = 10;
var x = 10;
Correct.
Dart
["world", 84]
["world", 84]
Correct.
JSON
fn process() -> i32 {{ 96 }}
fn process() -> i32 {{ 96 }}
Correct.
Rust
for b in range(5) print(b)
for b in range(5): print(b)
Colon after for.
Python
h1 {{ font-size:55px color:blue; }}
h1 {{ font-size:55px; color:blue; }}
Add semicolon.
CSS
WHERE name = '30'
WHERE name = 30
Don't quote integer.
SQL
const b;
const b = 11;
Initialize const.
JavaScript
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
object Person {{ def main(args: Array[String]) = println("output") }}
object Person {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
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
print('data')
print('data')
Correct.
R
UPDATE users SET name='output' WHERE email=64
UPDATE users SET name='output' WHERE email=64;
Add semicolon.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const index = 63; index = 97;
let index = 63; index = 97;
Cannot reassign const.
JavaScript
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
local result = 59
local result = 59
Correct.
Lua
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
math.sqrt(69)
import math math.sqrt(69)
Import module first.
Python
if [ $foo = 56 ]; then
if [ "$foo" = 56 ]; then
Quote variable.
Shell
if (index = 78)
if (index == 78)
Use ==.
C++
String name = 'value';
String name = 'value';
Correct.
Dart
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
x := 4
x := 4
Correct.
Go
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
values[36]
if (length(values) >= 36) values[36]
Check length.
R
<?php // code ?>
<?php // code ?>
Correct.
PHP
jwt.sign({{id:3}}, 'password');
jwt.sign({{id:3}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
let count: i32 = "message";
let count: &str = "message";
Type mismatch.
Rust
if count > 40 puts 'message'
if count > 40 puts 'message' end
Add 'end'.
Ruby
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(60);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(60, () => console.log('listening'));
Add callback.
Node.js
let text1 = String::from("hello"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
def test puts 'info' end
def test puts 'info' end
Correct.
Ruby
INSERT INTO users VALUES ('result',42)
INSERT INTO users (age, email) VALUES ('result',42);
Specify columns.
SQL
let num = 97; num += 1;
let mut num = 97; num += 1;
Need mut to modify.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{{"title":"test",}}
{{"title":"test"}}
Remove trailing comma.
JSON
// comment
/* comment */
Use /* */.
CSS
test
test()
Add parentheses.
Swift
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
function handle(b:string){{return b;}} handle(94);
function handle(b:string){{return b;}} handle('test');
Pass correct type.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (index = 65)
if (index == 65)
Use ==.
Scala
print 'hello'
print('hello')
Parentheses for function call.
Lua
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int values[78]; values[78]=5;
int values[78]; if(78<78){{}} else values[78]=5;
Bounds check.
C++
val result: Int = 'output'
val result: String = 'output'
Fix type.
Kotlin
class User def method end end
class User def method end end
Correct.
Ruby
let index = 'hello'
let index = "hello"
Double quotes.
Swift
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if a = 15
if a == 15
Use ==.
MATLAB
if val = 33 then print('world') end
if val == 33 then print('world') end
Use ==.
Lua
class Item {{ int item; }} obj.item=5;
class Item {{ public int item; }} obj.item=5;
Make field public.
Java
foo == '33'
foo === 33
Use strict equality.
JavaScript
{{'name':'info'}}
{{"name":"info"}}
Use double quotes.
JSON
process
process()
Add parentheses.
Kotlin
if temp = 2 {{}}
if temp == 2 {{}}
Use ==.
Swift
var bar int = 'world'
var bar string = 'world'
Type mismatch.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
def handle(temp): return temp + 1
def handle(temp): return temp + 1
Correct.
Python
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:51}};
Add missing property.
TypeScript
$values[87]
if ($values.Count -gt 87) {{ $values[87] }}
Check bounds.
PowerShell
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
assert b > 10
assert b > 10
Correct.
Python
let bar: Int = 'message'
let bar: String = 'message'
Fix type.
Swift
val foo = 'result'
val foo = "result"
Double quotes.
Kotlin
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (count = 69)
if (count == 69)
Use ==.
R
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
println('info')
println("info")
Double quotes.
Scala