https://issues.dlang.org/show_bug.cgi?id=22270
Dennis <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |[email protected] Hardware|x86_64 |All Resolution|--- |INVALID OS|Linux |All --- Comment #1 from Dennis <[email protected]> --- Neither method gets `scope` inferred. If you remove the `new` in Bar (`scope bar = Bar;`) you'll get the same error for the struct. What's happening is that since `Bar` is a pointer, it gets dereferenced implicitly: ``` @safe void main() { scope Bar* bar = new Bar; (*bar).dummy; // dereference strips away the scope layer } ``` `dummy` can't escape the pointer `bar` since `this` is passed by `ref`. Escaping a pointer to a ref variable (`&this`) is fixed by https://github.com/dlang/dmd/pull/12812. The class case is not allowed since dummy can do this: ``` Foo globalFoo; class Foo { @safe void dummy() { globalFoo = this; } } ``` So they are not consistent because `struct` is a value type and `class` a reference type. --
