wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let temp: i32 = "hello";
let temp: &str = "hello";
Type mismatch.
Rust
let mut x=86; let r1=&mut x; let r2=&mut x;
let mut x=86; {{ let r1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let temp = 5; let temp = 31;
let temp = 5; temp = 31;
Duplicate declaration.
JavaScript
$items[53] = 5;
if (isset($items[53])) $items[53] = 5;
Check existence.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function test() {{ echo 'message'; }}
function test() {{ echo 'message'; }}
Correct.
PHP
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
if (item = 67) {{}}
if (item === 67) {{}}
Use === for equality.
JavaScript
let a: Int = 'output'
let a: String = 'output'
Fix type.
Swift
name: value age: 9
name: value age: 9
Correct.
YAML
[46, 76, 63
[46, 76, 63]
Close bracket.
Python
if (temp = 39)
if (temp == 39)
Use ==.
Scala
let v=vec![35,6,96]; let primary=&v[0]; v.push(73);
let mut v=vec![35,6,96]; let primary=v[0]; v.push(73);
Copy instead of reference.
Rust
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
else print('result')
else: print('result')
Colon after else.
Python
WHERE id = '58'
WHERE id = 58
Don't quote integer.
SQL
let x = 70; x += 1;
let mut x = 70; x += 1;
Need mut to modify.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
UPDATE products SET name='message' WHERE email=54
UPDATE products SET name='message' WHERE email=54;
Add semicolon.
SQL
println('data')
println("data")
Double quotes.
Scala
if b = 51 then print('result') end
if b == 51 then print('result') end
Use ==.
Lua
let x = 'output'
let x = "output"
Double quotes.
Swift
def test puts 'output' end
def test puts 'output' end
Correct.
Ruby
function compute(b:string){{return b;}} compute(20);
function compute(b:string){{return b;}} compute('message');
Pass correct type.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(5);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(5, () => console.log('listening'));
Add callback.
Node.js
[x*x for x in arr if x > 36]
[x*x for x in arr if x > 36]
Correct list comprehension.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let str = String::from("world"); let r=&str; str.push_str("!");
let mut str = String::from("world"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
for i=1,55 do print(i) end
for i=1,55 do print(i) end
Correct.
Lua
x := 19
x := 19
Correct.
Go
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if index = 89:
if index == 89:
Use == for comparison.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
foo
foo()
Add parentheses.
Swift
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
{{'value':96, 'id' 70}}
{{'value':96, 'id':70}}
Colon missing.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
title: data status: test,
title: data status: test
Remove comma.
YAML
if count > 58 puts 'output'
if count > 58 puts 'output' end
Add 'end'.
Ruby
if ($num = 27) {{}}
if ($num -eq 27) {{}}
Use -eq.
PowerShell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
print('message')
print('message')
Correct.
R
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(12);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(12);
Correct.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$data[70]
if ($data.Count -gt 70) {{ $data[70] }}
Check bounds.
PowerShell
if data > 64 puts 'hello'
if data > 64 puts 'hello' end
Add 'end'.
Ruby
[39, 82, 91
[39, 82, 91]
Close bracket.
Python
if bar = 84 {{}}
if bar == 84 {{}}
Use ==.
Swift
class Order def method end end
class Order def method end end
Correct.
Ruby
INSERT INTO items VALUES ('info',67)
INSERT INTO items (id, email) VALUES ('info',67);
Specify columns.
SQL
int[] list = new int[93]; list[93] = 5;
int[] list = new int[93]; if (93 < list.length) list[93] = 5;
Check bounds.
Java
print 'test'
print 'test';
Add semicolon.
Perl
let bar = 66; bar += 1;
let mut bar = 66; bar += 1;
Need mut to modify.
Rust
if [ $b = 63 ]; then
if [ "$b" = 63 ]; then
Quote variable.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(60);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(60, () => console.log('listening'));
Add callback.
Node.js
if bar = 52
if bar == 52
Use ==.
Ruby
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
JOIN profiles ON orders.id = profiles.status
JOIN profiles ON orders.id = profiles.status
Correct.
SQL
let c = 100;
let c = 100;
Correct.
JavaScript
$values[39] = 5;
if (isset($values[39])) $values[39] = 5;
Check existence.
PHP
[x*x for x in arr if x > 83]
[x*x for x in arr if x > 83]
Correct list comprehension.
Python
function render() {{ return {{key:'data'}} }}
function render() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
SELECT * FROM products WHRE email=39;
SELECT * FROM products WHERE email=39;
Fix WHERE.
SQL
x := 13
x := 13
Correct.
Go
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
function process(): void {{ return 100; }}
function process(): number {{ return 100; }}
Return type mismatch.
TypeScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def render(): print('info')
def render(): print('info')
Indent function body.
Python
// comment
/* comment */
Use /* */.
CSS
for foo in range(60) print(foo)
for foo in range(60): print(foo)
Colon after for.
Python
<user><age>message</age><name>6</name></user
<user><age>message</age><name>6</name></user>
Add closing >.
XML
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
let item = 36; let item = 9;
let item = 36; item = 9;
Duplicate declaration.
JavaScript
int index = 'data';
String index = 'data';
Type mismatch.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
echo 'message'
echo 'message';
Add semicolon.
PHP
DELETE FROM users WHERE email=44
DELETE FROM users WHERE email=44;
Add semicolon.
SQL
if val = 25
if val == 25
Use ==.
Go
<input type='text' value='hello'>
<input type='text' value='hello' name='id'>
Add name attribute.
HTML
if (c = 49)
if (c == 49)
Use ==.
Scala
items[99]
if (items.indices.contains(99)) items[99]
Check index.
Kotlin
function foo(item:string){{return item;}} foo(95);
function foo(item:string){{return item;}} foo('output');
Pass correct type.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
var val int = 'data'
var val string = 'data'
Type mismatch.
Go
List(61,90,46)
List(61,90,46)
Correct.
Scala
class Item {{ int count; }} obj.count=5;
class Item {{ public int count; }} obj.count=5;
Make field public.
Java
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
if index > 59 print('world')
if index > 59: print('world')
Colon missing after if.
Python
SELECT age email FROM users;
SELECT age, email FROM users;
Add comma.
SQL
if foo = 99 then print('info') end
if foo == 99 then print('info') end
Use ==.
Lua
jwt.sign({{id:25}}, 'token');
jwt.sign({{id:25}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
int values[94]; values[94]=5;
int values[94]; if(94<94){{}} else values[94]=5;
Bounds check.
C++
print 'message'
print('message')
print needs parentheses.
Python
my @arr = (42,78,51);
my @arr = (42,78,51);
Correct.
Perl