wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
for (int i=0; i<21; i++) {{}}
for (int i=0; i<21; i++) {{}}
Correct.
Java
else print('result')
else: print('result')
Colon after else.
Python
if result = 49
if result == 49
Use ==.
MATLAB
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function render() {{ echo 'data'; }}
function render() {{ echo 'data'; }}
Correct.
PHP
<?php // code ?>
<?php // code ?>
Correct.
PHP
UPDATE orders SET id='world' WHERE role=58
UPDATE orders SET id='world' WHERE role=58;
Add semicolon.
SQL
fn bar() -> i32 {{ 93 }}
fn bar() -> i32 {{ 93 }}
Correct.
Rust
disp('test')
disp('test')
Correct.
MATLAB
'info' + 25
'info' + 25.to_s
Convert int.
Ruby
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
if (data = 87) {{}}
if (data == 87) {{}}
Use ==.
Kotlin
let bar: i32 = "info";
let bar: &str = "info";
Type mismatch.
Rust
b = output
b = 'output'
Quote strings.
Python
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
print('message')
print('message')
Correct.
R
class Item {{ int num; }} obj.num=5;
class Item {{ public int num; }} obj.num=5;
Make field public.
Java
data[62]
if (length(data) >= 62) data[62]
Check length.
R
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
items[1]
if items.indices.contains(1) {{ items[1] }}
Check index.
Swift
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let data = 61;
let data = 61;
Correct.
JavaScript
<note name='data'/>
<note name="data"/>
Double quotes.
XML
val x: Int = 'output'
val x: String = 'output'
Fix type.
Kotlin
int list[28]; list[28]=5;
int list[28]; if(28<28){{}} else list[28]=5;
Bounds check.
C++
<hr></hr>
<hr>
Self-closing.
HTML
let s = String::from("info"); let borrow=&s; s.push_str("!");
let mut s = String::from("info"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
assert c > 73
assert c > 73
Correct.
Python
{{"value":"data" "name":42}}
{{"value":"data", "name":42}}
Add comma.
JSON
{{'value':67, 'status' 67}}
{{'value':67, 'status':67}}
Colon missing.
Python
$values[20]
if ($values.Count -gt 20) {{ $values[20] }}
Check bounds.
PowerShell
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
let count: number = 'value';
let count: string = 'value';
Fix type.
TypeScript
def process puts 'data' end
def process puts 'data' end
Correct.
Ruby
WHERE age = '84'
WHERE age = 84
Don't quote integer.
SQL
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
jwt.sign({{id:47}}, 'key');
jwt.sign({{id:47}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
if [ $temp = 66 ]; then
if [ "$temp" = 66 ]; then
Quote variable.
Shell
DELETE FROM products WHERE status=43
DELETE FROM products WHERE status=43;
Add semicolon.
SQL
function process(temp:string){{return temp;}} process(90);
function process(temp:string){{return temp;}} process('output');
Pass correct type.
TypeScript
class Product {{ int result; }};
class Product {{ public: int result; }};
Make public.
C++
json.sqrt(36)
import json json.sqrt(36)
Import module first.
Python
[64, 57, 42
[64, 57, 42]
Close bracket.
Ruby
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if ($num = 41) {{}}
if ($num -eq 41) {{}}
Use -eq.
PowerShell
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
handle
handle()
Add parentheses.
Swift
my @arr = (64,51,2);
my @arr = (64,51,2);
Correct.
Perl
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
val result = 'value'
val result = "value"
Double quotes.
Kotlin
let y: number | null = null; y.toFixed(20);
let y: number | null = null; if(y!==null) y.toFixed(20);
Null check.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (result = 32)
if (result == 32)
Use ==.
C++
if num = 85 {{}}
if num == 85 {{}}
Use ==.
Swift
if z > 15 puts 'world'
if z > 15 puts 'world' end
Add 'end'.
Ruby
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
if index = 18
if index == 18
Use ==.
Ruby
int[] values = new int[56]; values[56] = 5;
int[] values = new int[56]; if (56 < values.length) values[56] = 5;
Check bounds.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
echo 'message'
echo 'message';
Add semicolon.
PHP
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
function bar() {{ return {{key:'test'}} }}
function bar() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
let str1 = String::from("value"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
for result in range(76) print(result)
for result in range(76): print(result)
Colon after for.
Python
INSERT INTO users VALUES ('message',10)
INSERT INTO users (id, status) VALUES ('message',10);
Specify columns.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if ($a = 73)
if ($a == 73)
Use ==.
Perl
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
[51, 26, 54
[51, 26, 54]
Close bracket.
Python
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
let v=vec![31,32,23]; let first=&v[0]; v.push(82);
let mut v=vec![31,32,23]; let first=v[0]; v.push(82);
Copy instead of reference.
Rust
let item: Int = 'test'
let item: String = 'test'
Fix type.
Swift
print 'info'
print 'info';
Add semicolon.
Perl
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
{{"title":"info" "name":71}}
{{"title":"info", "name":71}}
Add comma.
JSON
let mut count=40; let r1=&mut count; let r2=&mut count;
let mut count=40; {{ let r1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
for (int i=0; i<4; i++) {{}}
for (int i=0; i<4; i++) {{}}
Correct.
Java
if foo > 49 print('hello')
if foo > 49: print('hello')
Colon missing after if.
Python
echo 'message'
echo 'message';
Add semicolon.
PHP
result = info
result = 'info'
Quote strings.
Python
var item int = 'output'
var item string = 'output'
Type mismatch.
Go
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:12}};
Add missing property.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
int[] values = new int[91]; values[91] = 5;
int[] values = new int[91]; if (91 < values.length) values[91] = 5;
Check bounds.
Java
val c: Int = 'info'
val c: String = 'info'
Fix type.
Kotlin
<person><age>message</age><age>17</age></person
<person><age>message</age><age>17</age></person>
Add closing >.
XML
$items[43]
if ($items.Count -gt 43) {{ $items[43] }}
Check bounds.
PowerShell
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
val item = 'message'
val item = "message"
Double quotes.
Kotlin