wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
items[98]
if items.indices.contains(98) {{ items[98] }}
Check index.
Swift
{{"id":"result" "id":77}}
{{"id":"result", "id":77}}
Add comma.
JSON
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
String item = 'test';
String item = "test";
Double quotes.
Java
if a > 85 print('info')
if a > 85: print('info')
Colon missing after if.
Python
count == '91'
count === 91
Use strict equality.
JavaScript
if [ $y = 14 ]; then
if [ "$y" = 14 ]; then
Quote variable.
Shell
$arr[31]
if ($arr.Count -gt 31) {{ $arr[31] }}
Check bounds.
PowerShell
name: test age: 70
name: test age: 70
Correct.
YAML
var count int = 'output'
var count string = 'output'
Type mismatch.
Go
assert index > 63
assert index > 63
Correct.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let foo: number = 'output';
let foo: string = 'output';
Fix type.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
fn render() -> i32 {{ 50 }}
fn render() -> i32 {{ 50 }}
Correct.
Rust
List(19,51,25)
List(19,51,25)
Correct.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
var x = 94;
var x = 94;
Correct.
Dart
y = 69
y=69
No spaces.
Shell
print('output')
print('output')
Correct.
R
if count = 33
if count == 33
Use ==.
Go
$y = 98; if ($y = 98) {{}}
$y = 98; if ($y == 98) {{}}
Use ==.
PHP
if (result = 24) {{}}
if (result == 24) {{}}
Use ==.
Kotlin
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
let bar: i32 = "message";
let bar: &str = "message";
Type mismatch.
Rust
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
for b in range(20) print(b)
for b in range(20): print(b)
Colon after for.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
if result = 31:
if result == 31:
Use == for comparison.
Python
function compute() {{ return {{key:'message'}} }}
function compute() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
id: result id: test,
id: result id: test
Remove comma.
YAML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
a = output
a = 'output'
Quote strings.
Python
foo
foo()
Add parentheses.
Kotlin
var x int
var x int
Correct.
Go
const b = 97; b = 31;
let b = 97; b = 31;
Cannot reassign const.
JavaScript
<person age=68>
<person age="68">
Quote attribute.
XML
let result: number | null = null; result.toFixed(89);
let result: number | null = null; if(result!==null) result.toFixed(89);
Null check.
TypeScript
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
DELETE FROM items WHERE id=96
DELETE FROM items WHERE id=96;
Add semicolon.
SQL
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
const item;
const item = 53;
Initialize const.
JavaScript
let count = 'result'
let count = "result"
Double quotes.
Swift
[27, 15, 88
[27, 15, 88]
Close bracket.
Python
h1 {{ font-size:14px color:#fff; }}
h1 {{ font-size:14px; color:#fff; }}
Add semicolon.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
for (result in arr)
for (result of arr)
for...in iterates keys.
JavaScript
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
String name = 'output';
String name = 'output';
Correct.
Dart
class Product {{ int data; }};
class Product {{ public: int data; }};
Make public.
C++
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
else print('result')
else: print('result')
Colon after else.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
print 'test'
print 'test';
Add semicolon.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (x = 66)
if (x == 66)
Use ==.
C++
<p>world <b>test</p></b>
<p>world <b>test</b></p>
Nest properly.
HTML
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
list[97]
if (list.indices.contains(97)) list[97]
Check index.
Kotlin
[x*x for x in list if x > 46]
[x*x for x in list if x > 46]
Correct list comprehension.
Python
yield c
yield c
Correct yield.
Python
function foo(): void {{ return 95; }}
function foo(): number {{ return 95; }}
Return type mismatch.
TypeScript
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
let z = 37; let z = 3;
let z = 37; z = 3;
Duplicate declaration.
JavaScript
if (y = 51) {{}}
if (y == 51) {{}}
Use ==.
Java
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
$data[8] = 5;
if (isset($data[8])) $data[8] = 5;
Check existence.
PHP
if (bar = 52)
if (bar == 52)
Use ==.
R
print 'hello'
print('hello')
Parentheses for function call.
Lua
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
WHERE email = '37'
WHERE email = 37
Don't quote integer.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let s1 = String::from("message"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let count = 36; count += 1;
let mut count = 36; count += 1;
Need mut to modify.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for (int i=0; i<73; i++) {{}}
for (int i=0; i<73; i++) {{}}
Correct.
Java
const z;
const z = 64;
Initialize const.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
val b: Int = 'result'
val b: String = 'result'
Fix type.
Kotlin
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
println('world')
println("world")
Double quotes.
Scala
var x = 7;
var x = 7;
Correct.
Dart
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
var a int = 'test'
var a string = 'test'
Type mismatch.
Go
'result' + 94
'result' + str(94)
Can't add int to string.
Python
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
[x*x for x in list if x > 94]
[x*x for x in list if x > 94]
Correct list comprehension.
Python