The following:
struct V
{
W w;
struct W
{
this(scope ref V v)
{
this.v = &v;
}
V* v;
}
}
void main()
{
V v;
}
Produces this:
Error: struct app.V no size because of forward reference
Expecting: to compile.
Error is also not pointing the line number the issue was suppose to be.
Work around:
1. Removing the "scope" keyword makes the program compile.
2. Changing W ctor signature to:
this(scope V* v)
{
this.v = v;
}
also makes it work.
Compiled with dmd 2.073.1 on win32
Comment #1 by syniurge — 2017-07-14T21:30:12Z
It's not specific to nested classes:
struct S {
S2 a;
}
struct S2 {
void foo(scope S s) { }
}
=> Error: struct S no size because of forward reference
Kinda related: issue 17548 was another bogus forward ref error originating from the same TypeStruct.hasPointers call in TypeFuntion.semantic (but as I understand it that call isn't the actual problem).
Comment #2 by dlang-bugzilla — 2017-07-15T06:12:04Z
Elle's example stopped working after https://github.com/dlang/dmd/pull/5897 but I don't know enough about scope whether know if this can be marked as a regression.
Comment #3 by bugzilla — 2017-08-31T06:33:35Z
This is a bit of a hopeless circular tangle. 'scope' is ignored if the type has no pointers. So S is checked for pointers. S.a is of type S2, which then must be checked for pointers. Checking S2 for pointers means evaluating each member to see if it is a field, which gets us back to looking at the 'scope'.
Not sure if this is reasonably fixable.
Comment #4 by radu.racariu — 2017-08-31T08:17:21Z
I think the original description is different than Elie's example.
For one, the argument is sent by ref - the issue I was describing is related to the interaction of 'scope' and 'ref'.
I expected that 'scope ref V' be the same as 'scope V*'
Comment #5 by radu.racariu — 2017-11-06T15:49:53Z
Just to point that "scope" is to blame here, removing "scope" from the inner stuct ctor like:
+++++++++++++++++++
struct V
{
W w;
struct W
{
this(/*scope*/ ref V v)
{
this.v = &v;
}
V* v;
}
}
void main()
{
V v;
}
+++++++++++++++++++
compiles without errors.
Comment #6 by robert.schadek — 2024-12-13T18:51:38Z