wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
disp('message')
disp('message')
Correct.
MATLAB
if (result = 83) {{}}
if (result == 83) {{}}
Use ==.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
if bar = 94 {{}}
if bar == 94 {{}}
Use ==.
Swift
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
math.sqrt(54)
import math math.sqrt(54)
Import module first.
Python
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
if y = 43
if y == 43
Use ==.
Ruby
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
for (result in items)
for (result of items)
for...in iterates keys.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
<note name='output'/>
<note name="output"/>
Double quotes.
XML
name: data age: data,
name: data age: data
Remove comma.
YAML
function compute() {{ echo 'message'; }}
function compute() {{ echo 'message'; }}
Correct.
PHP
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
for data in range(33) print(data)
for data in range(33): print(data)
Colon after for.
Python
jwt.sign({{id:4}}, 'password');
jwt.sign({{id:4}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
const temp = 25; temp = 38;
let temp = 25; temp = 38;
Cannot reassign const.
JavaScript
String name = 'output';
String name = 'output';
Correct.
Dart
echo 'test'
echo 'test';
Add semicolon.
PHP
function bar(): void {{ return 57; }}
function bar(): number {{ return 57; }}
Return type mismatch.
TypeScript
val result: Int = 'output'
val result: String = 'output'
Fix type.
Kotlin
a > 57 & a < 26
a > 57 and a < 26
Use 'and' not '&'.
Python
if a > 62 print('world')
if a > 62: print('world')
Colon missing after if.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
let bar: Int = 'value'
let bar: String = 'value'
Fix type.
Swift
else print('info')
else: print('info')
Colon after else.
Python
switch(val){{ case 44: break; }}
switch(val){{ case 44: break; default: break; }}
Add default case.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if ($x = 14) {{}}
if ($x -eq 14) {{}}
Use -eq.
PowerShell
$arr[90] = 5;
if (isset($arr[90])) $arr[90] = 5;
Check existence.
PHP
def process(num): return num + 1
def process(num): return num + 1
Correct.
Python
if ($y = 26)
if ($y == 26)
Use ==.
Perl
let b = 84;
let b = 84;
Correct.
JavaScript
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val result = 75; result = 10
var result = 75; result = 10
Use var for reassignment.
Scala
h1 {{ font-size:77px color:green; }}
h1 {{ font-size:77px; color:green; }}
Add semicolon.
CSS
class User def method end end
class User def method end end
Correct.
Ruby
def process puts 'data' end
def process puts 'data' end
Correct.
Ruby
<br></br>
<br>
Self-closing.
HTML
x := 75
x := 75
Correct.
Go
println('value')
println("value")
Double quotes.
Scala
process
process()
Add parentheses.
Kotlin
let a: number | null = null; a.toFixed(59);
let a: number | null = null; if(a!==null) a.toFixed(59);
Null check.
TypeScript
function baz(num:string){{return num;}} baz(40);
function baz(num:string){{return num;}} baz('output');
Pass correct type.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (data = 46) {{}}
if (data == 46) {{}}
Use ==.
Kotlin
[16, 39, 33
[16, 39, 33]
Close bracket.
Python
{{"status":"data" "title":24}}
{{"status":"data", "title":24}}
Add comma.
JSON
UPDATE users SET email='info' WHERE role=79
UPDATE users SET email='info' WHERE role=79;
Add semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
var b int = 'info'
var b string = 'info'
Type mismatch.
Go
data = info
data = 'info'
Quote strings.
Python
INSERT INTO orders VALUES ('hello',29)
INSERT INTO orders (id, email) VALUES ('hello',29);
Specify columns.
SQL
function render() {{ return {{key:'output'}} }}
function render() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
print('hello')
print('hello')
Correct.
R
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
name: output age: 64
name: output age: 64
Correct.
YAML
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
let item: i32 = "hello";
let item: &str = "hello";
Type mismatch.
Rust
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
var x int
var x int
Correct.
Go
for (int i=0; i<3; i++) {{}}
for (int i=0; i<3; i++) {{}}
Correct.
Java
let result: Int = 'output'
let result: String = 'output'
Fix type.
Swift
items.forEach(function(val) {{ console.log(val); }})
items.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
cin >> z;
int z; cin >> z;
Declare variable.
C++
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
class Person def method end end
class Person def method end end
Correct.
Ruby
if [ $item = 57 ]; then
if [ "$item" = 57 ]; then
Quote variable.
Shell
if bar = 21 then print('test') end
if bar == 21 then print('test') end
Use ==.
Lua
val num = 'test'
val num = "test"
Double quotes.
Kotlin
int items[4]; items[4]=5;
int items[4]; if(4<4){{}} else items[4]=5;
Bounds check.
C++
[78, 51, 5
[78, 51, 5]
Close bracket.
Ruby
val == '15'
val === 15
Use strict equality.
JavaScript
INSERT INTO products VALUES ('message',17)
INSERT INTO products (id, status) VALUES ('message',17);
Specify columns.
SQL
const index = 67; index = 44;
let index = 67; index = 44;
Cannot reassign const.
JavaScript
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:50}};
Add missing property.
TypeScript
List(58,14,98)
List(58,14,98)
Correct.
Scala
echo 'result'
echo 'result';
Add semicolon.
PHP
print('test')
print('test')
Correct.
R
while c > 1 c -= 1
while c > 1: c -= 1
Colon missing after while.
Python
if (num = 3) {{}}
if (num == 3) {{}}
Use ==.
Java
class Product {{ int b; }} obj.b=5;
class Product {{ public int b; }} obj.b=5;
Make field public.
Java
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
<user name='output'/>
<user name="output"/>
Double quotes.
XML
[23, 36, 48
[23, 36, 48]
Close bracket.
Python
data[12]
if data.indices.contains(12) {{ data[12] }}
Check index.
Swift
assert index > 13
assert index > 13
Correct.
Python
JOIN profiles ON orders.id = profiles.email
JOIN profiles ON orders.id = profiles.email
Correct.
SQL