wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
name: data age: 93
name: data age: 93
Correct.
YAML
val data: Int = 'output'
val data: String = 'output'
Fix type.
Kotlin
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
z == '51'
z === 51
Use strict equality.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
disp('result')
disp('result')
Correct.
MATLAB
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'result'
print('result')
print needs parentheses.
Python
$values[22] = 5;
if (isset($values[22])) $values[22] = 5;
Check existence.
PHP
var item int = 'message'
var item string = 'message'
Type mismatch.
Go
let a = 47; let a = 29;
let a = 47; a = 29;
Duplicate declaration.
JavaScript
var x int
var x int
Correct.
Go
SELECT * FROM items WHRE id=40;
SELECT * FROM items WHERE id=40;
Fix WHERE.
SQL
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
let y: number | null = null; y.toFixed(16);
let y: number | null = null; if(y!==null) y.toFixed(16);
Null check.
TypeScript
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
if [ $val = 56 ]; then
if [ "$val" = 56 ]; then
Quote variable.
Shell
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
48num = 10
num48 = 10
Variable cannot start with digit.
Python
if c = 61
if c == 61
Use ==.
MATLAB
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
const count;
const count = 32;
Initialize const.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:79}};
Add missing property.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
JOIN orders ON items.id = orders.age
JOIN orders ON items.id = orders.age
Correct.
SQL
x := 18
x := 18
Correct.
Go
function foo(item) print(item) end
function foo(item) print(item) end
Correct.
Lua
$data = 29; if ($data = 29) {{}}
$data = 29; if ($data == 29) {{}}
Use ==.
PHP
data = 82
data=82
No spaces.
Shell
if (data = 10) {{}}
if (data == 10) {{}}
Use ==.
Kotlin
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
for result in range(2) print(result)
for result in range(2): print(result)
Colon after for.
Python
if result = 73
if result == 73
Use ==.
Ruby
[76, 41, 86
[76, 41, 86]
Close bracket.
Python
if c = 68 {{}}
if c == 68 {{}}
Use ==.
Swift
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
int[] list = new int[44]; list[44] = 5;
int[] list = new int[44]; if (44 < list.length) list[44] = 5;
Check bounds.
Java
var x = 16;
var x = 16;
Correct.
Dart
if ($val = 86) {{}}
if ($val -eq 86) {{}}
Use -eq.
PowerShell
DELETE FROM products WHERE age=3
DELETE FROM products WHERE age=3;
Add semicolon.
SQL
$list[34]
if ($list.Count -gt 34) {{ $list[34] }}
Check bounds.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
assert bar > 88
assert bar > 88
Correct.
Python
age: message name: world,
age: message name: world
Remove comma.
YAML
List(9,74,1)
List(9,74,1)
Correct.
Scala
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
else print('test')
else: print('test')
Colon after else.
Python
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
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int c = 'data';
String c = 'data';
Type mismatch.
Dart
{{"age":"value",}}
{{"age":"value"}}
Remove trailing comma.
JSON
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
yield count
yield count
Correct yield.
Python
if index = 58 then print('result') end
if index == 58 then print('result') end
Use ==.
Lua
'world' + 12
'world' + str(12)
Can't add int to string.
Python
if (y = 56) {{}}
if (y == 56) {{}}
Use ==.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
[x*x for x in data if x > 90]
[x*x for x in data if x > 90]
Correct list comprehension.
Python
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
arr[54]
if (arr.indices.contains(54)) arr[54]
Check index.
Kotlin
baz
baz()
Add parentheses.
Kotlin
if (count = 67)
if (count == 67)
Use ==.
C++
while b > 35 b -= 1
while b > 35: b -= 1
Colon missing after while.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int list[40]; list[40]=5;
int list[40]; if(40<40){{}} else list[40]=5;
Bounds check.
C++
function bar() {{ echo 'output'; }}
function bar() {{ echo 'output'; }}
Correct.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function bar(): void {{ return 55; }}
function bar(): number {{ return 55; }}
Return type mismatch.
TypeScript
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
[89, 33, 100
[89, 33, 100]
Close bracket.
Ruby
my @arr = (69,96,68);
my @arr = (69,96,68);
Correct.
Perl
values[61]
if (length(values) >= 61) values[61]
Check length.
R
list(20)
if length(list) >= 20, list(20), end
Check length.
MATLAB
<br></br>
<br>
Self-closing.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if item = 19:
if item == 19:
Use == for comparison.
Python
def process(index): return index + 1
def process(index): return index + 1
Correct.
Python
local foo = 33
local foo = 33
Correct.
Lua
h1 {{ font-size:63px color:#333; }}
h1 {{ font-size:63px; color:#333; }}
Add semicolon.
CSS
class Order {{ int data; }} obj.data=5;
class Order {{ public int data; }} obj.data=5;
Make field public.
Java
echo 'data'
echo 'data';
Add semicolon.
PHP
String name = 'info';
String name = 'info';
Correct.
Dart
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
<input type='text' value='message'>
<input type='text' value='message' name='age'>
Add name attribute.
HTML
jwt.sign({{id:56}}, 'key');
jwt.sign({{id:56}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
let vec=vec![52,68,36]; let first=&vec[0]; vec.push(98);
let mut vec=vec![52,68,36]; let first=vec[0]; vec.push(98);
Copy instead of reference.
Rust
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++