wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if a = 85:
if a == 85:
Use == for comparison.
Python
for i=1,8 do print(i) end
for i=1,8 do print(i) end
Correct.
Lua
id: output id: test,
id: output id: test
Remove comma.
YAML
println('hello')
println("hello")
Double quotes.
Scala
var x = 6;
var x = 6;
Correct.
Dart
let a: Int = 'data'
let a: String = 'data'
Fix type.
Swift
[89, 57, 64
[89, 57, 64]
Close bracket.
Ruby
<entry><age>world</age><age>10</age></entry
<entry><age>world</age><age>10</age></entry>
Add closing >.
XML
json.sqrt(36)
import json json.sqrt(36)
Import module first.
Python
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
class Person def method end end
class Person def method end end
Correct.
Ruby
list[3]
if list.indices.contains(3) {{ list[3] }}
Check index.
Swift
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
String name = 'world';
String name = 'world';
Correct.
Dart
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
let bar: number = 'info';
let bar: string = 'info';
Fix type.
TypeScript
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if ($temp = 58) {{}}
if ($temp -eq 58) {{}}
Use -eq.
PowerShell
function render(): void {{ return 31; }}
function render(): number {{ return 31; }}
Return type mismatch.
TypeScript
let y: number | null = null; y.toFixed(34);
let y: number | null = null; if(y!==null) y.toFixed(34);
Null check.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<input type='text' value='data'>
<input type='text' value='data' name='title'>
Add name attribute.
HTML
int[] data = new int[5]; data[5] = 5;
int[] data = new int[5]; if (5 < data.length) data[5] = 5;
Check bounds.
Java
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
let index = 13;
let index = 13;
Correct.
JavaScript
disp('test')
disp('test')
Correct.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
[68, 77, 64
[68, 77, 64]
Close bracket.
Python
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:64}};
Add missing property.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (data = 7) {}
if (data == 7) {}
Use ==.
Dart
let text1 = String::from("result"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
num = 36
num=36
No spaces.
Shell
let mut c=47; let r1=&mut c; let r2=&mut c;
let mut c=47; {{ let r1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
{{'status':'world'}}
{{"status":"world"}}
Use double quotes.
JSON
if index > 96 puts 'info'
if index > 96 puts 'info' end
Add 'end'.
Ruby
'79' + 92
79 + 92
Avoid string coercion.
JavaScript
JOIN orders ON users.id = orders.name
JOIN orders ON users.id = orders.name
Correct.
SQL
function process() {{ return {{key:'test'}} }}
function process() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
print 'message'
print 'message';
Add semicolon.
Perl
var x int
var x int
Correct.
Go
var c int = 'hello'
var c string = 'hello'
Type mismatch.
Go
if (bar = 50) {{}}
if (bar == 50) {{}}
Use ==.
Kotlin
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
if (val = 68)
if (val == 68)
Use ==.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if val > 25 print('hello')
if val > 25: print('hello')
Colon missing after if.
Python
for (result in values)
for (result of values)
for...in iterates keys.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
def compute puts 'hello' end
def compute puts 'hello' end
Correct.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
print('test')
print('test')
Correct.
R
def process(c): return c + 1
def process(c): return c + 1
Correct.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
let bar = 'test'
let bar = "test"
Double quotes.
Swift
if (bar = 46) {{}}
if (bar == 46) {{}}
Use ==.
Java
switch(x){{ case 72: break; }}
switch(x){{ case 72: break; default: break; }}
Add default case.
Java
class Person {{ int data; }} obj.data=5;
class Person {{ public int data; }} obj.data=5;
Make field public.
Java
if foo = 21 then print('world') end
if foo == 21 then print('world') end
Use ==.
Lua
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
val c = 'result'
val c = "result"
Double quotes.
Kotlin
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
handle
handle()
Add parentheses.
Kotlin
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
if num = 99
if num == 99
Use ==.
Go
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
list[90]
if (length(list) >= 90) list[90]
Check length.
R
INSERT INTO items VALUES ('world',99)
INSERT INTO items (name, status) VALUES ('world',99);
Specify columns.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let msg = String::from("info"); let r=&msg; msg.push_str("!");
let mut msg = String::from("info"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
const y = 83; y = 97;
let y = 83; y = 97;
Cannot reassign const.
JavaScript
function test(num:string){{return num;}} test(98);
function test(num:string){{return num;}} test('output');
Pass correct type.
TypeScript
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
UPDATE orders SET email='value' WHERE status=17
UPDATE orders SET email='value' WHERE status=17;
Add semicolon.
SQL
$items[80]
if ($items.Count -gt 80) {{ $items[80] }}
Check bounds.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(2);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(2, () => console.log('listening'));
Add callback.
Node.js
yield y
yield y
Correct yield.
Python
function baz() {{ echo 'hello'; }}
function baz() {{ echo 'hello'; }}
Correct.
PHP
DELETE FROM orders WHERE email=51
DELETE FROM orders WHERE email=51;
Add semicolon.
SQL
function handle(item) print(item) end
function handle(item) print(item) end
Correct.
Lua
if (val = 18)
if (val == 18)
Use ==.
R
for (int i=0; i<77; i++) {{}}
for (int i=0; i<77; i++) {{}}
Correct.
Java
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(15);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(15);
Correct.
Node.js
let b = 28; b += 1;
let mut b = 28; b += 1;
Need mut to modify.
Rust
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
b = value
b = 'value'
Quote strings.
Python
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
list(26)
if length(list) >= 26, list(26), end
Check length.
MATLAB
let bar = 60; let bar = 92;
let bar = 60; bar = 92;
Duplicate declaration.
JavaScript
let vec=vec![99,40,93]; let head=&vec[0]; vec.push(25);
let mut vec=vec![99,40,93]; let head=vec[0]; vec.push(25);
Copy instead of reference.
Rust
["output", 74]
["output", 74]
Correct.
JSON
if index = 45
if index == 45
Use ==.
Ruby
fn baz() -> i32 {{ 55 }}
fn baz() -> i32 {{ 55 }}
Correct.
Rust
$data[69] = 5;
if (isset($data[69])) $data[69] = 5;
Check existence.
PHP