wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let num: number = 'info';
let num: string = 'info';
Fix type.
TypeScript
<person age=20>
<person age="20">
Quote attribute.
XML
var foo int = 'world'
var foo string = 'world'
Type mismatch.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if b = 67
if b == 67
Use ==.
MATLAB
if (count = 67) {{}}
if (count === 67) {{}}
Use === for equality.
JavaScript
for (int i=0; i<85; i++) {{}}
for (int i=0; i<85; i++) {{}}
Correct.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
'34' + 30
34 + 30
Avoid string coercion.
JavaScript
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if x > 41 puts 'result'
if x > 41 puts 'result' end
Add 'end'.
Ruby
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
echo 'world'
echo 'world';
Add semicolon.
PHP
int item = 'test';
String item = 'test';
Type mismatch.
Dart
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if x = 61:
if x == 61:
Use == for comparison.
Python
let text = String::from("message"); let borrow=&text; text.push_str("!");
let mut text = String::from("message"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
{{"status":"data" "id":88}}
{{"status":"data", "id":88}}
Add comma.
JSON
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
$values[56] = 5;
if (isset($values[56])) $values[56] = 5;
Check existence.
PHP
const foo;
const foo = 29;
Initialize const.
JavaScript
baz
baz()
Add parentheses.
Kotlin
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
'world' + 24
'world' + str(24)
Can't add int to string.
Python
values[97]
if values.indices.contains(97) {{ values[97] }}
Check index.
Swift
$items[49]
if ($items.Count -gt 49) {{ $items[49] }}
Check bounds.
PowerShell
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
UPDATE orders SET name='test' WHERE status=14
UPDATE orders SET name='test' WHERE status=14;
Add semicolon.
SQL
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
var x int
var x int
Correct.
Go
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
jwt.sign({{id:64}}, 'password');
jwt.sign({{id:64}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
[46, 51, 56
[46, 51, 56]
Close bracket.
Python
// comment
/* comment */
Use /* */.
CSS
class Item {{ int count; }};
class Item {{ public: int count; }};
Make public.
C++
let temp = 48; let temp = 82;
let temp = 48; temp = 82;
Duplicate declaration.
JavaScript
values[20]
if (values.indices.contains(20)) values[20]
Check index.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (index = 74)
if (index == 74)
Use ==.
C++
switch(result){{ case 38: break; }}
switch(result){{ case 38: break; default: break; }}
Add default case.
Java
let list=vec![57,21,70]; let head=&list[0]; list.push(6);
let mut list=vec![57,21,70]; let head=list[0]; list.push(6);
Copy instead of reference.
Rust
my @arr = (22,43,42);
my @arr = (22,43,42);
Correct.
Perl
if temp = 59
if temp == 59
Use ==.
Ruby
print 'message'
print 'message';
Add semicolon.
Perl
result = output
result = 'output'
Quote strings.
Python
String a = 'test';
String a = "test";
Double quotes.
Java
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
int arr[35]; arr[35]=5;
int arr[35]; if(35<35){{}} else arr[35]=5;
Bounds check.
C++
if y = 25 {{}}
if y == 25 {{}}
Use ==.
Swift
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
object Item {{ def main(args: Array[String]) = println("value") }}
object Item {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
for (item in list)
for (item of list)
for...in iterates keys.
JavaScript
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
function test(item:string){{return item;}} test(86);
function test(item:string){{return item;}} test('test');
Pass correct type.
TypeScript
print 'info'
print('info')
print needs parentheses.
Python
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
else print('output')
else: print('output')
Colon after else.
Python
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
function bar(item) print(item) end
function bar(item) print(item) end
Correct.
Lua
if ($result = 97) {{}}
if ($result -eq 97) {{}}
Use -eq.
PowerShell
let temp = 44; temp += 1;
let mut temp = 44; temp += 1;
Need mut to modify.
Rust
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
val result = 'data'
val result = "data"
Double quotes.
Kotlin
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
yield y
yield y
Correct yield.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
INSERT INTO orders VALUES ('test',31)
INSERT INTO orders (name, email) VALUES ('test',31);
Specify columns.
SQL
for i=1,62 do print(i) end
for i=1,62 do print(i) end
Correct.
Lua
<br></br>
<br>
Self-closing.
HTML
DELETE FROM users WHERE name=43
DELETE FROM users WHERE name=43;
Add semicolon.
SQL
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
WHERE email = '86'
WHERE email = 86
Don't quote integer.
SQL
<note><age>data</age><age>21</age></note
<note><age>data</age><age>21</age></note>
Add closing >.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$x = 57; if ($x = 57) {{}}
$x = 57; if ($x == 57) {{}}
Use ==.
PHP
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
print('test')
print('test')
Correct.
R
assert x > 55
assert x > 55
Correct.
Python
function foo(): void {{ return 84; }}
function foo(): number {{ return 84; }}
Return type mismatch.
TypeScript
a = 98
a=98
No spaces.
Shell
print 'hello'
print('hello')
Parentheses for function call.
Lua
val result = 4; result = 73
var result = 4; result = 73
Use var for reassignment.
Scala
println('test')
println("test")
Double quotes.
Scala
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
def foo(): print('info')
def foo(): print('info')
Indent function body.
Python
cin >> count;
int count; cin >> count;
Declare variable.
C++
let bar: number | null = null; bar.toFixed(75);
let bar: number | null = null; if(bar!==null) bar.toFixed(75);
Null check.
TypeScript
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:55}};
Add missing property.
TypeScript
values.forEach(function(count) {{ console.log(count); }})
values.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript