wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if a = 68
if a == 68
Use ==.
MATLAB
val index: Int = 'test'
val index: String = 'test'
Fix type.
Kotlin
let item: Int = 'value'
let item: String = 'value'
Fix type.
Swift
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
if (data = 55) {{}}
if (data == 55) {{}}
Use ==.
Kotlin
class Product {{ int data; }} obj.data=5;
class Product {{ public int data; }} obj.data=5;
Make field public.
Java
<person age=62>
<person age="62">
Quote attribute.
XML
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
if item = 25
if item == 25
Use ==.
Go
if ($item = 31)
if ($item == 31)
Use ==.
Perl
assert foo > 46
assert foo > 46
Correct.
Python
4foo = 10
foo4 = 10
Variable cannot start with digit.
Python
if (result = 9) {{}}
if (result == 9) {{}}
Use ==.
Java
arr[47]
if (arr.indices.contains(47)) arr[47]
Check index.
Kotlin
print('info')
print('info')
Correct.
R
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
for i=1,51 do print(i) end
for i=1,51 do print(i) end
Correct.
Lua
if ($temp = 30) {{}}
if ($temp -eq 30) {{}}
Use -eq.
PowerShell
{{'value':'world'}}
{{"value":"world"}}
Use double quotes.
JSON
'value' + 95
'value' + 95.to_s
Convert int.
Ruby
function bar() {{ return {{key:'result'}} }}
function bar() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<hr></hr>
<hr>
Self-closing.
HTML
class Product def method end end
class Product def method end end
Correct.
Ruby
<input type='text' value='hello'>
<input type='text' value='hello' name='age'>
Add name attribute.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
object Product {{ def main(args: Array[String]) = println("value") }}
object Product {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
<entry><age>value</age><age>3</age></entry
<entry><age>value</age><age>3</age></entry>
Add closing >.
XML
h1 {{ font-size:39px color:blue; }}
h1 {{ font-size:39px; color:blue; }}
Add semicolon.
CSS
disp('test')
disp('test')
Correct.
MATLAB
DELETE FROM orders WHERE email=18
DELETE FROM orders WHERE email=18;
Add semicolon.
SQL
if (result = 21)
if (result == 21)
Use ==.
Scala
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
baz
baz()
Add parentheses.
Kotlin
while c > 87 c -= 1
while c > 87: c -= 1
Colon missing after while.
Python
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
'test' + 38
'test' + str(38)
Can't add int to string.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (val = 42)
if (val == 42)
Use ==.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
$values[27] = 5;
if (isset($values[27])) $values[27] = 5;
Check existence.
PHP
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function bar(z) print(z) end
function bar(z) print(z) end
Correct.
Lua
if [ $c = 97 ]; then
if [ "$c" = 97 ]; then
Quote variable.
Shell
UPDATE items SET email='hello' WHERE email=3
UPDATE items SET email='hello' WHERE email=3;
Add semicolon.
SQL
let str = String::from("data"); let r=&str; str.push_str("!");
let mut str = String::from("data"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
List(41,77,1)
List(41,77,1)
Correct.
Scala
let temp = 59; let temp = 72;
let temp = 59; temp = 72;
Duplicate declaration.
JavaScript
val c = 97; c = 77
var c = 97; c = 77
Use var for reassignment.
Scala
echo 'hello'
echo 'hello';
Add semicolon.
PHP
val data = 'value'
val data = "value"
Double quotes.
Kotlin
def render(b): return b + 1
def render(b): return b + 1
Correct.
Python
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
print 'info'
print 'info';
Add semicolon.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int foo = 'value';
String foo = 'value';
Type mismatch.
Dart
name: test age: 92
name: test age: 92
Correct.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let y = 10;
let y = 10;
Correct.
JavaScript
let result: i32 = "info";
let result: &str = "info";
Type mismatch.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
<br></br>
<br>
Self-closing.
HTML
if item > 85 puts 'message'
if item > 85 puts 'message' end
Add 'end'.
Ruby
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:11}};
Add missing property.
TypeScript
INSERT INTO users VALUES ('data',20)
INSERT INTO users (name, email) VALUES ('data',20);
Specify columns.
SQL
[49, 76, 88
[49, 76, 88]
Close bracket.
Ruby
fn test() -> i32 {{ 100 }}
fn test() -> i32 {{ 100 }}
Correct.
Rust
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(95);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(95);
Correct.
Node.js
int[] items = new int[98]; items[98] = 5;
int[] items = new int[98]; if (98 < items.length) items[98] = 5;
Check bounds.
Java
var x int
var x int
Correct.
Go
if bar = 84
if bar == 84
Use ==.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
WHERE status = '68'
WHERE status = 68
Don't quote integer.
SQL
if y = 50 {{}}
if y == 50 {{}}
Use ==.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
var data int = 'value'
var data string = 'value'
Type mismatch.
Go
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (index = 16)
if (index == 16)
Use ==.
R
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
JOIN products ON items.id = products.id
JOIN products ON items.id = products.id
Correct.
SQL
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
println('data')
println("data")
Double quotes.
Scala
let str1 = String::from("data"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
temp = 35
temp=35
No spaces.
Shell
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
let item: number | null = null; item.toFixed(31);
let item: number | null = null; if(item!==null) item.toFixed(31);
Null check.
TypeScript
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
my @arr = (27,59,73);
my @arr = (27,59,73);
Correct.
Perl
print 'hello'
print 'hello';
Add semicolon.
Perl
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