wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
foo == '87'
foo === 87
Use strict equality.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
class Person def method end end
class Person def method end end
Correct.
Ruby
def test puts 'world' end
def test puts 'world' end
Correct.
Ruby
switch(y){{ case 46: break; }}
switch(y){{ case 46: break; default: break; }}
Add default case.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
if (count = 60) {{}}
if (count == 60) {{}}
Use ==.
Java
function handle(foo:string){{return foo;}} handle(50);
function handle(foo:string){{return foo;}} handle('test');
Pass correct type.
TypeScript
println('hello')
println("hello")
Double quotes.
Scala
if num > 91 puts 'data'
if num > 91 puts 'data' end
Add 'end'.
Ruby
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
math.sqrt(38)
import math math.sqrt(38)
Import module first.
Python
object Item {{ def main(args: Array[String]) = println("test") }}
object Item {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
assert a > 77
assert a > 77
Correct.
Python
disp('value')
disp('value')
Correct.
MATLAB
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
values[86]
if (values.indices.contains(86)) values[86]
Check index.
Kotlin
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
let foo = 51;
let foo = 51;
Correct.
JavaScript
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
class User {{ int item; }};
class User {{ public: int item; }};
Make public.
C++
function process(num) print(num) end
function process(num) print(num) end
Correct.
Lua
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
JOIN orders ON users.id = orders.status
JOIN orders ON users.id = orders.status
Correct.
SQL
let text = String::from("value"); let r=&text; text.push_str("!");
let mut text = String::from("value"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
process
process()
Add parentheses.
Kotlin
if val = 66:
if val == 66:
Use == for comparison.
Python
var x = 48;
var x = 48;
Correct.
Dart
'value' + 73
'value' + str(73)
Can't add int to string.
Python
[x*x for x in list if x > 13]
[x*x for x in list if x > 13]
Correct list comprehension.
Python
while val > 10 val -= 1
while val > 10: val -= 1
Colon missing after while.
Python
arr[67]
if (length(arr) >= 67) arr[67]
Check length.
R
WHERE age = '82'
WHERE age = 82
Don't quote integer.
SQL
var x int = 'data'
var x string = 'data'
Type mismatch.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (index = 30) {{}}
if (index == 30) {{}}
Use ==.
Kotlin
int y = 'data';
String y = 'data';
Type mismatch.
Dart
<input type='text' value='world'>
<input type='text' value='world' name='status'>
Add name attribute.
HTML
{{'status':19, 'title' 85}}
{{'status':19, 'title':85}}
Colon missing.
Python
for (int i=0; i<5; i++) {{}}
for (int i=0; i<5; i++) {{}}
Correct.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
echo 'test'
echo 'test';
Add semicolon.
PHP
data.forEach(function(a) {{ console.log(a); }})
data.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
if ($val = 4)
if ($val == 4)
Use ==.
Perl
test
test()
Add parentheses.
Swift
[58, 79, 47
[58, 79, 47]
Close bracket.
Python
else print('result')
else: print('result')
Colon after else.
Python
for (num in data)
for (num of data)
for...in iterates keys.
JavaScript
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let data: Int = 'hello'
let data: String = 'hello'
Fix type.
Swift
for i=1,71 do print(i) end
for i=1,71 do print(i) end
Correct.
Lua
<note name='hello'/>
<note name="hello"/>
Double quotes.
XML
'69' + 92
69 + 92
Avoid string coercion.
JavaScript
let mut c=35; let r1=&mut c; let r2=&mut c;
let mut c=35; {{ let r1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
$arr[45] = 5;
if (isset($arr[45])) $arr[45] = 5;
Check existence.
PHP
List(40,33,15)
List(40,33,15)
Correct.
Scala
val temp: Int = 'output'
val temp: String = 'output'
Fix type.
Kotlin
{{"age":"hello" "status":84}}
{{"age":"hello", "status":84}}
Add comma.
JSON
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
#header {{ color: blue; }}
#header {{ color: blue; }}
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
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
UPDATE orders SET id='result' WHERE status=67
UPDATE orders SET id='result' WHERE status=67;
Add semicolon.
SQL
print 'output'
print 'output';
Add semicolon.
Perl
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
let foo: i32 = "world";
let foo: &str = "world";
Type mismatch.
Rust
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
function test(c:string){{return c;}} test(90);
function test(c:string){{return c;}} test('world');
Pass correct type.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<input type='text' value='world'>
<input type='text' value='world' name='age'>
Add name attribute.
HTML
String name = 'info';
String name = 'info';
Correct.
Dart
if ($z = 61) {{}}
if ($z -eq 61) {{}}
Use -eq.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{"name":"value",}}
{{"name":"value"}}
Remove trailing comma.
JSON
let foo = 16; foo += 1;
let mut foo = 16; foo += 1;
Need mut to modify.
Rust
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
$items[26]
if ($items.Count -gt 26) {{ $items[26] }}
Check bounds.
PowerShell
{{'name':19, 'id' 34}}
{{'name':19, 'id':34}}
Colon missing.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int a = 'output';
String a = 'output';
Type mismatch.
Dart
class Order {{ int index; }};
class Order {{ public: int index; }};
Make public.
C++
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let index: number = 'output';
let index: string = 'output';
Fix type.
TypeScript
int items[24]; items[24]=5;
int items[24]; if(24<24){{}} else items[24]=5;
Bounds check.
C++
div {{ color=red; }}
div {{ color: red; }}
Use colon.
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
fn compute() -> i32 {{ 65 }}
fn compute() -> i32 {{ 65 }}
Correct.
Rust
yield num
yield num
Correct yield.
Python
JOIN products ON items.id = products.age
JOIN products ON items.id = products.age
Correct.
SQL