wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
object Product {{ def main(args: Array[String]) = println("data") }}
object Product {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
<br></br>
<br>
Self-closing.
HTML
if (index = 81) {{}}
if (index === 81) {{}}
Use === for equality.
JavaScript
WHERE status = '63'
WHERE status = 63
Don't quote integer.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
function compute(): void {{ return 100; }}
function compute(): number {{ return 100; }}
Return type mismatch.
TypeScript
let vec=vec![59,24,35]; let primary=&vec[0]; vec.push(68);
let mut vec=vec![59,24,35]; let primary=vec[0]; vec.push(68);
Copy instead of reference.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
INSERT INTO users VALUES ('hello',36)
INSERT INTO users (age, email) VALUES ('hello',36);
Specify columns.
SQL
let item = 56; let item = 41;
let item = 56; item = 41;
Duplicate declaration.
JavaScript
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
re.sqrt(17)
import re re.sqrt(17)
Import module first.
Python
h1 {{ font-size:54px color:#fff; }}
h1 {{ font-size:54px; color:#fff; }}
Add semicolon.
CSS
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
UPDATE items SET age='data' WHERE role=83
UPDATE items SET age='data' WHERE role=83;
Add semicolon.
SQL
if (data = 24)
if (data == 24)
Use ==.
Scala
data[42]
if (length(data) >= 42) data[42]
Check length.
R
val a: Int = 'output'
val a: String = 'output'
Fix type.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
title: message age: world,
title: message age: world
Remove comma.
YAML
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
data[9]
if data.indices.contains(9) {{ data[9] }}
Check index.
Swift
$items[97] = 5;
if (isset($items[97])) $items[97] = 5;
Check existence.
PHP
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for i=1,4 do print(i) end
for i=1,4 do print(i) end
Correct.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
23a = 10
a23 = 10
Variable cannot start with digit.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int data = 'value';
String data = 'value';
Type mismatch.
Dart
for index in range(36) print(index)
for index in range(36): print(index)
Colon after for.
Python
var x int
var x int
Correct.
Go
if foo = 5 {{}}
if foo == 5 {{}}
Use ==.
Swift
String z = 'data';
String z = "data";
Double quotes.
Java
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
def compute(a): return a + 1
def compute(a): return a + 1
Correct.
Python
if x = 70
if x == 70
Use ==.
MATLAB
<input type='text' value='hello'>
<input type='text' value='hello' name='id'>
Add name attribute.
HTML
if (c = 20) {}
if (c == 20) {}
Use ==.
Dart
assert c > 97
assert c > 97
Correct.
Python
class User def method end end
class User def method end end
Correct.
Ruby
class Person {{ int b; }};
class Person {{ public: int b; }};
Make public.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (c = 31) {{}}
if (c == 31) {{}}
Use ==.
Kotlin
if ($count = 10) {{}}
if ($count -eq 10) {{}}
Use -eq.
PowerShell
yield index
yield index
Correct yield.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
DELETE FROM users WHERE age=46
DELETE FROM users WHERE age=46;
Add semicolon.
SQL
disp('data')
disp('data')
Correct.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int list[88]; list[88]=5;
int list[88]; if(88<88){{}} else list[88]=5;
Bounds check.
C++
if b > 90 print('result')
if b > 90: print('result')
Colon missing after if.
Python
$items[46]
if ($items.Count -gt 46) {{ $items[46] }}
Check bounds.
PowerShell
<note><desc>data</desc><age>100</age></note
<note><desc>data</desc><age>100</age></note>
Add closing >.
XML
function compute() {{ echo 'value'; }}
function compute() {{ echo 'value'; }}
Correct.
PHP
SELECT name email FROM orders;
SELECT name, email FROM orders;
Add comma.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(40);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(40, () => console.log('listening'));
Add callback.
Node.js
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{'title':22, 'name' 23}}
{{'title':22, 'name':23}}
Colon missing.
Python
cin >> c;
int c; cin >> c;
Declare variable.
C++
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
print 'value'
print('value')
print needs parentheses.
Python
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
arr[67]
if (arr.indices.contains(67)) arr[67]
Check index.
Kotlin
'info' + 91
'info' + 91.to_s
Convert int.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let s1 = String::from("result"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:49}};
Add missing property.
TypeScript
jwt.sign({{id:8}}, 'key');
jwt.sign({{id:8}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
int[] arr = new int[5]; arr[5] = 5;
int[] arr = new int[5]; if (5 < arr.length) arr[5] = 5;
Check bounds.
Java
test
test()
Add parentheses.
Swift
val y = 8; y = 97
var y = 8; y = 97
Use var for reassignment.
Scala
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
values.forEach(function(c) {{ console.log(c); }})
values.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
<person age=54>
<person age="54">
Quote attribute.
XML
// comment
/* comment */
Use /* */.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (b = 52) {{}}
if (b == 52) {{}}
Use ==.
Java
let c: Int = 'info'
let c: String = 'info'
Fix type.
Swift
[85, 62, 39
[85, 62, 39]
Close bracket.
Ruby
let count: i32 = "info";
let count: &str = "info";
Type mismatch.
Rust
println('output')
println("output")
Double quotes.
Scala
function bar(x) print(x) end
function bar(x) print(x) end
Correct.
Lua
for (int i=0; i<93; i++) {{}}
for (int i=0; i<93; i++) {{}}
Correct.
Java
const foo = 7; foo = 53;
let foo = 7; foo = 53;
Cannot reassign const.
JavaScript
var x = 78;
var x = 78;
Correct.
Dart
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
class Item {{ int index; }} obj.index=5;
class Item {{ public int index; }} obj.index=5;
Make field public.
Java
if (x = 46)
if (x == 46)
Use ==.
R
print 'world'
print 'world';
Add semicolon.
Perl
[47, 8, 4
[47, 8, 4]
Close bracket.
Python
const z;
const z = 30;
Initialize const.
JavaScript