July 15, 2021
https://issues.dlang.org/show_bug.cgi?id=21912

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #9 from Dlang Bot <dlang-bot@dlang.rocks> ---
@dkorpel created dlang/dmd pull request #12880 "Fix issue 21912 - delegate assigned to return scope variable needs closure" fixing this issue:

- Fix issue 21912 - delegate assigned to return scope variable needs closure

https://github.com/dlang/dmd/pull/12880

--
July 22, 2021
https://issues.dlang.org/show_bug.cgi?id=21912

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #10 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #12880 "Fix issue 21912 - delegate assigned to return scope variable needs closure" was merged into stable:

- 12221d04c4c7259ebd7f7570e2555659142d8516 by dkorpel:
  Fix issue 21912 - delegate assigned to return scope variable needs closure

https://github.com/dlang/dmd/pull/12880

--
August 03, 2021
https://issues.dlang.org/show_bug.cgi?id=21912

--- Comment #11 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #12944 "Merge branch 'stable' into merge_master" was merged into master:

- f8d4e318a5bc8c71fe20b56ec9fc3f4400afe83d by Dennis:
  Fix issue 21912 - delegate assigned to return scope variable needs closure
(#12880)

https://github.com/dlang/dmd/pull/12944

--
December 22, 2021
https://issues.dlang.org/show_bug.cgi?id=21912

johanengelen@weka.io changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johanengelen@weka.io

--- Comment #12 from johanengelen@weka.io ---
I do not believe the linked PR a correct fix for the problem, and I do not agree (in all cases) with what the title of this bug report states. The linked PR fixes the problem of bad codegen, but over-constraints and limits correct use cases.

Whether a delegate assigned to return scope parameter needs a closure or not depends on what is done with the return value, that is exactly what the return attribute is for. The return attribute results in the return value being scope in the caller. If it the return value escapes from the caller, only then is a gc-allocated closure needed.

```
// This should compile fine, without gc allocation:
auto invoker(Dlg)(scope Dlg dlg) { return dlg; }  // <--- `return` is infered
on parameter
@nogc void f(int x) { invoker({x++;}); }  // <--- return value is discarded,
hence does not escape the scope.

// This should compile fine, without gc allocation:
auto invoker(Dlg)(scope Dlg dlg) { return dlg; }  // <--- `return` is infered
on parameter
@nogc void f(int x) {
    scope inv = invoker({x++;});
    inv();
}

// This should give a compile error:
auto invoker(Dlg)(scope Dlg dlg) { return dlg; }
@nogc auto f(int x) { return invoker({x++;}); }  // <--- Error: `scope`
variable escapes scope OR allocation in @nogc
```

The breakage of the fix is perhaps larger than expected because return is still infered on template parameters, without -dip1000.

--
June 22, 2022
https://issues.dlang.org/show_bug.cgi?id=21912

--- Comment #13 from johanengelen@weka.io ---
Filed new issue for the above. https://issues.dlang.org/show_bug.cgi?id=23204

--
1 2
Next ›   Last »