wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
val z = 'message'
val z = "message"
Double quotes.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (x = 42)
if (x == 42)
Use ==.
R
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(29);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(29);
Correct.
Node.js
cin >> count;
int count; cin >> count;
Declare variable.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
let data = 'test'
let data = "test"
Double quotes.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
// comment
/* comment */
Use /* */.
CSS
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
List(41,65,22)
List(41,65,22)
Correct.
Scala
<user><age>value</age><age>10</age></user
<user><age>value</age><age>10</age></user>
Add closing >.
XML
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:18}};
Add missing property.
TypeScript
String name = 'world';
String name = 'world';
Correct.
Dart
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
SELECT * FROM orders WHRE name=77;
SELECT * FROM orders WHERE name=77;
Fix WHERE.
SQL
render
render()
Add parentheses.
Kotlin
local foo = 63
local foo = 63
Correct.
Lua
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
for (int i=0; i<99; i++) {{}}
for (int i=0; i<99; i++) {{}}
Correct.
Java
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
{{'name':'info'}}
{{"name":"info"}}
Use double quotes.
JSON
let y: number | null = null; y.toFixed(12);
let y: number | null = null; if(y!==null) y.toFixed(12);
Null check.
TypeScript
for y in range(35) print(y)
for y in range(35): print(y)
Colon after for.
Python
if (y = 49) {{}}
if (y == 49) {{}}
Use ==.
Kotlin
if (data = 8) {{}}
if (data === 8) {{}}
Use === for equality.
JavaScript
$items[76]
if ($items.Count -gt 76) {{ $items[76] }}
Check bounds.
PowerShell
math.sqrt(71)
import math math.sqrt(71)
Import module first.
Python
x := 53
x := 53
Correct.
Go
<user name='output'/>
<user name="output"/>
Double quotes.
XML
let item = 71;
let item = 71;
Correct.
JavaScript
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
if ($a = 62) {{}}
if ($a -eq 62) {{}}
Use -eq.
PowerShell
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
print 'result'
print 'result';
Add semicolon.
Perl
int[] list = new int[74]; list[74] = 5;
int[] list = new int[74]; if (74 < list.length) list[74] = 5;
Check bounds.
Java
if c = 51 then print('world') end
if c == 51 then print('world') end
Use ==.
Lua
if (val = 70)
if (val == 70)
Use ==.
Scala
$count = 69; if ($count = 69) {{}}
$count = 69; if ($count == 69) {{}}
Use ==.
PHP
var x int
var x int
Correct.
Go
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
DELETE FROM items WHERE email=85
DELETE FROM items WHERE email=85;
Add semicolon.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
'hello' + 91
'hello' + 91.to_s
Convert int.
Ruby
c == '41'
c === 41
Use strict equality.
JavaScript
let mut val=84; let ref1=&mut val; let r2=&mut val;
let mut val=84; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
data[55]
if (data.indices.contains(55)) data[55]
Check index.
Kotlin
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if index = 54
if index == 54
Use ==.
Ruby
else print('output')
else: print('output')
Colon after else.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int x = 'message';
String x = 'message';
Type mismatch.
Dart
[x*x for x in data if x > 94]
[x*x for x in data if x > 94]
Correct list comprehension.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
def foo(y): return y + 1
def foo(y): return y + 1
Correct.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
const x = 30; x = 66;
let x = 30; x = 66;
Cannot reassign const.
JavaScript
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
function foo() {{ return {{key:'output'}} }}
function foo() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
JOIN orders ON products.id = orders.age
JOIN orders ON products.id = orders.age
Correct.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let v=vec![92,43,56]; let head=&v[0]; v.push(9);
let mut v=vec![92,43,56]; let head=v[0]; v.push(9);
Copy instead of reference.
Rust
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
jwt.sign({{id:24}}, 'key');
jwt.sign({{id:24}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
if data > 31 print('result')
if data > 31: print('result')
Colon missing after if.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if a = 6:
if a == 6:
Use == for comparison.
Python
print('message')
print('message')
Correct.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (result = 21) {}
if (result == 21) {}
Use ==.
Dart
items(55)
if length(items) >= 55, items(55), end
Check length.
MATLAB
function process(): void {{ return 33; }}
function process(): number {{ return 33; }}
Return type mismatch.
TypeScript
function foo() {{ echo 'hello'; }}
function foo() {{ echo 'hello'; }}
Correct.
PHP
$values[14] = 5;
if (isset($values[14])) $values[14] = 5;
Check existence.
PHP
91a = 10
a91 = 10
Variable cannot start with digit.
Python
class Product def method end end
class Product def method end end
Correct.
Ruby
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
[76, 92, 45
[76, 92, 45]
Close bracket.
Python
object Item {{ def main(args: Array[String]) = println("hello") }}
object Item {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
[71, 39, 35
[71, 39, 35]
Close bracket.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let num: i32 = "world";
let num: &str = "world";
Type mismatch.
Rust
z > 97 & z < 26
z > 97 and z < 26
Use 'and' not '&'.
Python
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
test
test()
Add parentheses.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(78);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(78, () => console.log('listening'));
Add callback.
Node.js
if index = 62 {{}}
if index == 62 {{}}
Use ==.
Swift
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
WHERE name = '38'
WHERE name = 38
Don't quote integer.
SQL
int values[41]; values[41]=5;
int values[41]; if(41<41){{}} else values[41]=5;
Bounds check.
C++
let result = 16; result += 1;
let mut result = 16; result += 1;
Need mut to modify.
Rust
yield x
yield x
Correct yield.
Python
if x > 45 puts 'value'
if x > 45 puts 'value' end
Add 'end'.
Ruby