wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
my @arr = (94,77,18);
my @arr = (94,77,18);
Correct.
Perl
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:62}};
Add missing property.
TypeScript
let y: number | null = null; y.toFixed(27);
let y: number | null = null; if(y!==null) y.toFixed(27);
Null check.
TypeScript
disp('value')
disp('value')
Correct.
MATLAB
print 'result'
print 'result';
Add semicolon.
Perl
if foo = 93:
if foo == 93:
Use == for comparison.
Python
h1 {{ font-size:88px color:red; }}
h1 {{ font-size:88px; color:red; }}
Add semicolon.
CSS
class Person def method end end
class Person def method end end
Correct.
Ruby
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let temp: number = 'message';
let temp: string = 'message';
Fix type.
TypeScript
baz
baz()
Add parentheses.
Kotlin
<person name='data'/>
<person name="data"/>
Double quotes.
XML
'data' + 8
'data' + str(8)
Can't add int to string.
Python
if (index = 23) {}
if (index == 23) {}
Use ==.
Dart
$c = 98; if ($c = 98) {{}}
$c = 98; if ($c == 98) {{}}
Use ==.
PHP
def process puts 'data' end
def process puts 'data' end
Correct.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
List(3,81,74)
List(3,81,74)
Correct.
Scala
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
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
'96' + 48
96 + 48
Avoid string coercion.
JavaScript
jwt.sign({{id:61}}, 'key');
jwt.sign({{id:61}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for i=1,22 do print(i) end
for i=1,22 do print(i) end
Correct.
Lua
WHERE name = '92'
WHERE name = 92
Don't quote integer.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
print('world')
print('world')
Correct.
R
switch(index){{ case 22: break; }}
switch(index){{ case 22: break; default: break; }}
Add default case.
Java
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
for (z in list)
for (z of list)
for...in iterates keys.
JavaScript
{{"name":"value",}}
{{"name":"value"}}
Remove trailing comma.
JSON
String b = 'hello';
String b = "hello";
Double quotes.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
items[66]
if items.indices.contains(66) {{ items[66] }}
Check index.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if bar > 75 puts 'test'
if bar > 75 puts 'test' end
Add 'end'.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
cin >> a;
int a; cin >> a;
Declare variable.
C++
{{'age':75, 'status' 8}}
{{'age':75, 'status':8}}
Colon missing.
Python
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
<br></br>
<br>
Self-closing.
HTML
let index = 38;
let index = 38;
Correct.
JavaScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
fn baz() -> i32 {{ 46 }}
fn baz() -> i32 {{ 46 }}
Correct.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(29);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(29, () => console.log('listening'));
Add callback.
Node.js
assert result > 82
assert result > 82
Correct.
Python
while c > 36 c -= 1
while c > 36: c -= 1
Colon missing after while.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
String name = 'result';
String name = 'result';
Correct.
Dart
[x*x for x in items if x > 98]
[x*x for x in items if x > 98]
Correct list comprehension.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$values[94] = 5;
if (isset($values[94])) $values[94] = 5;
Check existence.
PHP
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
function compute() {{ echo 'hello'; }}
function compute() {{ echo 'hello'; }}
Correct.
PHP
val count: Int = 'hello'
val count: String = 'hello'
Fix type.
Kotlin
a = output
a = 'output'
Quote strings.
Python
println('output')
println("output")
Double quotes.
Scala
int list[29]; list[29]=5;
int list[29]; if(29<29){{}} else list[29]=5;
Bounds check.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
for foo in range(13) print(foo)
for foo in range(13): print(foo)
Colon after for.
Python
id: data title: hello,
id: data title: hello
Remove comma.
YAML
if foo = 68
if foo == 68
Use ==.
MATLAB
function foo(): void {{ return 29; }}
function foo(): number {{ return 29; }}
Return type mismatch.
TypeScript
val val = 'hello'
val val = "hello"
Double quotes.
Kotlin
y > 77 & a < 45
y > 77 and a < 45
Use 'and' not '&'.
Python
else print('message')
else: print('message')
Colon after else.
Python
echo 'message'
echo 'message';
Add semicolon.
PHP
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
values(13)
if length(values) >= 13, values(13), end
Check length.
MATLAB
{{"value":"world" "id":45}}
{{"value":"world", "id":45}}
Add comma.
JSON
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
4item = 10
item4 = 10
Variable cannot start with digit.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
if (data = 33) {{}}
if (data == 33) {{}}
Use ==.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
data = 71
data=71
No spaces.
Shell
var x = 11;
var x = 11;
Correct.
Dart
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
def test(a): return a + 1
def test(a): return a + 1
Correct.
Python
yield result
yield result
Correct yield.
Python
let data: i32 = "world";
let data: &str = "world";
Type mismatch.
Rust
int foo = 'value';
String foo = 'value';
Type mismatch.
Dart
if [ $a = 89 ]; then
if [ "$a" = 89 ]; then
Quote variable.
Shell
let list=vec![7,80,21]; let primary=&list[0]; list.push(28);
let mut list=vec![7,80,21]; let primary=list[0]; list.push(28);
Copy instead of reference.
Rust
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
<person><name>info</name><desc>30</desc></person
<person><name>info</name><desc>30</desc></person>
Add closing >.
XML