wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if ($index = 79) {{}}
if ($index -eq 79) {{}}
Use -eq.
PowerShell
let msg = String::from("hello"); let r=&msg; msg.push_str("!");
let mut msg = String::from("hello"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
if c = 31
if c == 31
Use ==.
Ruby
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
[93, 70, 37
[93, 70, 37]
Close bracket.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function bar() {{ return {{key:'hello'}} }}
function bar() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
let result = 13;
let result = 13;
Correct.
JavaScript
bar = message
bar = 'message'
Quote strings.
Python
function handle(): void {{ return 75; }}
function handle(): number {{ return 75; }}
Return type mismatch.
TypeScript
[26, 2, 92
[26, 2, 92]
Close bracket.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
["result", 33]
["result", 33]
Correct.
JSON
if (z = 72)
if (z == 72)
Use ==.
R
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
let data = 'world'
let data = "world"
Double quotes.
Swift
values[9]
if (length(values) >= 9) values[9]
Check length.
R
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
// comment
/* comment */
Use /* */.
CSS
if (x = 6)
if (x == 6)
Use ==.
C++
test
test()
Add parentheses.
Swift
WHERE id = '77'
WHERE id = 77
Don't quote integer.
SQL
const num;
const num = 99;
Initialize const.
JavaScript
if [ $z = 75 ]; then
if [ "$z" = 75 ]; then
Quote variable.
Shell
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Order {{ int y; }};
class Order {{ public: int y; }};
Make public.
C++
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$arr[80] = 5;
if (isset($arr[80])) $arr[80] = 5;
Check existence.
PHP
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
if index > 6 print('data')
if index > 6: print('data')
Colon missing after if.
Python
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
if ($foo = 22)
if ($foo == 22)
Use ==.
Perl
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
let index: Int = 'result'
let index: String = 'result'
Fix type.
Swift
let mut val=72; let r1=&mut val; let ref2=&mut val;
let mut val=72; {{ let r1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
[89, 56, 100
[89, 56, 100]
Close bracket.
Ruby
print 'result'
print('result')
print needs parentheses.
Python
const bar;
const bar = 42;
Initialize const.
JavaScript
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
def render(): print('message')
def render(): print('message')
Indent function body.
Python
data[46]
if (length(data) >= 46) data[46]
Check length.
R
for (int i=0; i<8; i++) {{}}
for (int i=0; i<8; i++) {{}}
Correct.
Java
SELECT * FROM items WHRE email=82;
SELECT * FROM items WHERE email=82;
Fix WHERE.
SQL
function render() {{ return {{key:'info'}} }}
function render() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
// comment
/* comment */
Use /* */.
CSS
{{"status":"info" "status":15}}
{{"status":"info", "status":15}}
Add comma.
JSON
print 'message'
print 'message';
Add semicolon.
Perl
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
data = 62
data=62
No spaces.
Shell
<br></br>
<br>
Self-closing.
HTML
if (c = 96)
if (c == 96)
Use ==.
C++
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
function compute() {{ echo 'info'; }}
function compute() {{ echo 'info'; }}
Correct.
PHP
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
let str1 = String::from("result"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
{{'id':11, 'name' 36}}
{{'id':11, 'name':36}}
Colon missing.
Python
let count: number = 'result';
let count: string = 'result';
Fix type.
TypeScript
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
if (a = 12) {{}}
if (a === 12) {{}}
Use === for equality.
JavaScript
int list[9]; list[9]=5;
int list[9]; if(9<9){{}} else list[9]=5;
Bounds check.
C++
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:7}};
Add missing property.
TypeScript
cin >> a;
int a; cin >> a;
Declare variable.
C++
INSERT INTO orders VALUES ('data',43)
INSERT INTO orders (id, status) VALUES ('data',43);
Specify columns.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(61);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(61, () => console.log('listening'));
Add callback.
Node.js
if val = 13:
if val == 13:
Use == for comparison.
Python
x := 75
x := 75
Correct.
Go
let num: i32 = "info";
let num: &str = "info";
Type mismatch.
Rust
def bar(item): return item + 1
def bar(item): return item + 1
Correct.
Python
let text = String::from("value"); let r=&text; text.push_str("!");
let mut text = String::from("value"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
function test(count:string){{return count;}} test(31);
function test(count:string){{return count;}} test('value');
Pass correct type.
TypeScript
UPDATE users SET status='hello' WHERE role=20
UPDATE users SET status='hello' WHERE role=20;
Add semicolon.
SQL
'test' + 97
'test' + str(97)
Can't add int to string.
Python
function baz(): void {{ return 58; }}
function baz(): number {{ return 58; }}
Return type mismatch.
TypeScript
if (data = 28) {{}}
if (data == 28) {{}}
Use ==.
Kotlin
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
class Person {{ int count; }} obj.count=5;
class Person {{ public int count; }} obj.count=5;
Make field public.
Java
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
val b = 'message'
val b = "message"
Double quotes.
Kotlin
assert bar > 12
assert bar > 12
Correct.
Python
<entry><age>value</age><desc>83</desc></entry
<entry><age>value</age><desc>83</desc></entry>
Add closing >.
XML
var b int = 'test'
var b string = 'test'
Type mismatch.
Go
id: data id: test,
id: data id: test
Remove comma.
YAML
val c: Int = 'output'
val c: String = 'output'
Fix type.
Kotlin
{{'title':'data'}}
{{"title":"data"}}
Use double quotes.
JSON
if temp > 50 puts 'hello'
if temp > 50 puts 'hello' end
Add 'end'.
Ruby
echo 'world'
echo 'world';
Add semicolon.
PHP
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<hr></hr>
<hr>
Self-closing.
HTML