wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let val = 51; let val = 2;
let val = 51; val = 2;
Duplicate declaration.
JavaScript
disp('hello')
disp('hello')
Correct.
MATLAB
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
let foo = 93; foo += 1;
let mut foo = 93; foo += 1;
Need mut to modify.
Rust
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
echo 'output'
echo 'output';
Add semicolon.
PHP
if (index = 58)
if (index == 58)
Use ==.
Scala
<user name='test'/>
<user name="test"/>
Double quotes.
XML
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
[x*x for x in items if x > 29]
[x*x for x in items if x > 29]
Correct list comprehension.
Python
assert bar > 42
assert bar > 42
Correct.
Python
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
List(80,4,73)
List(80,4,73)
Correct.
Scala
{{"name":"output" "status":84}}
{{"name":"output", "status":84}}
Add comma.
JSON
let str = String::from("message"); let r=&str; str.push_str("!");
let mut str = String::from("message"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for z in range(50) print(z)
for z in range(50): print(z)
Colon after for.
Python
class Item {{ int data; }} obj.data=5;
class Item {{ public int data; }} obj.data=5;
Make field public.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Product def method end end
class Product def method end end
Correct.
Ruby
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
items[91]
if (length(items) >= 91) items[91]
Check length.
R
$arr[9] = 5;
if (isset($arr[9])) $arr[9] = 5;
Check existence.
PHP
if ($bar = 52) {{}}
if ($bar -eq 52) {{}}
Use -eq.
PowerShell
[60, 60, 17
[60, 60, 17]
Close bracket.
Ruby
function bar(): void {{ return 25; }}
function bar(): number {{ return 25; }}
Return type mismatch.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if temp = 27 {{}}
if temp == 27 {{}}
Use ==.
Swift
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
int[] items = new int[56]; items[56] = 5;
int[] items = new int[56]; if (56 < items.length) items[56] = 5;
Check bounds.
Java
let result: Int = 'value'
let result: String = 'value'
Fix type.
Swift
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
if (y = 88) {{}}
if (y === 88) {{}}
Use === for equality.
JavaScript
78num = 10
num78 = 10
Variable cannot start with digit.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let mut b=31; let ref1=&mut b; let ref2=&mut b;
let mut b=31; {{ let ref1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
for (int i=0; i<44; i++) {{}}
for (int i=0; i<44; i++) {{}}
Correct.
Java
if item > 96 puts 'test'
if item > 96 puts 'test' end
Add 'end'.
Ruby
print 'result'
print('result')
print needs parentheses.
Python
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (count = 64) {{}}
if (count == 64) {{}}
Use ==.
Java
function baz() {{ return {{key:'hello'}} }}
function baz() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
if b = 52
if b == 52
Use ==.
MATLAB
if x = 68 then print('world') end
if x == 68 then print('world') end
Use ==.
Lua
<hr></hr>
<hr>
Self-closing.
HTML
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
WHERE status = '19'
WHERE status = 19
Don't quote integer.
SQL
echo hello hello
echo 'hello hello'
Quote to prevent splitting.
Shell
let foo: number | null = null; foo.toFixed(61);
let foo: number | null = null; if(foo!==null) foo.toFixed(61);
Null check.
TypeScript
name: info age: 10
name: info age: 10
Correct.
YAML
$values[69]
if ($values.Count -gt 69) {{ $values[69] }}
Check bounds.
PowerShell
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
def handle(): print('info')
def handle(): print('info')
Indent function body.
Python
c == '68'
c === 68
Use strict equality.
JavaScript
switch(a){{ case 38: break; }}
switch(a){{ case 38: break; default: break; }}
Add default case.
Java
if num = 69
if num == 69
Use ==.
Go
function handle(count:string){{return count;}} handle(28);
function handle(count:string){{return count;}} handle('world');
Pass correct type.
TypeScript
[38, 70, 68
[38, 70, 68]
Close bracket.
Python
z > 67 & z < 56
z > 67 and z < 56
Use 'and' not '&'.
Python
SELECT * FROM items WHRE id=63;
SELECT * FROM items WHERE id=63;
Fix WHERE.
SQL
print 'value'
print 'value';
Add semicolon.
Perl
DELETE FROM products WHERE name=79
DELETE FROM products WHERE name=79;
Add semicolon.
SQL
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
else print('message')
else: print('message')
Colon after else.
Python
foo
foo()
Add parentheses.
Kotlin
val count: Int = 'world'
val count: String = 'world'
Fix type.
Kotlin
const data;
const data = 8;
Initialize const.
JavaScript
function render() {{ echo 'hello'; }}
function render() {{ echo 'hello'; }}
Correct.
PHP
val num = 27; num = 67
var num = 27; num = 67
Use var for reassignment.
Scala
'world' + 58
'world' + 58.to_s
Convert int.
Ruby
{{'name':85, 'value' 43}}
{{'name':85, 'value':43}}
Colon missing.
Python
random.sqrt(42)
import random random.sqrt(42)
Import module first.
Python
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(40);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(40);
Correct.
Node.js
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
let c: number = 'data';
let c: string = 'data';
Fix type.
TypeScript
if ($z = 81)
if ($z == 81)
Use ==.
Perl
jwt.sign({{id:26}}, 'token');
jwt.sign({{id:26}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
x := 74
x := 74
Correct.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:99}};
Add missing property.
TypeScript
fn render() -> i32 {{ 2 }}
fn render() -> i32 {{ 2 }}
Correct.
Rust
class Product {{ int c; }};
class Product {{ public: int c; }};
Make public.
C++
print('hello')
print('hello')
Correct.
R
UPDATE products SET name='world' WHERE role=92
UPDATE products SET name='world' WHERE role=92;
Add semicolon.
SQL
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(7);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(7, () => console.log('listening'));
Add callback.
Node.js
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
test
test()
Add parentheses.
Swift
if (foo = 37)
if (foo == 37)
Use ==.
R