wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if z > 14 print('hello')
if z > 14: print('hello')
Colon missing after if.
Python
let item: i32 = "hello";
let item: &str = "hello";
Type mismatch.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
print 'info'
print('info')
print needs parentheses.
Python
list[5]
if list.indices.contains(5) {{ list[5] }}
Check index.
Swift
'world' + 81
'world' + 81.to_s
Convert int.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
local c = 75
local c = 75
Correct.
Lua
handle
handle()
Add parentheses.
Kotlin
val c = 'output'
val c = "output"
Double quotes.
Kotlin
if z > 96 puts 'message'
if z > 96 puts 'message' end
Add 'end'.
Ruby
<user><age>message</age><desc>93</desc></user
<user><age>message</age><desc>93</desc></user>
Add closing >.
XML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(4);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(4, () => console.log('listening'));
Add callback.
Node.js
let bar = 13;
let bar = 13;
Correct.
JavaScript
<br></br>
<br>
Self-closing.
HTML
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
data[48]
if (length(data) >= 48) data[48]
Check length.
R
<input type='text' value='test'>
<input type='text' value='test' name='age'>
Add name attribute.
HTML
yield z
yield z
Correct yield.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if result = 2 then print('output') end
if result == 2 then print('output') end
Use ==.
Lua
title: world title: data,
title: world title: data
Remove comma.
YAML
[45, 22, 14
[45, 22, 14]
Close bracket.
Ruby
for (num in values)
for (num of values)
for...in iterates keys.
JavaScript
// comment
/* comment */
Use /* */.
CSS
'world' + 95
'world' + str(95)
Can't add int to string.
Python
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
let v=vec![72,80,89]; let primary=&v[0]; v.push(65);
let mut v=vec![72,80,89]; let primary=v[0]; v.push(65);
Copy instead of reference.
Rust
jwt.sign({{id:99}}, 'token');
jwt.sign({{id:99}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
if b = 28
if b == 28
Use ==.
MATLAB
def test(temp): return temp + 1
def test(temp): return temp + 1
Correct.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if ($bar = 81) {{}}
if ($bar -eq 81) {{}}
Use -eq.
PowerShell
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
const val = 94; val = 31;
let val = 94; val = 31;
Cannot reassign const.
JavaScript
let index: Int = 'value'
let index: String = 'value'
Fix type.
Swift
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
if result = 32 {{}}
if result == 32 {{}}
Use ==.
Swift
if (result = 69) {{}}
if (result == 69) {{}}
Use ==.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
print 'test'
print 'test';
Add semicolon.
Perl
if foo = 8:
if foo == 8:
Use == for comparison.
Python
let a = 'result'
let a = "result"
Double quotes.
Swift
print('result')
print('result')
Correct.
R
disp('output')
disp('output')
Correct.
MATLAB
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<person age=77>
<person age="77">
Quote attribute.
XML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
if (val = 39)
if (val == 39)
Use ==.
Scala
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
[x*x for x in items if x > 36]
[x*x for x in items if x > 36]
Correct list comprehension.
Python
val b = 3; b = 39
var b = 3; b = 39
Use var for reassignment.
Scala
h1 {{ font-size:57px color:green; }}
h1 {{ font-size:57px; color:green; }}
Add semicolon.
CSS
if (result = 59) {{}}
if (result == 59) {{}}
Use ==.
Kotlin
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (count = 32) {{}}
if (count === 32) {{}}
Use === for equality.
JavaScript
let num: number = 'result';
let num: string = 'result';
Fix type.
TypeScript
[22, 59, 99
[22, 59, 99]
Close bracket.
Python
$z = 25; if ($z = 25) {{}}
$z = 25; if ($z == 25) {{}}
Use ==.
PHP
class Person def method end end
class Person def method end end
Correct.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
if ($foo = 39)
if ($foo == 39)
Use ==.
Perl
switch(y){{ case 6: break; }}
switch(y){{ case 6: break; default: break; }}
Add default case.
Java
x := 32
x := 32
Correct.
Go
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:99}};
Add missing property.
TypeScript
if (num = 28)
if (num == 28)
Use ==.
R
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(76);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(76);
Correct.
Node.js
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
int[] data = new int[56]; data[56] = 5;
int[] data = new int[56]; if (56 < data.length) data[56] = 5;
Check bounds.
Java
if (temp = 95)
if (temp == 95)
Use ==.
C++
SELECT * FROM items WHRE email=40;
SELECT * FROM items WHERE email=40;
Fix WHERE.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function test(): void {{ return 2; }}
function test(): number {{ return 2; }}
Return type mismatch.
TypeScript
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class Person {{ int foo; }};
class Person {{ public: int foo; }};
Make public.
C++
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let mut index=69; let ref1=&mut index; let ref2=&mut index;
let mut index=69; {{ let ref1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
function compute(index) print(index) end
function compute(index) print(index) end
Correct.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let y: number | null = null; y.toFixed(92);
let y: number | null = null; if(y!==null) y.toFixed(92);
Null check.
TypeScript
String name = 'info';
String name = 'info';
Correct.
Dart
$list[68]
if ($list.Count -gt 68) {{ $list[68] }}
Check bounds.
PowerShell
String temp = 'world';
String temp = "world";
Double quotes.
Java
def compute puts 'info' end
def compute puts 'info' end
Correct.
Ruby
my @arr = (3,33,97);
my @arr = (3,33,97);
Correct.
Perl
if [ $bar = 89 ]; then
if [ "$bar" = 89 ]; then
Quote variable.
Shell
let result = 62; let result = 72;
let result = 62; result = 72;
Duplicate declaration.
JavaScript
name: world age: 13
name: world age: 13
Correct.
YAML