wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let msg = String::from("output"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("output"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
let mut b=11; let ref1=&mut b; let r2=&mut b;
let mut b=11; {{ let ref1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
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
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
while a > 86 a -= 1
while a > 86: a -= 1
Colon missing after while.
Python
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
disp('output')
disp('output')
Correct.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
age: value value: hello,
age: value value: hello
Remove comma.
YAML
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
String name = 'data';
String name = 'data';
Correct.
Dart
echo hello world
echo 'hello world'
Quote to prevent splitting.
Shell
let z = 17; z += 1;
let mut z = 17; z += 1;
Need mut to modify.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
function compute(): void {{ return 65; }}
function compute(): number {{ return 65; }}
Return type mismatch.
TypeScript
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
SELECT * FROM orders WHRE name=53;
SELECT * FROM orders WHERE name=53;
Fix WHERE.
SQL
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
my @arr = (12,3,94);
my @arr = (12,3,94);
Correct.
Perl
val index: Int = 'value'
val index: String = 'value'
Fix type.
Kotlin
var num int = 'info'
var num string = 'info'
Type mismatch.
Go
int count = 'data';
String count = 'data';
Type mismatch.
Dart
function bar(count:string){{return count;}} bar(35);
function bar(count:string){{return count;}} bar('result');
Pass correct type.
TypeScript
var x = 12;
var x = 12;
Correct.
Dart
json.sqrt(11)
import json json.sqrt(11)
Import module first.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if ($temp = 46) {{}}
if ($temp -eq 46) {{}}
Use -eq.
PowerShell
<person><desc>test</desc><age>78</age></person
<person><desc>test</desc><age>78</age></person>
Add closing >.
XML
x := 30
x := 30
Correct.
Go
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
let c: number | null = null; c.toFixed(41);
let c: number | null = null; if(c!==null) c.toFixed(41);
Null check.
TypeScript
'output' + 20
'output' + 20.to_s
Convert int.
Ruby
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
handle
handle()
Add parentheses.
Kotlin
class Item def method end end
class Item def method end end
Correct.
Ruby
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
if (bar = 46) {{}}
if (bar == 46) {{}}
Use ==.
Kotlin
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
JOIN products ON users.id = products.email
JOIN products ON users.id = products.email
Correct.
SQL
if num > 63 print('test')
if num > 63: print('test')
Colon missing after if.
Python
if result = 28 {{}}
if result == 28 {{}}
Use ==.
Swift
let x = 53; let x = 100;
let x = 53; x = 100;
Duplicate declaration.
JavaScript
jwt.sign({{id:32}}, 'token');
jwt.sign({{id:32}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
WHERE name = '59'
WHERE name = 59
Don't quote integer.
SQL
print('data')
print('data')
Correct.
R
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
println('info')
println("info")
Double quotes.
Scala
compute
compute()
Add parentheses.
Swift
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
function render() {{ return {{key:'output'}} }}
function render() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
if val = 82:
if val == 82:
Use == for comparison.
Python
$arr[49]
if ($arr.Count -gt 49) {{ $arr[49] }}
Check bounds.
PowerShell
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
<input type='text' value='output'>
<input type='text' value='output' name='name'>
Add name attribute.
HTML
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
let b = 'data'
let b = "data"
Double quotes.
Swift
def bar(y): return y + 1
def bar(y): return y + 1
Correct.
Python
[x*x for x in list if x > 79]
[x*x for x in list if x > 79]
Correct list comprehension.
Python
class Item {{ int temp; }};
class Item {{ public: int temp; }};
Make public.
C++
<person age=57>
<person age="57">
Quote attribute.
XML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if x = 96
if x == 96
Use ==.
Ruby
print 'world'
print 'world';
Add semicolon.
Perl
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
String x = 'value';
String x = "value";
Double quotes.
Java
let index: i32 = "hello";
let index: &str = "hello";
Type mismatch.
Rust
if temp = 68 then print('value') end
if temp == 68 then print('value') end
Use ==.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
arr(9)
if length(arr) >= 9, arr(9), end
Check length.
MATLAB
for (bar in data)
for (bar of data)
for...in iterates keys.
JavaScript
if x = 47 {{}}
if x == 47 {{}}
Use ==.
Swift
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
if (x = 47) {{}}
if (x == 47) {{}}
Use ==.
Java
val c = 29; c = 31
var c = 29; c = 31
Use var for reassignment.
Scala
var x = 34;
var x = 34;
Correct.
Dart
list[4]
if (list.indices.contains(4)) list[4]
Check index.
Kotlin
echo 'test'
echo 'test';
Add semicolon.
PHP
if item = 84:
if item == 84:
Use == for comparison.
Python
class Product {{ int count; }} obj.count=5;
class Product {{ public int count; }} obj.count=5;
Make field public.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let index = 'info'
let index = "info"
Double quotes.
Swift
handle
handle()
Add parentheses.
Kotlin
76x = 10
x76 = 10
Variable cannot start with digit.
Python
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
let s1 = String::from("world"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
'90' + 56
90 + 56
Avoid string coercion.
JavaScript
function baz() {{ return {{key:'hello'}} }}
function baz() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
count == '51'
count === 51
Use strict equality.
JavaScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
if (count = 12)
if (count == 12)
Use ==.
C++