Why can't 'scope' be inferred here?
Paul Backus
snarwin at gmail.com
Fri Jun 21 12:50:10 UTC 2019
The following code fails to compile with -dip1000:
struct Inner(T) {
T value;
this(ref T value) { this.value = value; }
}
struct Outer(T) {
Inner!T inner;
void opAssign(ref T rhs) { inner = Inner!T(rhs); }
}
@safe void main() {
int x;
int* p = &x;
Outer!(int*) o;
o = p;
}
(Interactive: https://run.dlang.io/is/yYTReh)
Changing Inner's constructor to take a `scope ref T value` fixes
the error. But since Inner is a template, and the body of the
constructor is available to the compiler, shouldn't it be able to
infer the `scope` attribute?
More information about the Digitalmars-d-learn
mailing list