Bug 20362 – dmd fails to infer scope parameter for delegate
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-11-06T15:44:53Z
Last change time
2020-02-06T05:44:39Z
Keywords
pull, safe
Assigned to
No Owner
Creator
Atila Neves
Comments
Comment #0 by atila.neves — 2019-11-06T15:44:53Z
With dmd 2.089.0, *without* using -preview=dip1000, this fails to compile:
--------------------
void stringify(scope void delegate(scope const char[]) sink) {
sink("oops");
}
void main() {
string str;
stringify((chars) {str ~= chars; });
}
--------------------
bug.d(7): Error: function bug.stringify(scope void delegate(scope const(char[])) sink) is not callable using argument types (void)
bug.d(7): cannot pass argument __lambda1 of type void to parameter scope void delegate(scope const(char[])) sink
It compiles successfully with -preview=dip1000. A workaround is to explicitly add `scope` to the `chars` parameter of the delegate, and then it compiles with and without -preview=dip1000.
This is blocking this PR:
https://github.com/dlang/dmd/pull/10506
Comment #1 by atila.neves — 2020-02-05T15:19:03Z
Note: the code was taken out of context, but the reason it's *really* important is that it occurs in Throwable.toString
Comment #2 by dlang-bot — 2020-02-05T15:44:16Z
@atilaneves updated dlang/dmd pull request #10506 "WIP (do not merge): Make `in` mean `scope const` in DIP1000" mentioning this issue:
- Non hacky way to get around issue 20362
https://github.com/dlang/dmd/pull/10506
Comment #3 by dlang-bot — 2020-02-05T17:55:33Z
@atilaneves created dlang/dmd pull request #10764 "Fix issue 20362 - always infer scope for lambdas" fixing this issue:
- Fix issue 20362 - always infer scope for lambdas
Before, scope was only inferred if -preview=dip1000
was used, now it always is.
https://github.com/dlang/dmd/pull/10764
Comment #4 by dlang-bot — 2020-02-06T05:44:39Z
dlang/dmd pull request #10764 "Fix issue 20362 - always infer scope for lambdas" was merged into master:
- ac32a33c1dfdeec2b24dda175cbb1fe87778c012 by Atila Neves:
Fix issue 20362 - always infer scope for lambdas
Before, scope was only inferred if -preview=dip1000
was used, now it always is.
https://github.com/dlang/dmd/pull/10764