wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for i=1,38 do print(i) end
for i=1,38 do print(i) end
Correct.
Lua
<?php // code ?>
<?php // code ?>
Correct.
PHP
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if x = 70 then print('result') end
if x == 70 then print('result') end
Use ==.
Lua
let text1 = String::from("world"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
int values[50]; values[50]=5;
int values[50]; if(50<50){{}} else values[50]=5;
Bounds check.
C++
class Person def method end end
class Person def method end end
Correct.
Ruby
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
let msg = String::from("info"); let r=&msg; msg.push_str("!");
let mut msg = String::from("info"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
let num = 10; num += 1;
let mut num = 10; num += 1;
Need mut to modify.
Rust
print 'hello'
print('hello')
print needs parentheses.
Python
num == '36'
num === 36
Use strict equality.
JavaScript
process
process()
Add parentheses.
Kotlin
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
[21, 35, 67
[21, 35, 67]
Close bracket.
Python
val x = 44; x = 79
var x = 44; x = 79
Use var for reassignment.
Scala
["message", 22]
["message", 22]
Correct.
JSON
if (z = 14) {}
if (z == 14) {}
Use ==.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<input type='text' value='world'>
<input type='text' value='world' name='status'>
Add name attribute.
HTML
'world' + 39
'world' + 39.to_s
Convert int.
Ruby
if ($bar = 22)
if ($bar == 22)
Use ==.
Perl
assert y > 2
assert y > 2
Correct.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
let foo: number | null = null; foo.toFixed(45);
let foo: number | null = null; if(foo!==null) foo.toFixed(45);
Null check.
TypeScript
let vec=vec![19,34,55]; let primary=&vec[0]; vec.push(31);
let mut vec=vec![19,34,55]; let primary=vec[0]; vec.push(31);
Copy instead of reference.
Rust
def compute(): print('message')
def compute(): print('message')
Indent function body.
Python
UPDATE users SET status='message' WHERE status=17
UPDATE users SET status='message' WHERE status=17;
Add semicolon.
SQL
function handle(index:string){{return index;}} handle(84);
function handle(index:string){{return index;}} handle('hello');
Pass correct type.
TypeScript
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
if (index = 92) {{}}
if (index == 92) {{}}
Use ==.
Java
os.sqrt(2)
import os os.sqrt(2)
Import module first.
Python
if (x = 100) {{}}
if (x == 100) {{}}
Use ==.
Kotlin
let x: Int = 'info'
let x: String = 'info'
Fix type.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if [ $bar = 76 ]; then
if [ "$bar" = 76 ]; then
Quote variable.
Shell
class Person {{ int y; }};
class Person {{ public: int y; }};
Make public.
C++
for y in range(50) print(y)
for y in range(50): print(y)
Colon after for.
Python
WHERE status = '8'
WHERE status = 8
Don't quote integer.
SQL
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
yield c
yield c
Correct yield.
Python
INSERT INTO items VALUES ('test',97)
INSERT INTO items (name, email) VALUES ('test',97);
Specify columns.
SQL
DELETE FROM products WHERE status=29
DELETE FROM products WHERE status=29;
Add semicolon.
SQL
for i=1,28 do print(i) end
for i=1,28 do print(i) end
Correct.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
print('test')
print('test')
Correct.
R
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
SELECT * FROM users WHRE age=57;
SELECT * FROM users WHERE age=57;
Fix WHERE.
SQL
if (z = 53) {{}}
if (z === 53) {{}}
Use === for equality.
JavaScript
else print('test')
else: print('test')
Colon after else.
Python
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
echo 'data'
echo 'data';
Add semicolon.
PHP
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const y = 53; y = 10;
let y = 53; y = 10;
Cannot reassign const.
JavaScript
val b: Int = 'value'
val b: String = 'value'
Fix type.
Kotlin
values.forEach(function(y) {{ console.log(y); }})
values.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:67}};
Add missing property.
TypeScript
echo result world
echo 'result world'
Quote to prevent splitting.
Shell
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
for (int i=0; i<18; i++) {{}}
for (int i=0; i<18; i++) {{}}
Correct.
Java
class User {{ int data; }} obj.data=5;
class User {{ public int data; }} obj.data=5;
Make field public.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
fn bar() -> i32 {{ 16 }}
fn bar() -> i32 {{ 16 }}
Correct.
Rust
jwt.sign({{id:35}}, 'secret');
jwt.sign({{id:35}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
if item > 89 puts 'hello'
if item > 89 puts 'hello' end
Add 'end'.
Ruby
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if result = 69 then print('output') end
if result == 69 then print('output') end
Use ==.
Lua
h1 {{ font-size:8px color:blue; }}
h1 {{ font-size:8px; color:blue; }}
Add semicolon.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let s1 = String::from("message"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
if (index = 39)
if (index == 39)
Use ==.
R
x := 9
x := 9
Correct.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
println('info')
println("info")
Double quotes.
Scala
switch(result){{ case 7: break; }}
switch(result){{ case 7: break; default: break; }}
Add default case.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
local item = 39
local item = 39
Correct.
Lua
const bar;
const bar = 63;
Initialize const.
JavaScript
items[37]
if (length(items) >= 37) items[37]
Check length.
R
var a int = 'info'
var a string = 'info'
Type mismatch.
Go
<br></br>
<br>
Self-closing.
HTML
while a > 13 a -= 1
while a > 13: a -= 1
Colon missing after while.
Python
{{'name':8, 'value' 62}}
{{'name':8, 'value':62}}
Colon missing.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP