Comment #0 by bus_dlangzilla — 2018-08-27T04:39:36Z
struct Foo(T)
{
import std.traits: hasElaborateDestructor;
static if(hasElaborateDestructor!A) {}
}
struct A
{
B b;
}
struct B
{
// Error: struct `test.A` no size because of forward reference
Foo!(A)[] arr;
}
Comment #1 by bus_dlangzilla — 2018-08-27T04:41:32Z
Same result if "Foo!(A)[]" is changed to "Foo!(A)*"
Comment #2 by dhasenan — 2018-08-27T05:58:22Z
Reduced testcase that doesn't rely on phobos:
---
struct Foo(T)
{
alias F = typeof(T.tupleof);
}
struct B
{
// Error: struct `test.A` no size because of forward reference
Foo!(B)[] arr;
}
---
In typesem.d:3495, we call `mt.sym.size(e.loc);`. We use it as a shortcut to run semantic analysis on the type before getting the type tuple. This results in a bad error message, but it's straightforward to improve that error message.
Obviously, some stuff won't fly, so we can't glibly leave everything to a later semantic step. The fix required to make this work fully is to run minimal semantic analysis during tupleof, lazily finish that semantic analysis, and only error out then.
That would catch the obvious problem of:
---
struct Foo
{
static if (!hasElaborateDestructor!B) ~this() {}
}
struct B
{
Foo foo;
}
---
But would let the original example compile.
Unfortunately, that level of change is beyond me at the moment.
Comment #4 by github-bugzilla — 2018-09-06T13:10:17Z
Commit pushed to master at https://github.com/dlang/dmdhttps://github.com/dlang/dmd/commit/379446e0f059d25e8da909bf5373f861af5069c5
Improve diagnostic with forward references and tupleof
When using tupleof in a template forward reference context, dmd
emitted an error message complaining that it could not calculate the
size of the struct. This happened even in cases when the size was not
obviously required.
To make things less confusing and workarounds more obvious, the error
message now explicitly says that tupleof is the problem.
Relates to (but doesn't fix) issue 19196.
Comment #5 by robert.schadek — 2024-12-13T19:00:24Z