Bug 23354 – [REG master] object.d(393): Error: reference to stack allocated value returned by 'new F(1)' assigned to non-scope parameter 'lhs'

Status
RESOLVED
Resolution
REMIND
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-09-21T15:43:59Z
Last change time
2022-09-23T13:45:25Z
Keywords
rejects-valid, safe
Assigned to
No Owner
Creator
Iain Buclaw
See also
https://issues.dlang.org/show_bug.cgi?id=19812

Comments

Comment #0 by ibuclaw — 2022-09-21T15:43:59Z
$ dmd druntime/src/object.d -o- -unittest -preview=dip1000 druntime/src/object.d(393): Error: reference to stack allocated value returned by `new F(1)` assigned to non-scope parameter `lhs` druntime/src/object.d(393): Error: reference to stack allocated value returned by `new G(1)` assigned to non-scope parameter `rhs` Caused by https://github.com/dlang/dmd/pull/14367
Comment #1 by ibuclaw — 2022-09-21T21:39:54Z
Test extracted from druntime. Fails with -preview=dip1000, succeeds with -preview=dip1000 -checkaction=context. --- /// If same exact type => one call to method opEquals /// This test passes `@safe` because it defines a new opEquals with `@safe` @safe void unittest1() { class F { int flag; this(int flag) { this.flag = flag; } bool opEquals(const F o) const @safe nothrow pure { return flag == o.flag; } } assert(new F(0) == new F(0)); assert(!(new F(0) == new F(1))); } /// General case => symmetric calls to method opEquals @safe void unittest2() { int fEquals, gEquals; class Base { int flag; this(int flag) { this.flag = flag; } } class F : Base { this(int flag) { super(flag); } bool opEquals(const Base o) @safe { fEquals++; return flag == o.flag; } } class G : Base { this(int flag) { super(flag); } bool opEquals(const Base o) @safe { gEquals++; return flag == o.flag; } } assert(new F(1) == new G(1)); assert(fEquals == 1); assert(gEquals == 1); }
Comment #2 by ibuclaw — 2022-09-23T13:45:25Z
Regression PR has been reverted https://github.com/dlang/dmd/pull/14463 This needs to be checked again when re-fixing issue 19812.