Bug 17512 – [REG 2.073] [DIP1000] Error on bad interplay of 'auto ref' and 'return' attribute deduction.

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-06-15T21:46:21Z
Last change time
2018-03-26T03:55:54Z
Keywords
industry, safe
Assigned to
No Owner
Creator
johanengelen
See also
https://issues.dlang.org/show_bug.cgi?id=18661

Comments

Comment #0 by johanengelen — 2017-06-15T21:46:21Z
Testcase: ``` struct A(T) { T _value; bool _hasValue; auto ref getOr(T alternativeValue) { return _hasValue ? _value : alternativeValue; } } A!int a; ``` DMD 2.073 fails with: > dmd -c testcase.d -o- testcase.d(7): Error: function has 'return' but does not return any indirections testcase.d(13): Error: template instance testcase.A!int error instantiating DMD 2.074: > dmd -c testcase.d -o- testcase.d(7): Error: function type 'pure nothrow @nogc return @safe int(int alternativeValue)' has 'return' but does not return any indirections testcase.d(13): Error: template instance manhole.A!int error instantiating DMD 2.072.2 compiles it fine.
Comment #1 by johanengelen — 2017-06-15T22:00:31Z
Wait... is this even valid code? It's escaping a reference to a local value. The error message could be much improved.
Comment #2 by johanengelen — 2017-06-15T22:12:40Z
Or... it _is_ a frontend bug, as the compiler should deduce that the return type cannot be 'ref'. It correctly deduces that ("does not return any indirections") but because it added "return" function attribute earlier, the error happens. (sorry for the confusion, not thinking clearly)
Comment #3 by dlang-bugzilla — 2017-06-18T06:45:07Z
FWIW, the error starts appearing after https://github.com/dlang/dmd/pull/6452
Comment #4 by chilli — 2018-02-15T10:07:21Z
Another error example from phobos (-dip1000, DMD64 D Compiler v2.078.2): https://github.com/dlang/phobos/blob/master/std/range/package.d std/range/package.d(1738) [referring to roundRobin.Result. @property auto ref front()]: Error: function type pure nothrow @nogc @property return @safe int() has return but does not return any indirections
Comment #5 by bugzilla — 2018-03-11T21:34:27Z
Comment #6 by github-bugzilla — 2018-03-16T05:18:00Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/56b770c60cb301b46a287e201fb4934f6551414b fix Issue 17512 - [REG 2.073] [DIP1000] Error on bad interplay of 'auto ref' and 'return' attribute deduction https://github.com/dlang/dmd/commit/abd5267fc35169111fac9a9fa919195c4c9a7762 Merge pull request #8001 from WalterBright/fix17512 fix Issue 17512 - [REG 2.073] [DIP1000] Error on bad interplay of 'au…
Comment #7 by john.loughran.colvin — 2018-03-22T19:53:46Z
This seems to not to be totally resolved in very similar cases: struct S0(T) { int a; auto ref immutable(int) getA() { return a; } } alias A = S0!int; test.d(4): Error: function type pure nothrow @nogc return @safe immutable(int)() has return but does not return any indirections
Comment #8 by bugzilla — 2018-03-26T03:55:54Z
(In reply to John Colvin from comment #7) > This seems to not to be totally resolved in very similar cases: Please do not reopen bugs because more issues come up. File a new issue instead. Otherwise, bugzilla loses the 1:1 correlation between PRs and issues, and becomes much less manageable. I refiled it as https://issues.dlang.org/show_bug.cgi?id=18661 Closing this again.