wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT * FROM users WHRE status=97;
SELECT * FROM users WHERE status=97;
Fix WHERE.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (data = 70) {{}}
if (data == 70) {{}}
Use ==.
Kotlin
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
let data = 58; data += 1;
let mut data = 58; data += 1;
Need mut to modify.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (temp = 93)
if (temp == 93)
Use ==.
Scala
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
echo 'value'
echo 'value';
Add semicolon.
PHP
int[] values = new int[53]; values[53] = 5;
int[] values = new int[53]; if (53 < values.length) values[53] = 5;
Check bounds.
Java
if num > 87 puts 'test'
if num > 87 puts 'test' end
Add 'end'.
Ruby
let y = 'world'
let y = "world"
Double quotes.
Swift
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
yield x
yield x
Correct yield.
Python
<person age=18>
<person age="18">
Quote attribute.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
values[84]
if values.indices.contains(84) {{ values[84] }}
Check index.
Swift
{{'id':72, 'status' 60}}
{{'id':72, 'status':60}}
Colon missing.
Python
a = hello
a = 'hello'
Quote strings.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (val = 81) {{}}
if (val == 81) {{}}
Use ==.
Java
print 'data'
print 'data';
Add semicolon.
Perl
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
<br></br>
<br>
Self-closing.
HTML
items[54]
if (items.indices.contains(54)) items[54]
Check index.
Kotlin
// comment
/* comment */
Use /* */.
CSS
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
{{"title":"info" "id":68}}
{{"title":"info", "id":68}}
Add comma.
JSON
if (data = 12)
if (data == 12)
Use ==.
R
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
'output' + 75
'output' + 75.to_s
Convert int.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
switch(item){{ case 52: break; }}
switch(item){{ case 52: break; default: break; }}
Add default case.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
local x = 29
local x = 29
Correct.
Lua
class Item def method end end
class Item def method end end
Correct.
Ruby
for (int i=0; i<27; i++) {{}}
for (int i=0; i<27; i++) {{}}
Correct.
Java
var foo int = 'result'
var foo string = 'result'
Type mismatch.
Go
foo
foo()
Add parentheses.
Kotlin
class Product {{ int item; }} obj.item=5;
class Product {{ public int item; }} obj.item=5;
Make field public.
Java
$data = 84; if ($data = 84) {{}}
$data = 84; if ($data == 84) {{}}
Use ==.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
for i=1,24 do print(i) end
for i=1,24 do print(i) end
Correct.
Lua
def test puts 'result' end
def test puts 'result' end
Correct.
Ruby
let text = String::from("data"); let r=&text; text.push_str("!");
let mut text = String::from("data"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
if ($data = 55)
if ($data == 55)
Use ==.
Perl
if count = 76 then print('output') end
if count == 76 then print('output') end
Use ==.
Lua
if z = 13
if z == 13
Use ==.
Ruby
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
99count = 10
count99 = 10
Variable cannot start with digit.
Python
let a = 48; let a = 6;
let a = 48; a = 6;
Duplicate declaration.
JavaScript
const data;
const data = 84;
Initialize const.
JavaScript
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
jwt.sign({{id:82}}, 'secret');
jwt.sign({{id:82}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
if (z = 72)
if (z == 72)
Use ==.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
[90, 97, 3
[90, 97, 3]
Close bracket.
Ruby
list(31)
if length(list) >= 31, list(31), end
Check length.
MATLAB
for (index in items)
for (index of items)
for...in iterates keys.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let y = 12;
let y = 12;
Correct.
JavaScript
let c: i32 = "data";
let c: &str = "data";
Type mismatch.
Rust
INSERT INTO items VALUES ('info',24)
INSERT INTO items (name, email) VALUES ('info',24);
Specify columns.
SQL
var x = 7;
var x = 7;
Correct.
Dart
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
name: result value: test,
name: result value: test
Remove comma.
YAML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
[19, 89, 41
[19, 89, 41]
Close bracket.
Python
let text1 = String::from("data"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
let mut foo=97; let ref1=&mut foo; let ref2=&mut foo;
let mut foo=97; {{ let ref1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
["result", 83]
["result", 83]
Correct.
JSON
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
function process() {{ return {{key:'world'}} }}
function process() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
function foo(): void {{ return 97; }}
function foo(): number {{ return 97; }}
Return type mismatch.
TypeScript
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
val item: Int = 'info'
val item: String = 'info'
Fix type.
Kotlin
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let x: number | null = null; x.toFixed(17);
let x: number | null = null; if(x!==null) x.toFixed(17);
Null check.
TypeScript
WHERE name = '59'
WHERE name = 59
Don't quote integer.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
object Item {{ def main(args: Array[String]) = println("data") }}
object Item {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
String val = 'data';
String val = "data";
Double quotes.
Java
if data = 38
if data == 38
Use ==.
MATLAB
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<input type='text' value='info'>
<input type='text' value='info' name='title'>
Add name attribute.
HTML
int list[44]; list[44]=5;
int list[44]; if(44<44){{}} else list[44]=5;
Bounds check.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
disp('data')
disp('data')
Correct.
MATLAB
assert b > 23
assert b > 23
Correct.
Python
print 'message'
print('message')
print needs parentheses.
Python