Bug 20314 – passing const variables to `only` forces const range element type
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-10-24T12:17:48Z
Last change time
2019-11-22T02:29:27Z
Keywords
pull
Assigned to
No Owner
Creator
FeepingCreature
Comments
Comment #0 by default_357-line — 2019-10-24T12:17:48Z
Consider this code:
import std;
void main()
{
const string s = "foo", t = "bar";
auto range = only(s, t);
[range].joiner(only(", ")).join.writeln;
}
Since `only` takes its parameters by `auto ref`, the fact that s and t are `const string` forces `only` to have an `ElementType` of `const(string)`, which then breaks `joiner`.
There's no reason for `only` to be `auto ref`, since it copies its parameters anyways.
Comment #1 by dlang-bot — 2019-10-24T12:27:03Z
@FeepingCreature created dlang/phobos pull request #7253 "Fix issue 20314: pass `only` parameters by value" fixing this issue:
- Fix issue 20314: pass `only` parameters by value
https://github.com/dlang/phobos/pull/7253
Comment #2 by dlang-bot — 2019-11-22T02:29:27Z
dlang/phobos pull request #7253 "Fix issue 20314: pass `only` parameters by value" was merged into master:
- f806629e30c50bb920319685e89e3e2f58e73195 by Mathis Beer:
Fix issue 20314: pass `only` parameters by value
https://github.com/dlang/phobos/pull/7253