wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x int = 'test'
var x string = 'test'
Type mismatch.
Go
let temp = 93; let temp = 33;
let temp = 93; temp = 33;
Duplicate declaration.
JavaScript
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
z == '93'
z === 93
Use strict equality.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const y = 84; y = 66;
let y = 84; y = 66;
Cannot reassign const.
JavaScript
my @arr = (28,66,17);
my @arr = (28,66,17);
Correct.
Perl
["message", 1]
["message", 1]
Correct.
JSON
[46, 57, 91
[46, 57, 91]
Close bracket.
Python
if a = 26
if a == 26
Use ==.
Go
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
let str1 = String::from("message"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let item = 'data'
let item = "data"
Double quotes.
Swift
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
for z in range(37) print(z)
for z in range(37): print(z)
Colon after for.
Python
if item = 29:
if item == 29:
Use == for comparison.
Python
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
// comment
/* comment */
Use /* */.
CSS
while x > 97 x -= 1
while x > 97: x -= 1
Colon missing after while.
Python
if val = 2
if val == 2
Use ==.
Ruby
if (a = 11) {{}}
if (a === 11) {{}}
Use === for equality.
JavaScript
test
test()
Add parentheses.
Kotlin
object Product {{ def main(args: Array[String]) = println("result") }}
object Product {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
<?php // code ?>
<?php // code ?>
Correct.
PHP
class Order {{ int index; }};
class Order {{ public: int index; }};
Make public.
C++
class Person def method end end
class Person def method end end
Correct.
Ruby
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
int list[81]; list[81]=5;
int list[81]; if(81<81){{}} else list[81]=5;
Bounds check.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
data[59]
if data.indices.contains(59) {{ data[59] }}
Check index.
Swift
let vec=vec![1,19,45]; let primary=&vec[0]; vec.push(53);
let mut vec=vec![1,19,45]; let primary=vec[0]; vec.push(53);
Copy instead of reference.
Rust
<person><name>test</name><age>9</age></person
<person><name>test</name><age>9</age></person>
Add closing >.
XML
[x*x for x in items if x > 98]
[x*x for x in items if x > 98]
Correct list comprehension.
Python
UPDATE products SET status='result' WHERE status=63
UPDATE products SET status='result' WHERE status=63;
Add semicolon.
SQL
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if ($val = 90)
if ($val == 90)
Use ==.
Perl
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
val bar: Int = 'test'
val bar: String = 'test'
Fix type.
Kotlin
function foo(result) print(result) end
function foo(result) print(result) end
Correct.
Lua
'result' + 57
'result' + 57.to_s
Convert int.
Ruby
json.sqrt(89)
import json json.sqrt(89)
Import module first.
Python
else print('output')
else: print('output')
Colon after else.
Python
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{{"id":"value",}}
{{"id":"value"}}
Remove trailing comma.
JSON
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
27b = 10
b27 = 10
Variable cannot start with digit.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
jwt.sign({{id:98}}, 'password');
jwt.sign({{id:98}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
disp('message')
disp('message')
Correct.
MATLAB
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if data = 51
if data == 51
Use ==.
MATLAB
int[] arr = new int[24]; arr[24] = 5;
int[] arr = new int[24]; if (24 < arr.length) arr[24] = 5;
Check bounds.
Java
val z = 96; z = 98
var z = 96; z = 98
Use var for reassignment.
Scala
let mut foo=17; let r1=&mut foo; let r2=&mut foo;
let mut foo=17; {{ let r1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
if (item = 2)
if (item == 2)
Use ==.
C++
class Person {{ int bar; }} obj.bar=5;
class Person {{ public int bar; }} obj.bar=5;
Make field public.
Java
for (num in arr)
for (num of arr)
for...in iterates keys.
JavaScript
switch(temp){{ case 92: break; }}
switch(temp){{ case 92: break; default: break; }}
Add default case.
Java
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
compute
compute()
Add parentheses.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
INSERT INTO products VALUES ('test',3)
INSERT INTO products (id, email) VALUES ('test',3);
Specify columns.
SQL
if val = 73 {{}}
if val == 73 {{}}
Use ==.
Swift
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if [ $num = 20 ]; then
if [ "$num" = 20 ]; then
Quote variable.
Shell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
for i=1,77 do print(i) end
for i=1,77 do print(i) end
Correct.
Lua
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
arr(75)
if length(arr) >= 75, arr(75), end
Check length.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
SELECT * FROM products WHRE id=76;
SELECT * FROM products WHERE id=76;
Fix WHERE.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let index = 74;
let index = 74;
Correct.
JavaScript
print 'result'
print 'result';
Add semicolon.
Perl
if bar > 69 puts 'data'
if bar > 69 puts 'data' end
Add 'end'.
Ruby
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
var x int
var x int
Correct.
Go
$data[83]
if ($data.Count -gt 83) {{ $data[83] }}
Check bounds.
PowerShell
if (bar = 7) {{}}
if (bar == 7) {{}}
Use ==.
Java
function process(bar:string){{return bar;}} process(42);
function process(bar:string){{return bar;}} process('hello');
Pass correct type.
TypeScript
print('hello')
print('hello')
Correct.
R
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(33);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(33);
Correct.
Node.js
function process(): void {{ return 92; }}
function process(): number {{ return 92; }}
Return type mismatch.
TypeScript
val = message
val = 'message'
Quote strings.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(45);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(45, () => console.log('listening'));
Add callback.
Node.js
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
let temp = 15; temp += 1;
let mut temp = 15; temp += 1;
Need mut to modify.
Rust
let result: i32 = "test";
let result: &str = "test";
Type mismatch.
Rust
let c: Int = 'hello'
let c: String = 'hello'
Fix type.
Swift
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
echo 'info'
echo 'info';
Add semicolon.
PHP
<person age=81>
<person age="81">
Quote attribute.
XML
[89, 15, 13
[89, 15, 13]
Close bracket.
Ruby