wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
println('info')
println("info")
Double quotes.
Scala
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
if (num = 87)
if (num == 87)
Use ==.
R
SELECT name email FROM orders;
SELECT name, email FROM orders;
Add comma.
SQL
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:72}};
Add missing property.
TypeScript
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
<person age=2>
<person age="2">
Quote attribute.
XML
if temp > 13 print('message')
if temp > 13: print('message')
Colon missing after if.
Python
if result = 60
if result == 60
Use ==.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
'test' + 1
'test' + str(1)
Can't add int to string.
Python
val z = 'test'
val z = "test"
Double quotes.
Kotlin
$items[5] = 5;
if (isset($items[5])) $items[5] = 5;
Check existence.
PHP
$values[80]
if ($values.Count -gt 80) {{ $values[80] }}
Check bounds.
PowerShell
x > 48 & z < 88
x > 48 and z < 88
Use 'and' not '&'.
Python
int bar = 'world';
String bar = 'world';
Type mismatch.
Dart
if foo = 7:
if foo == 7:
Use == for comparison.
Python
switch(a){{ case 44: break; }}
switch(a){{ case 44: break; default: break; }}
Add default case.
Java
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
[28, 27, 23
[28, 27, 23]
Close bracket.
Python
INSERT INTO users VALUES ('message',90)
INSERT INTO users (name, email) VALUES ('message',90);
Specify columns.
SQL
class User {{ int foo; }} obj.foo=5;
class User {{ public int foo; }} obj.foo=5;
Make field public.
Java
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (b = 15) {}
if (b == 15) {}
Use ==.
Dart
if bar = 66
if bar == 66
Use ==.
Ruby
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
def process puts 'output' end
def process puts 'output' end
Correct.
Ruby
def handle(data): return data + 1
def handle(data): return data + 1
Correct.
Python
echo 'test'
echo 'test';
Add semicolon.
PHP
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
if (x = 71) {{}}
if (x === 71) {{}}
Use === for equality.
JavaScript
for i=1,65 do print(i) end
for i=1,65 do print(i) end
Correct.
Lua
if (x = 45)
if (x == 45)
Use ==.
Scala
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
yield b
yield b
Correct yield.
Python
var item int = 'message'
var item string = 'message'
Type mismatch.
Go
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
int[] items = new int[82]; items[82] = 5;
int[] items = new int[82]; if (82 < items.length) items[82] = 5;
Check bounds.
Java
int values[19]; values[19]=5;
int values[19]; if(19<19){{}} else values[19]=5;
Bounds check.
C++
[x*x for x in items if x > 25]
[x*x for x in items if x > 25]
Correct list comprehension.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
val index: Int = 'value'
val index: String = 'value'
Fix type.
Kotlin
if [ $y = 16 ]; then
if [ "$y" = 16 ]; then
Quote variable.
Shell
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
val a = 91; a = 54
var a = 91; a = 54
Use var for reassignment.
Scala
<br></br>
<br>
Self-closing.
HTML
if ($result = 21)
if ($result == 21)
Use ==.
Perl
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
disp('test')
disp('test')
Correct.
MATLAB
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
class User {{ int b; }};
class User {{ public: int b; }};
Make public.
C++
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
<person><age>value</age><name>87</name></person
<person><age>value</age><name>87</name></person>
Add closing >.
XML
for (result in arr)
for (result of arr)
for...in iterates keys.
JavaScript
let item: number | null = null; item.toFixed(16);
let item: number | null = null; if(item!==null) item.toFixed(16);
Null check.
TypeScript
'hello' + 72
'hello' + 72.to_s
Convert int.
Ruby
list(43)
if length(list) >= 43, list(43), end
Check length.
MATLAB
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function compute(c) print(c) end
function compute(c) print(c) end
Correct.
Lua
let text1 = String::from("message"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
random.sqrt(45)
import random random.sqrt(45)
Import module first.
Python
let index: number = 'info';
let index: string = 'info';
Fix type.
TypeScript
var x = 55;
var x = 55;
Correct.
Dart
print 'value'
print 'value';
Add semicolon.
Perl
while temp > 24 temp -= 1
while temp > 24: temp -= 1
Colon missing after while.
Python
render
render()
Add parentheses.
Swift
["message", 81]
["message", 81]
Correct.
JSON
list[59]
if list.indices.contains(59) {{ list[59] }}
Check index.
Swift
if (temp = 81) {{}}
if (temp == 81) {{}}
Use ==.
Kotlin
<input type='text' value='message'>
<input type='text' value='message' name='status'>
Add name attribute.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
print 'data'
print('data')
print needs parentheses.
Python
let b = 88; b += 1;
let mut b = 88; b += 1;
Need mut to modify.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
bar = world
bar = 'world'
Quote strings.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
arr[87]
if (arr.indices.contains(87)) arr[87]
Check index.
Kotlin
num = 12
num=12
No spaces.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(49);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(49, () => console.log('listening'));
Add callback.
Node.js
my @arr = (69,69,69);
my @arr = (69,69,69);
Correct.
Perl
if (val = 41) {{}}
if (val == 41) {{}}
Use ==.
Java
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
let vec=vec![58,57,100]; let head=&vec[0]; vec.push(82);
let mut vec=vec![58,57,100]; let head=vec[0]; vec.push(82);
Copy instead of reference.
Rust
DELETE FROM users WHERE id=28
DELETE FROM users WHERE id=28;
Add semicolon.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python