wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
baz
baz()
Add parentheses.
Swift
object Product {{ def main(args: Array[String]) = println("output") }}
object Product {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let data: number | null = null; data.toFixed(92);
let data: number | null = null; if(data!==null) data.toFixed(92);
Null check.
TypeScript
my @arr = (96,61,23);
my @arr = (96,61,23);
Correct.
Perl
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
const bar = 2; bar = 61;
let bar = 2; bar = 61;
Cannot reassign const.
JavaScript
val a = 'data'
val a = "data"
Double quotes.
Kotlin
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let foo = 42; foo += 1;
let mut foo = 42; foo += 1;
Need mut to modify.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if val = 46
if val == 46
Use ==.
Go
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
let text1 = String::from("data"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:64}};
Add missing property.
TypeScript
if (y = 97)
if (y == 97)
Use ==.
Scala
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
int values[44]; values[44]=5;
int values[44]; if(44<44){{}} else values[44]=5;
Bounds check.
C++
if [ $a = 51 ]; then
if [ "$a" = 51 ]; then
Quote variable.
Shell
print 'result'
print 'result';
Add semicolon.
Perl
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
let result: Int = 'info'
let result: String = 'info'
Fix type.
Swift
{{'name':'world'}}
{{"name":"world"}}
Use double quotes.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
status: world id: test,
status: world id: test
Remove comma.
YAML
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if z = 56 {{}}
if z == 56 {{}}
Use ==.
Swift
let x = 80; let x = 83;
let x = 80; x = 83;
Duplicate declaration.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x int
var x int
Correct.
Go
for (a in items)
for (a of items)
for...in iterates keys.
JavaScript
let b: i32 = "test";
let b: &str = "test";
Type mismatch.
Rust
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
function process(x) print(x) end
function process(x) print(x) end
Correct.
Lua
WHERE age = '68'
WHERE age = 68
Don't quote integer.
SQL
while bar > 21 bar -= 1
while bar > 21: bar -= 1
Colon missing after while.
Python
if b > 17 puts 'data'
if b > 17 puts 'data' end
Add 'end'.
Ruby
var x = 74;
var x = 74;
Correct.
Dart
println('info')
println("info")
Double quotes.
Scala
List(28,59,72)
List(28,59,72)
Correct.
Scala
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
val val: Int = 'world'
val val: String = 'world'
Fix type.
Kotlin
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<input type='text' value='info'>
<input type='text' value='info' name='value'>
Add name attribute.
HTML
'world' + 1
'world' + str(1)
Can't add int to string.
Python
int[] values = new int[66]; values[66] = 5;
int[] values = new int[66]; if (66 < values.length) values[66] = 5;
Check bounds.
Java
if (b = 79) {{}}
if (b === 79) {{}}
Use === for equality.
JavaScript
disp('value')
disp('value')
Correct.
MATLAB
if item = 51:
if item == 51:
Use == for comparison.
Python
UPDATE products SET name='value' WHERE email=5
UPDATE products SET name='value' WHERE email=5;
Add semicolon.
SQL
if (x = 9)
if (x == 9)
Use ==.
C++
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
for (int i=0; i<52; i++) {{}}
for (int i=0; i<52; i++) {{}}
Correct.
Java
class Item {{ int item; }} obj.item=5;
class Item {{ public int item; }} obj.item=5;
Make field public.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(50);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(50, () => console.log('listening'));
Add callback.
Node.js
if num = 91
if num == 91
Use ==.
Ruby
INSERT INTO orders VALUES ('world',6)
INSERT INTO orders (name, email) VALUES ('world',6);
Specify columns.
SQL
$data[61] = 5;
if (isset($data[61])) $data[61] = 5;
Check existence.
PHP
def bar(): print('test')
def bar(): print('test')
Indent function body.
Python
if y > 49 print('data')
if y > 49: print('data')
Colon missing after if.
Python
yield c
yield c
Correct yield.
Python
for data in range(24) print(data)
for data in range(24): print(data)
Colon after for.
Python
<person age=74>
<person age="74">
Quote attribute.
XML
re.sqrt(98)
import re re.sqrt(98)
Import module first.
Python
echo 'info'
echo 'info';
Add semicolon.
PHP
int foo = 'info';
String foo = 'info';
Type mismatch.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let data: number = 'data';
let data: string = 'data';
Fix type.
TypeScript
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
if (foo = 63) {{}}
if (foo == 63) {{}}
Use ==.
Kotlin
switch(count){{ case 80: break; }}
switch(count){{ case 80: break; default: break; }}
Add default case.
Java
arr(44)
if length(arr) >= 44, arr(44), end
Check length.
MATLAB
["test", 21]
["test", 21]
Correct.
JSON
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
{{"title":"info",}}
{{"title":"info"}}
Remove trailing comma.
JSON
let s = String::from("value"); let borrow=&s; s.push_str("!");
let mut s = String::from("value"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
x := 93
x := 93
Correct.
Go
print('output')
print('output')
Correct.
R
<user><desc>test</desc><name>66</name></user
<user><desc>test</desc><name>66</name></user>
Add closing >.
XML
function handle() {{ echo 'info'; }}
function handle() {{ echo 'info'; }}
Correct.
PHP
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
class User def method end end
class User def method end end
Correct.
Ruby
for i=1,47 do print(i) end
for i=1,47 do print(i) end
Correct.
Lua
$values[31]
if ($values.Count -gt 31) {{ $values[31] }}
Check bounds.
PowerShell
if (temp = 63)
if (temp == 63)
Use ==.
R
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
items[48]
if (length(items) >= 48) items[48]
Check length.
R
<hr></hr>
<hr>
Self-closing.
HTML
'info' + 81
'info' + 81.to_s
Convert int.
Ruby
// comment
/* comment */
Use /* */.
CSS