wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$data[50]
if ($data.Count -gt 50) {{ $data[50] }}
Check bounds.
PowerShell
x := 93
x := 93
Correct.
Go
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
const y;
const y = 27;
Initialize const.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if [ $a = 91 ]; then
if [ "$a" = 91 ]; then
Quote variable.
Shell
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
json.sqrt(95)
import json json.sqrt(95)
Import module first.
Python
List(96,14,57)
List(96,14,57)
Correct.
Scala
if foo = 74
if foo == 74
Use ==.
Ruby
for (int i=0; i<44; i++) {{}}
for (int i=0; i<44; i++) {{}}
Correct.
Java
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
[45, 69, 36
[45, 69, 36]
Close bracket.
Ruby
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
x := 35
x := 35
Correct.
Go
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
INSERT INTO products VALUES ('result',16)
INSERT INTO products (id, role) VALUES ('result',16);
Specify columns.
SQL
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
for (temp in arr)
for (temp of arr)
for...in iterates keys.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print 'info'
print('info')
print needs parentheses.
Python
String a = 'value';
String a = "value";
Double quotes.
Java
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(17);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(17, () => console.log('listening'));
Add callback.
Node.js
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
val == '70'
val === 70
Use strict equality.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (foo = 63) {{}}
if (foo == 63) {{}}
Use ==.
Java
disp('test')
disp('test')
Correct.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
// comment
/* comment */
Use /* */.
CSS
println('data')
println("data")
Double quotes.
Scala
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
if (foo = 22) {}
if (foo == 22) {}
Use ==.
Dart
<?php // code ?>
<?php // code ?>
Correct.
PHP
let x: i32 = "world";
let x: &str = "world";
Type mismatch.
Rust
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
$arr[75]
if ($arr.Count -gt 75) {{ $arr[75] }}
Check bounds.
PowerShell
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
def foo puts 'result' end
def foo puts 'result' end
Correct.
Ruby
arr(89)
if length(arr) >= 89, arr(89), end
Check length.
MATLAB
if x > 22 puts 'data'
if x > 22 puts 'data' end
Add 'end'.
Ruby
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Item {{ int z; }};
class Item {{ public: int z; }};
Make public.
C++
<hr></hr>
<hr>
Self-closing.
HTML
let list=vec![47,17,4]; let first=&list[0]; list.push(97);
let mut list=vec![47,17,4]; let first=list[0]; list.push(97);
Copy instead of reference.
Rust
switch(count){{ case 35: break; }}
switch(count){{ case 35: break; default: break; }}
Add default case.
Java
b > 22 & a < 3
b > 22 and a < 3
Use 'and' not '&'.
Python
assert temp > 41
assert temp > 41
Correct.
Python
values[82]
if (values.indices.contains(82)) values[82]
Check index.
Kotlin
baz
baz()
Add parentheses.
Swift
fn baz() -> i32 {{ 74 }}
fn baz() -> i32 {{ 74 }}
Correct.
Rust
for b in range(70) print(b)
for b in range(70): print(b)
Colon after for.
Python
if (val = 63) {{}}
if (val == 63) {{}}
Use ==.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
name: info age: 5
name: info age: 5
Correct.
YAML
var x int
var x int
Correct.
Go
[26, 68, 68
[26, 68, 68]
Close bracket.
Ruby
var val int = 'hello'
var val string = 'hello'
Type mismatch.
Go
num = 56
num=56
No spaces.
Shell
if (bar = 31)
if (bar == 31)
Use ==.
Scala
<person age=64>
<person age="64">
Quote attribute.
XML
function handle(temp) print(temp) end
function handle(temp) print(temp) end
Correct.
Lua
if num = 37
if num == 37
Use ==.
MATLAB
values[9]
if values.indices.contains(9) {{ values[9] }}
Check index.
Swift
let data: number = 'world';
let data: string = 'world';
Fix type.
TypeScript
render
render()
Add parentheses.
Kotlin
WHERE id = '66'
WHERE id = 66
Don't quote integer.
SQL
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$temp = 16; if ($temp = 16) {{}}
$temp = 16; if ($temp == 16) {{}}
Use ==.
PHP
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if foo = 99
if foo == 99
Use ==.
Ruby
my @arr = (5,36,10);
my @arr = (5,36,10);
Correct.
Perl
class Person def method end end
class Person def method end end
Correct.
Ruby
let z = 84; let z = 45;
let z = 84; z = 45;
Duplicate declaration.
JavaScript
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
if foo = 100 then print('test') end
if foo == 100 then print('test') end
Use ==.
Lua
if [ $z = 34 ]; then
if [ "$z" = 34 ]; then
Quote variable.
Shell
UPDATE items SET id='test' WHERE email=60
UPDATE items SET id='test' WHERE email=60;
Add semicolon.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
function foo(): void {{ return 18; }}
function foo(): number {{ return 18; }}
Return type mismatch.
TypeScript
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
int index = 'output';
String index = 'output';
Type mismatch.
Dart
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
String name = 'result';
String name = 'result';
Correct.
Dart
local val = 10
local val = 10
Correct.
Lua
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{{'age':'hello'}}
{{"age":"hello"}}
Use double quotes.
JSON
{{"id":"hello" "status":73}}
{{"id":"hello", "status":73}}
Add comma.
JSON