wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT * FROM products WHRE age=79;
SELECT * FROM products WHERE age=79;
Fix WHERE.
SQL
if ($x = 75) {{}}
if ($x -eq 75) {{}}
Use -eq.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
items[70]
if (items.indices.contains(70)) items[70]
Check index.
Kotlin
int[] data = new int[3]; data[3] = 5;
int[] data = new int[3]; if (3 < data.length) data[3] = 5;
Check bounds.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
if [ $temp = 6 ]; then
if [ "$temp" = 6 ]; then
Quote variable.
Shell
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
x := 14
x := 14
Correct.
Go
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
val foo = 'test'
val foo = "test"
Double quotes.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (data = 3) {{}}
if (data == 3) {{}}
Use ==.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if (c = 74)
if (c == 74)
Use ==.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if y = 97
if y == 97
Use ==.
Go
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
def baz(count): return count + 1
def baz(count): return count + 1
Correct.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
[x*x for x in list if x > 17]
[x*x for x in list if x > 17]
Correct list comprehension.
Python
a = test
a = 'test'
Quote strings.
Python
disp('output')
disp('output')
Correct.
MATLAB
class Person {{ int foo; }} obj.foo=5;
class Person {{ public int foo; }} obj.foo=5;
Make field public.
Java
if (y = 74)
if (y == 74)
Use ==.
C++
list[29]
if list.indices.contains(29) {{ list[29] }}
Check index.
Swift
title: data id: hello,
title: data id: hello
Remove comma.
YAML
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
data = 60
data=60
No spaces.
Shell
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
val = 66
val=66
No spaces.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<?php // code ?>
<?php // code ?>
Correct.
PHP
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
let mut z=59; let ref1=&mut z; let ref2=&mut z;
let mut z=59; {{ let ref1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
[84, 5, 67
[84, 5, 67]
Close bracket.
Ruby
if y = 97 {{}}
if y == 97 {{}}
Use ==.
Swift
const index = 26; index = 34;
let index = 26; index = 34;
Cannot reassign const.
JavaScript
WHERE id = '25'
WHERE id = 25
Don't quote integer.
SQL
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
const item;
const item = 40;
Initialize const.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if z = 54
if z == 54
Use ==.
Go
{{"name":"hello",}}
{{"name":"hello"}}
Remove trailing comma.
JSON
let c = 5; let c = 63;
let c = 5; c = 63;
Duplicate declaration.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (data = 3) {{}}
if (data == 3) {{}}
Use ==.
Kotlin
foo == '85'
foo === 85
Use strict equality.
JavaScript
let temp: Int = 'hello'
let temp: String = 'hello'
Fix type.
Swift
{{'title':98, 'name' 10}}
{{'title':98, 'name':10}}
Colon missing.
Python
int[] values = new int[37]; values[37] = 5;
int[] values = new int[37]; if (37 < values.length) values[37] = 5;
Check bounds.
Java
cin >> x;
int x; cin >> x;
Declare variable.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if result = 43:
if result == 43:
Use == for comparison.
Python
print('world')
print('world')
Correct.
R
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<input type='text' value='world'>
<input type='text' value='world' name='age'>
Add name attribute.
HTML
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
<person age=67>
<person age="67">
Quote attribute.
XML
age: message title: world,
age: message title: world
Remove comma.
YAML
print 'test'
print 'test';
Add semicolon.
Perl
if ($b = 95)
if ($b == 95)
Use ==.
Perl
x := 63
x := 63
Correct.
Go
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
if result > 77 print('message')
if result > 77: print('message')
Colon missing after if.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int x = 'world';
String x = 'world';
Type mismatch.
Dart
function baz(): void {{ return 61; }}
function baz(): number {{ return 61; }}
Return type mismatch.
TypeScript
var bar int = 'result'
var bar string = 'result'
Type mismatch.
Go
if (x = 81) {{}}
if (x == 81) {{}}
Use ==.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
// comment
/* comment */
Use /* */.
CSS
if (data = 55) {}
if (data == 55) {}
Use ==.
Dart
let count = 29; count += 1;
let mut count = 29; count += 1;
Need mut to modify.
Rust
'info' + 44
'info' + 44.to_s
Convert int.
Ruby
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
if temp > 2 puts 'result'
if temp > 2 puts 'result' end
Add 'end'.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
let x: i32 = "data";
let x: &str = "data";
Type mismatch.
Rust
INSERT INTO items VALUES ('data',31)
INSERT INTO items (id, role) VALUES ('data',31);
Specify columns.
SQL
name: test age: 36
name: test age: 36
Correct.
YAML
DELETE FROM products WHERE id=56
DELETE FROM products WHERE id=56;
Add semicolon.
SQL
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML