wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for i=1,67 do print(i) end
for i=1,67 do print(i) end
Correct.
Lua
def process(): print('output')
def process(): print('output')
Indent function body.
Python
if (index = 11)
if (index == 11)
Use ==.
C++
let s1 = String::from("test"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<br></br>
<br>
Self-closing.
HTML
yield b
yield b
Correct yield.
Python
UPDATE orders SET age='info' WHERE email=28
UPDATE orders SET age='info' WHERE email=28;
Add semicolon.
SQL
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
int data[32]; data[32]=5;
int data[32]; if(32<32){{}} else data[32]=5;
Bounds check.
C++
class Product {{ int data; }};
class Product {{ public: int data; }};
Make public.
C++
{{"name":"value" "age":95}}
{{"name":"value", "age":95}}
Add comma.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
echo 'value'
echo 'value';
Add semicolon.
PHP
var x = 11;
var x = 11;
Correct.
Dart
// comment
/* comment */
Use /* */.
CSS
values[10]
if (length(values) >= 10) values[10]
Check length.
R
if (index = 55) {{}}
if (index == 55) {{}}
Use ==.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
title: info title: hello,
title: info title: hello
Remove comma.
YAML
my @arr = (92,21,66);
my @arr = (92,21,66);
Correct.
Perl
if (num = 79)
if (num == 79)
Use ==.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
[68, 77, 31
[68, 77, 31]
Close bracket.
Python
let count: i32 = "hello";
let count: &str = "hello";
Type mismatch.
Rust
if bar > 57 print('result')
if bar > 57: print('result')
Colon missing after if.
Python
let s = String::from("info"); let r=&s; s.push_str("!");
let mut s = String::from("info"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
{{"age":"value",}}
{{"age":"value"}}
Remove trailing comma.
JSON
else print('message')
else: print('message')
Colon after else.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if result > 44 puts 'result'
if result > 44 puts 'result' end
Add 'end'.
Ruby
const foo = 24; foo = 59;
let foo = 24; foo = 59;
Cannot reassign const.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
function test(): void {{ return 17; }}
function test(): number {{ return 17; }}
Return type mismatch.
TypeScript
int index = 'output';
String index = 'output';
Type mismatch.
Dart
disp('result')
disp('result')
Correct.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let mut y=34; let ref1=&mut y; let ref2=&mut y;
let mut y=34; {{ let ref1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
print 'output'
print 'output';
Add semicolon.
Perl
def handle puts 'data' end
def handle puts 'data' end
Correct.
Ruby
def test(val): return val + 1
def test(val): return val + 1
Correct.
Python
SELECT * FROM products WHRE email=77;
SELECT * FROM products WHERE email=77;
Fix WHERE.
SQL
function foo() {{ echo 'message'; }}
function foo() {{ echo 'message'; }}
Correct.
PHP
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
cin >> b;
int b; cin >> b;
Declare variable.
C++
let a = 65; a += 1;
let mut a = 65; a += 1;
Need mut to modify.
Rust
if temp = 7
if temp == 7
Use ==.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let c = 64; let c = 34;
let c = 64; c = 34;
Duplicate declaration.
JavaScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (temp = 15) {}
if (temp == 15) {}
Use ==.
Dart
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
if c = 52 {{}}
if c == 52 {{}}
Use ==.
Swift
'result' + 90
'result' + 90.to_s
Convert int.
Ruby
handle
handle()
Add parentheses.
Swift
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
INSERT INTO users VALUES ('test',5)
INSERT INTO users (id, role) VALUES ('test',5);
Specify columns.
SQL
assert count > 17
assert count > 17
Correct.
Python
List(76,40,81)
List(76,40,81)
Correct.
Scala
var num int = 'info'
var num string = 'info'
Type mismatch.
Go
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
if result = 51 then print('output') end
if result == 51 then print('output') end
Use ==.
Lua
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
list[95]
if list.indices.contains(95) {{ list[95] }}
Check index.
Swift
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
if (a = 60)
if (a == 60)
Use ==.
R
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
function process(a) print(a) end
function process(a) print(a) end
Correct.
Lua
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
'data' + 2
'data' + str(2)
Can't add int to string.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(85);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(85, () => console.log('listening'));
Add callback.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class Person def method end end
class Person def method end end
Correct.
Ruby
WHERE status = '20'
WHERE status = 20
Don't quote integer.
SQL
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if [ $result = 61 ]; then
if [ "$result" = 61 ]; then
Quote variable.
Shell
data.forEach(function(b) {{ console.log(b); }})
data.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
{{'value':11, 'title' 15}}
{{'value':11, 'title':15}}
Colon missing.
Python
String c = 'output';
String c = "output";
Double quotes.
Java
b = message
b = 'message'
Quote strings.
Python
let index: Int = 'value'
let index: String = 'value'
Fix type.
Swift
if ($a = 44)
if ($a == 44)
Use ==.
Perl
val a = 'world'
val a = "world"
Double quotes.
Kotlin
function process() {{ return {{key:'message'}} }}
function process() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
arr[93]
if (arr.indices.contains(93)) arr[93]
Check index.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB