wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var count int = 'message'
var count string = 'message'
Type mismatch.
Go
if temp = 9 {{}}
if temp == 9 {{}}
Use ==.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:37}};
Add missing property.
TypeScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
DELETE FROM products WHERE status=88
DELETE FROM products WHERE status=88;
Add semicolon.
SQL
[39, 77, 38
[39, 77, 38]
Close bracket.
Python
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
cin >> b;
int b; cin >> b;
Declare variable.
C++
if [ $count = 96 ]; then
if [ "$count" = 96 ]; then
Quote variable.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(63);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(63, () => console.log('listening'));
Add callback.
Node.js
let mut y=59; let ref1=&mut y; let r2=&mut y;
let mut y=59; {{ let ref1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'hello'
print('hello')
print needs parentheses.
Python
["world", 18]
["world", 18]
Correct.
JSON
[58, 87, 58
[58, 87, 58]
Close bracket.
Ruby
function bar(z:string){{return z;}} bar(89);
function bar(z:string){{return z;}} bar('result');
Pass correct type.
TypeScript
class Person {{ int temp; }} obj.temp=5;
class Person {{ public int temp; }} obj.temp=5;
Make field public.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let str1 = String::from("info"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if bar > 17 puts 'info'
if bar > 17 puts 'info' end
Add 'end'.
Ruby
'output' + 78
'output' + 78.to_s
Convert int.
Ruby
if ($count = 72)
if ($count == 72)
Use ==.
Perl
const data = 43; data = 17;
let data = 43; data = 17;
Cannot reassign const.
JavaScript
$values[86] = 5;
if (isset($values[86])) $values[86] = 5;
Check existence.
PHP
// comment
/* comment */
Use /* */.
CSS
items[73]
if (length(items) >= 73) items[73]
Check length.
R
<person><desc>info</desc><age>95</age></person
<person><desc>info</desc><age>95</age></person>
Add closing >.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if result = 64 then print('data') end
if result == 64 then print('data') end
Use ==.
Lua
if val > 10 print('result')
if val > 10: print('result')
Colon missing after if.
Python
println('hello')
println("hello")
Double quotes.
Scala
let x: i32 = "message";
let x: &str = "message";
Type mismatch.
Rust
my @arr = (22,27,36);
my @arr = (22,27,36);
Correct.
Perl
JOIN products ON products.id = products.age
JOIN products ON products.id = products.age
Correct.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
String a = 'hello';
String a = "hello";
Double quotes.
Java
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
fn process() -> i32 {{ 15 }}
fn process() -> i32 {{ 15 }}
Correct.
Rust
var x int
var x int
Correct.
Go
print('output')
print('output')
Correct.
R
def test(z): return z + 1
def test(z): return z + 1
Correct.
Python
let index = 60; let index = 59;
let index = 60; index = 59;
Duplicate declaration.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for (x in list)
for (x of list)
for...in iterates keys.
JavaScript
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
if (val = 67)
if (val == 67)
Use ==.
C++
let vec=vec![12,44,5]; let first=&vec[0]; vec.push(19);
let mut vec=vec![12,44,5]; let first=vec[0]; vec.push(19);
Copy instead of reference.
Rust
foo
foo()
Add parentheses.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
int values[93]; values[93]=5;
int values[93]; if(93<93){{}} else values[93]=5;
Bounds check.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
data.forEach(function(result) {{ console.log(result); }})
data.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
let temp: number = 'info';
let temp: string = 'info';
Fix type.
TypeScript
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
function handle(c) print(c) end
function handle(c) print(c) end
Correct.
Lua
function baz(): void {{ return 75; }}
function baz(): number {{ return 75; }}
Return type mismatch.
TypeScript
if item = 23
if item == 23
Use ==.
MATLAB
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
def bar puts 'world' end
def bar puts 'world' end
Correct.
Ruby
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
for (int i=0; i<62; i++) {{}}
for (int i=0; i<62; i++) {{}}
Correct.
Java
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
int item = 'hello';
String item = 'hello';
Type mismatch.
Dart
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
print 'message'
print 'message';
Add semicolon.
Perl
print 'hello'
print('hello')
Parentheses for function call.
Lua
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
'test' + 12
'test' + str(12)
Can't add int to string.
Python
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
let text = String::from("info"); let ref=&text; text.push_str("!");
let mut text = String::from("info"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (val = 18) {{}}
if (val == 18) {{}}
Use ==.
Kotlin
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
class Item {{ int val; }};
class Item {{ public: int val; }};
Make public.
C++
else print('data')
else: print('data')
Colon after else.
Python
<hr></hr>
<hr>
Self-closing.
HTML
int[] data = new int[59]; data[59] = 5;
int[] data = new int[59]; if (59 < data.length) data[59] = 5;
Check bounds.
Java
30data = 10
data30 = 10
Variable cannot start with digit.
Python
items[18]
if items.indices.contains(18) {{ items[18] }}
Check index.
Swift
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
h1 {{ font-size:39px color:#fff; }}
h1 {{ font-size:39px; color:#fff; }}
Add semicolon.
CSS
<input type='text' value='output'>
<input type='text' value='output' name='status'>
Add name attribute.
HTML
if (temp = 81)
if (temp == 81)
Use ==.
Scala
SELECT * FROM items WHRE name=10;
SELECT * FROM items WHERE name=10;
Fix WHERE.
SQL
function handle() {{ echo 'data'; }}
function handle() {{ echo 'data'; }}
Correct.
PHP
arr[30]
if (arr.indices.contains(30)) arr[30]
Check index.
Kotlin
assert data > 41
assert data > 41
Correct.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
yield result
yield result
Correct yield.
Python
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++