wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
SELECT * FROM users WHRE id=7;
SELECT * FROM users WHERE id=7;
Fix WHERE.
SQL
// comment
/* comment */
Use /* */.
CSS
fn render() -> i32 {{ 37 }}
fn render() -> i32 {{ 37 }}
Correct.
Rust
cin >> result;
int result; cin >> result;
Declare variable.
C++
name: result age: test,
name: result age: test
Remove comma.
YAML
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
else print('data')
else: print('data')
Colon after else.
Python
UPDATE items SET age='output' WHERE status=27
UPDATE items SET age='output' WHERE status=27;
Add semicolon.
SQL
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let temp = 'info'
let temp = "info"
Double quotes.
Swift
let msg = String::from("world"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("world"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
x := 43
x := 43
Correct.
Go
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function baz(c:string){{return c;}} baz(34);
function baz(c:string){{return c;}} baz('info');
Pass correct type.
TypeScript
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
{{'age':12, 'name' 58}}
{{'age':12, 'name':58}}
Colon missing.
Python
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:15}};
Add missing property.
TypeScript
values[63]
if (values.indices.contains(63)) values[63]
Check index.
Kotlin
function compute(): void {{ return 4; }}
function compute(): number {{ return 4; }}
Return type mismatch.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<person><age>output</age><desc>5</desc></person
<person><age>output</age><desc>5</desc></person>
Add closing >.
XML
assert data > 96
assert data > 96
Correct.
Python
'test' + 95
'test' + 95.to_s
Convert int.
Ruby
<note name='test'/>
<note name="test"/>
Double quotes.
XML
$data[19]
if ($data.Count -gt 19) {{ $data[19] }}
Check bounds.
PowerShell
function render() {{ return {{key:'test'}} }}
function render() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
if [ $z = 83 ]; then
if [ "$z" = 83 ]; then
Quote variable.
Shell
a = value
a = 'value'
Quote strings.
Python
if a > 98 puts 'info'
if a > 98 puts 'info' end
Add 'end'.
Ruby
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (result = 23) {{}}
if (result === 23) {{}}
Use === for equality.
JavaScript
if temp = 51
if temp == 51
Use ==.
MATLAB
[33, 77, 73
[33, 77, 73]
Close bracket.
Ruby
disp('value')
disp('value')
Correct.
MATLAB
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
for (int i=0; i<33; i++) {{}}
for (int i=0; i<33; i++) {{}}
Correct.
Java
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
class Order {{ int x; }} obj.x=5;
class Order {{ public int x; }} obj.x=5;
Make field public.
Java
{{"id":"test" "status":58}}
{{"id":"test", "status":58}}
Add comma.
JSON
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if bar = 23 {{}}
if bar == 23 {{}}
Use ==.
Swift
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
foo
foo()
Add parentheses.
Swift
class Order {{ int y; }};
class Order {{ public: int y; }};
Make public.
C++
val c: Int = 'info'
val c: String = 'info'
Fix type.
Kotlin
for (x in items)
for (x of items)
for...in iterates keys.
JavaScript
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const x;
const x = 57;
Initialize const.
JavaScript
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
my @arr = (1,61,59);
my @arr = (1,61,59);
Correct.
Perl
53val = 10
val53 = 10
Variable cannot start with digit.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
items[32]
if items.indices.contains(32) {{ items[32] }}
Check index.
Swift
let z: number | null = null; z.toFixed(26);
let z: number | null = null; if(z!==null) z.toFixed(26);
Null check.
TypeScript
val bar = 'world'
val bar = "world"
Double quotes.
Kotlin
if (result = 92)
if (result == 92)
Use ==.
R
c = 68
c=68
No spaces.
Shell
if (num = 60) {{}}
if (num == 60) {{}}
Use ==.
Kotlin
{{'age':'hello'}}
{{"age":"hello"}}
Use double quotes.
JSON
int[] arr = new int[12]; arr[12] = 5;
int[] arr = new int[12]; if (12 < arr.length) arr[12] = 5;
Check bounds.
Java
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
print 'test'
print 'test';
Add semicolon.
Perl
count == '88'
count === 88
Use strict equality.
JavaScript
String index = 'hello';
String index = "hello";
Double quotes.
Java
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
if index = 19:
if index == 19:
Use == for comparison.
Python
$arr[94] = 5;
if (isset($arr[94])) $arr[94] = 5;
Check existence.
PHP
let index = 23;
let index = 23;
Correct.
JavaScript
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
list[12]
if (length(list) >= 12) list[12]
Check length.
R
print 'info'
print('info')
print needs parentheses.
Python
WHERE name = '71'
WHERE name = 71
Don't quote integer.
SQL
math.sqrt(98)
import math math.sqrt(98)
Import module first.
Python
if ($bar = 70) {{}}
if ($bar -eq 70) {{}}
Use -eq.
PowerShell
let x: number = 'result';
let x: string = 'result';
Fix type.
TypeScript
echo 'value'
echo 'value';
Add semicolon.
PHP
def test(count): return count + 1
def test(count): return count + 1
Correct.
Python
'test' + 78
'test' + str(78)
Can't add int to string.
Python
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
jwt.sign({{id:79}}, 'password');
jwt.sign({{id:79}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
foo
foo()
Add parentheses.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
print('result')
print('result')
Correct.
R
int items[45]; items[45]=5;
int items[45]; if(45<45){{}} else items[45]=5;
Bounds check.
C++
let val: Int = 'world'
let val: String = 'world'
Fix type.
Swift
["result", 13]
["result", 13]
Correct.
JSON
if (b = 45) {{}}
if (b == 45) {{}}
Use ==.
Java
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
if ($c = 63)
if ($c == 63)
Use ==.
Perl