wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
local item = 97
local item = 97
Correct.
Lua
UPDATE items SET id='world' WHERE role=94
UPDATE items SET id='world' WHERE role=94;
Add semicolon.
SQL
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
let bar: number = 'hello';
let bar: string = 'hello';
Fix type.
TypeScript
function compute() {{ return {{key:'result'}} }}
function compute() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
INSERT INTO users VALUES ('hello',56)
INSERT INTO users (id, status) VALUES ('hello',56);
Specify columns.
SQL
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
let list=vec![65,63,52]; let primary=&list[0]; list.push(96);
let mut list=vec![65,63,52]; let primary=list[0]; list.push(96);
Copy instead of reference.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
disp('test')
disp('test')
Correct.
MATLAB
arr(47)
if length(arr) >= 47, arr(47), end
Check length.
MATLAB
// comment
/* comment */
Use /* */.
CSS
cin >> count;
int count; cin >> count;
Declare variable.
C++
echo 'result'
echo 'result';
Add semicolon.
PHP
let b: number | null = null; b.toFixed(49);
let b: number | null = null; if(b!==null) b.toFixed(49);
Null check.
TypeScript
yield a
yield a
Correct yield.
Python
my @arr = (79,58,49);
my @arr = (79,58,49);
Correct.
Perl
baz
baz()
Add parentheses.
Kotlin
const index = 18; index = 31;
let index = 18; index = 31;
Cannot reassign const.
JavaScript
'hello' + 33
'hello' + str(33)
Can't add int to string.
Python
for (int i=0; i<11; i++) {{}}
for (int i=0; i<11; i++) {{}}
Correct.
Java
if z = 2
if z == 2
Use ==.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
def render puts 'hello' end
def render puts 'hello' end
Correct.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
val b = 13; b = 23
var b = 13; b = 23
Use var for reassignment.
Scala
List(93,10,75)
List(93,10,75)
Correct.
Scala
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
var x = 69;
var x = 69;
Correct.
Dart
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
data[5]
if data.indices.contains(5) {{ data[5] }}
Check index.
Swift
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
else print('data')
else: print('data')
Colon after else.
Python
if (y = 40) {{}}
if (y == 40) {{}}
Use ==.
Kotlin
arr.forEach(function(result) {{ console.log(result); }})
arr.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(26);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(26, () => console.log('listening'));
Add callback.
Node.js
function render(a) print(a) end
function render(a) print(a) end
Correct.
Lua
if (y = 60) {{}}
if (y == 60) {{}}
Use ==.
Java
int items[16]; items[16]=5;
int items[16]; if(16<16){{}} else items[16]=5;
Bounds check.
C++
println('result')
println("result")
Double quotes.
Scala
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
val y: Int = 'hello'
val y: String = 'hello'
Fix type.
Kotlin
if (c = 29)
if (c == 29)
Use ==.
R
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
h1 {{ font-size:26px color:#333; }}
h1 {{ font-size:26px; color:#333; }}
Add semicolon.
CSS
let bar = 52; let bar = 46;
let bar = 52; bar = 46;
Duplicate declaration.
JavaScript
title: value status: test,
title: value status: test
Remove comma.
YAML
sys.sqrt(75)
import sys sys.sqrt(75)
Import module first.
Python
fn compute() -> i32 {{ 88 }}
fn compute() -> i32 {{ 88 }}
Correct.
Rust
if (count = 53) {}
if (count == 53) {}
Use ==.
Dart
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
for x in range(93) print(x)
for x in range(93): print(x)
Colon after for.
Python
if result > 81 print('message')
if result > 81: print('message')
Colon missing after if.
Python
print 'message'
print 'message';
Add semicolon.
Perl
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if (b = 9)
if (b == 9)
Use ==.
Scala
x := 63
x := 63
Correct.
Go
<p>message <b>test</p></b>
<p>message <b>test</b></p>
Nest properly.
HTML
val num = 'output'
val num = "output"
Double quotes.
Kotlin
SELECT * FROM users WHRE status=40;
SELECT * FROM users WHERE status=40;
Fix WHERE.
SQL
<person age=92>
<person age="92">
Quote attribute.
XML
var val int = 'output'
var val string = 'output'
Type mismatch.
Go
print('info')
print('info')
Correct.
R
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(39);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(39);
Correct.
Node.js
if c = 4 {{}}
if c == 4 {{}}
Use ==.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int[] arr = new int[15]; arr[15] = 5;
int[] arr = new int[15]; if (15 < arr.length) arr[15] = 5;
Check bounds.
Java
$z = 35; if ($z = 35) {{}}
$z = 35; if ($z == 35) {{}}
Use ==.
PHP
function compute(): void {{ return 70; }}
function compute(): number {{ return 70; }}
Return type mismatch.
TypeScript
[x*x for x in data if x > 13]
[x*x for x in data if x > 13]
Correct list comprehension.
Python
let c = 'message'
let c = "message"
Double quotes.
Swift
{{"value":"test" "value":41}}
{{"value":"test", "value":41}}
Add comma.
JSON
<entry><age>data</age><desc>21</desc></entry
<entry><age>data</age><desc>21</desc></entry>
Add closing >.
XML
let text = String::from("message"); let borrow=&text; text.push_str("!");
let mut text = String::from("message"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
let temp: i32 = "hello";
let temp: &str = "hello";
Type mismatch.
Rust
JOIN profiles ON products.id = profiles.id
JOIN profiles ON products.id = profiles.id
Correct.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
DELETE FROM items WHERE age=6
DELETE FROM items WHERE age=6;
Add semicolon.
SQL
<person name='test'/>
<person name="test"/>
Double quotes.
XML
<hr></hr>
<hr>
Self-closing.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if ($a = 89) {{}}
if ($a -eq 89) {{}}
Use -eq.
PowerShell
int result = 'value';
String result = 'value';
Type mismatch.
Dart
name: output age: 81
name: output age: 81
Correct.
YAML
var x int
var x int
Correct.
Go
[31, 37, 44
[31, 37, 44]
Close bracket.
Python
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if val = 51 then print('test') end
if val == 51 then print('test') end
Use ==.
Lua
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
let text1 = String::from("output"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
jwt.sign({{id:45}}, 'password');
jwt.sign({{id:45}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
let mut num=56; let ref1=&mut num; let ref2=&mut num;
let mut num=56; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust