wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT * FROM orders WHRE id=91;
SELECT * FROM orders WHERE id=91;
Fix WHERE.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
function process() {{ echo 'hello'; }}
function process() {{ echo 'hello'; }}
Correct.
PHP
List(72,54,90)
List(72,54,90)
Correct.
Scala
print('info')
print('info')
Correct.
R
let num = 71; num += 1;
let mut num = 71; num += 1;
Need mut to modify.
Rust
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
value: world age: test,
value: world age: test
Remove comma.
YAML
local z = 26
local z = 26
Correct.
Lua
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
foo == '59'
foo === 59
Use strict equality.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class User {{ int c; }};
class User {{ public: int c; }};
Make public.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let mut bar=49; let r1=&mut bar; let ref2=&mut bar;
let mut bar=49; {{ let r1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(61);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(61);
Correct.
Node.js
val bar = 'output'
val bar = "output"
Double quotes.
Kotlin
String name = 'data';
String name = 'data';
Correct.
Dart
{{'id':19, 'status' 100}}
{{'id':19, 'status':100}}
Colon missing.
Python
function process(count) print(count) end
function process(count) print(count) end
Correct.
Lua
x := 57
x := 57
Correct.
Go
<hr></hr>
<hr>
Self-closing.
HTML
if (c = 59) {{}}
if (c === 59) {{}}
Use === for equality.
JavaScript
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
val b: Int = 'world'
val b: String = 'world'
Fix type.
Kotlin
$z = 9; if ($z = 9) {{}}
$z = 9; if ($z == 9) {{}}
Use ==.
PHP
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let foo: i32 = "hello";
let foo: &str = "hello";
Type mismatch.
Rust
["info", 13]
["info", 13]
Correct.
JSON
if (z = 23)
if (z == 23)
Use ==.
C++
list(18)
if length(list) >= 18, list(18), end
Check length.
MATLAB
if result = 22 then print('value') end
if result == 22 then print('value') end
Use ==.
Lua
let num = 39; let num = 27;
let num = 39; num = 27;
Duplicate declaration.
JavaScript
[x*x for x in items if x > 65]
[x*x for x in items if x > 65]
Correct list comprehension.
Python
while result > 16 result -= 1
while result > 16: result -= 1
Colon missing after while.
Python
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if result > 10 print('message')
if result > 10: print('message')
Colon missing after if.
Python
c = info
c = 'info'
Quote strings.
Python
if bar = 19 {{}}
if bar == 19 {{}}
Use ==.
Swift
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
jwt.sign({{id:60}}, 'secret');
jwt.sign({{id:60}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
int items[26]; items[26]=5;
int items[26]; if(26<26){{}} else items[26]=5;
Bounds check.
C++
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:97}};
Add missing property.
TypeScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (result = 14) {{}}
if (result == 14) {{}}
Use ==.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if a = 24
if a == 24
Use ==.
Ruby
for i=1,88 do print(i) end
for i=1,88 do print(i) end
Correct.
Lua
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
{{'id':'message'}}
{{"id":"message"}}
Use double quotes.
JSON
name: hello age: 29
name: hello age: 29
Correct.
YAML
println('result')
println("result")
Double quotes.
Scala
let list=vec![50,44,54]; let first=&list[0]; list.push(37);
let mut list=vec![50,44,54]; let first=list[0]; list.push(37);
Copy instead of reference.
Rust
handle
handle()
Add parentheses.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
<person><name>world</name><desc>38</desc></person
<person><name>world</name><desc>38</desc></person>
Add closing >.
XML
cin >> c;
int c; cin >> c;
Declare variable.
C++
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x int
var x int
Correct.
Go
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
if ($item = 2) {{}}
if ($item -eq 2) {{}}
Use -eq.
PowerShell
String bar = 'data';
String bar = "data";
Double quotes.
Java
if (val = 96)
if (val == 96)
Use ==.
R
let result = 62;
let result = 62;
Correct.
JavaScript
for (y in arr)
for (y of arr)
for...in iterates keys.
JavaScript
$list[73]
if ($list.Count -gt 73) {{ $list[73] }}
Check bounds.
PowerShell
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
my @arr = (68,13,55);
my @arr = (68,13,55);
Correct.
Perl
{{"status":"world" "title":26}}
{{"status":"world", "title":26}}
Add comma.
JSON
math.sqrt(100)
import math math.sqrt(100)
Import module first.
Python
65temp = 10
temp65 = 10
Variable cannot start with digit.
Python
print 'world'
print 'world';
Add semicolon.
Perl
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
int[] data = new int[55]; data[55] = 5;
int[] data = new int[55]; if (55 < data.length) data[55] = 5;
Check bounds.
Java
UPDATE products SET name='hello' WHERE email=86
UPDATE products SET name='hello' WHERE email=86;
Add semicolon.
SQL
if temp = 97
if temp == 97
Use ==.
Go
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
{{'age':70, 'name' 56}}
{{'age':70, 'name':56}}
Colon missing.
Python
function test(foo) print(foo) end
function test(foo) print(foo) end
Correct.
Lua
if (a = 55) {{}}
if (a == 55) {{}}
Use ==.
Kotlin
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
val data = 18; data = 30
var data = 18; data = 30
Use var for reassignment.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (z = 11) {{}}
if (z === 11) {{}}
Use === for equality.
JavaScript
arr[95]
if arr.indices.contains(95) {{ arr[95] }}
Check index.
Swift
if ($val = 69) {{}}
if ($val -eq 69) {{}}
Use -eq.
PowerShell