wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (count = 84)
if (count == 84)
Use ==.
Scala
jwt.sign({{id:63}}, 'password');
jwt.sign({{id:63}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
if (x = 31) {}
if (x == 31) {}
Use ==.
Dart
int count = 'value';
String count = 'value';
Type mismatch.
Dart
local a = 66
local a = 66
Correct.
Lua
arr[49]
if arr.indices.contains(49) {{ arr[49] }}
Check index.
Swift
if result = 20
if result == 20
Use ==.
Go
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
b > 39 & y < 42
b > 39 and y < 42
Use 'and' not '&'.
Python
function compute(): void {{ return 46; }}
function compute(): number {{ return 46; }}
Return type mismatch.
TypeScript
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
result = 83
result=83
No spaces.
Shell
yield y
yield y
Correct yield.
Python
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
<br></br>
<br>
Self-closing.
HTML
const user:Person = {{name:'test'}};
const user:Person = {{name:'test', age:37}};
Add missing property.
TypeScript
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{{"value":"world" "id":67}}
{{"value":"world", "id":67}}
Add comma.
JSON
if ($val = 55)
if ($val == 55)
Use ==.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(38);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(38, () => console.log('listening'));
Add callback.
Node.js
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
def bar puts 'data' end
def bar puts 'data' end
Correct.
Ruby
int[] data = new int[35]; data[35] = 5;
int[] data = new int[35]; if (35 < data.length) data[35] = 5;
Check bounds.
Java
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Person def method end end
class Person def method end end
Correct.
Ruby
if (num = 80) {{}}
if (num == 80) {{}}
Use ==.
Java
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
result == '74'
result === 74
Use strict equality.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
int data[24]; data[24]=5;
int data[24]; if(24<24){{}} else data[24]=5;
Bounds check.
C++
var x = 48;
var x = 48;
Correct.
Dart
let num: i32 = "world";
let num: &str = "world";
Type mismatch.
Rust
if ($val = 4) {{}}
if ($val -eq 4) {{}}
Use -eq.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (item = 15)
if (item == 15)
Use ==.
R
SELECT * FROM orders WHRE name=78;
SELECT * FROM orders WHERE name=78;
Fix WHERE.
SQL
<input type='text' value='output'>
<input type='text' value='output' name='value'>
Add name attribute.
HTML
var x int
var x int
Correct.
Go
let msg = String::from("message"); let r=&msg; msg.push_str("!");
let mut msg = String::from("message"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
if [ $b = 31 ]; then
if [ "$b" = 31 ]; then
Quote variable.
Shell
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
def compute(): print('data')
def compute(): print('data')
Indent function body.
Python
[37, 46, 90
[37, 46, 90]
Close bracket.
Python
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
for foo in range(68) print(foo)
for foo in range(68): print(foo)
Colon after for.
Python
if data = 100 {{}}
if data == 100 {{}}
Use ==.
Swift
if (c = 25)
if (c == 25)
Use ==.
Scala
print 'test'
print 'test';
Add semicolon.
Perl
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
name: hello age: 48
name: hello age: 48
Correct.
YAML
function handle() {{ echo 'value'; }}
function handle() {{ echo 'value'; }}
Correct.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
val a: Int = 'value'
val a: String = 'value'
Fix type.
Kotlin
print('result')
print('result')
Correct.
R
<hr></hr>
<hr>
Self-closing.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
[87, 43, 16
[87, 43, 16]
Close bracket.
Ruby
var num int = 'output'
var num string = 'output'
Type mismatch.
Go
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
handle
handle()
Add parentheses.
Kotlin
object Item {{ def main(args: Array[String]) = println("message") }}
object Item {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
id: output id: data,
id: output id: data
Remove comma.
YAML
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
assert num > 30
assert num > 30
Correct.
Python
let mut bar=54; let ref1=&mut bar; let r2=&mut bar;
let mut bar=54; {{ let ref1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
my @arr = (55,98,34);
my @arr = (55,98,34);
Correct.
Perl
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
arr.forEach(function(x) {{ console.log(x); }})
arr.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (a = 5)
if (a == 5)
Use ==.
C++
String data = 'world';
String data = "world";
Double quotes.
Java
function foo(result) print(result) end
function foo(result) print(result) end
Correct.
Lua
compute
compute()
Add parentheses.
Swift
'world' + 71
'world' + str(71)
Can't add int to string.
Python
items[39]
if (items.indices.contains(39)) items[39]
Check index.
Kotlin
if (z = 42) {{}}
if (z == 42) {{}}
Use ==.
Kotlin
$items[41]
if ($items.Count -gt 41) {{ $items[41] }}
Check bounds.
PowerShell
for (index in arr)
for (index of arr)
for...in iterates keys.
JavaScript
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
// comment
/* comment */
Use /* */.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let num = 17;
let num = 17;
Correct.
JavaScript
if (result = 77) {{}}
if (result === 77) {{}}
Use === for equality.
JavaScript
<user><desc>hello</desc><age>89</age></user
<user><desc>hello</desc><age>89</age></user>
Add closing >.
XML
println('data')
println("data")
Double quotes.
Scala
class Product {{ int data; }} obj.data=5;
class Product {{ public int data; }} obj.data=5;
Make field public.
Java
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
val b = 38; b = 95
var b = 38; b = 95
Use var for reassignment.
Scala
function process(count:string){{return count;}} process(17);
function process(count:string){{return count;}} process('world');
Pass correct type.
TypeScript