D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20362 - dmd fails to infer scope parameter for delegate
Summary: dmd fails to infer scope parameter for delegate
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull, safe
Depends on:
Blocks:
 
Reported: 2019-11-06 15:44 UTC by Atila Neves
Modified: 2020-02-06 05:44 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Atila Neves 2019-11-06 15:44:53 UTC
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 Atila Neves 2020-02-05 15:19:03 UTC
Note: the code was taken out of context, but the reason it's *really* important is that it occurs in Throwable.toString
Comment 2 Dlang Bot 2020-02-05 15:44:16 UTC
@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 Dlang Bot 2020-02-05 17:55:33 UTC
@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 Dlang Bot 2020-02-06 05:44:39 UTC
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