Skip to content

Commit

Permalink
Merge pull request #6262 from MartinNowak/fix16574
Browse files Browse the repository at this point in the history
fix Issue 16574 - forward reference issue with with speculative test
  • Loading branch information
Михаил Страшун committed Nov 19, 2016
2 parents 8c00c7e + 0aac63d commit b2691f3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/aggregate.d
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,13 @@ extern (C++) abstract class AggregateDeclaration : ScopeDsymbol
// There's unresolvable forward reference.
if (type != Type.terror)
error(loc, "no size because of forward reference");
type = Type.terror;
errors = true;
// Don't cache errors from speculative semantic, might be resolvable later.
// https://issues.dlang.org/show_bug.cgi?id=16574
if (!global.gag)
{
type = Type.terror;
errors = true;
}
return false;
}

Expand Down
34 changes: 34 additions & 0 deletions test/compilable/test16574.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// https://issues.dlang.org/show_bug.cgi?id=16574
template Recursive(T) if (is(T == class))
{
// fails because T is still forward referenced
// speculative determineSize must not set type to error
static assert (!__traits(compiles, { new T; }));
// known size of class
static assert (is(typeof(T.init) == T));

alias Recursive = T;
}

// must be resolvable
class C
{
Recursive!C r;
}

template Recursive(T) if (is(T == struct))
{
// fails because T is still forward referenced
// speculative determineSize must not set type to error
static assert (!__traits(compiles, { T t; }));
// no size yet for struct
static assert (!is(typeof(T.init)));

alias Recursive = T*;
}

// must be resolvable
struct S
{
Recursive!S r;
}

0 comments on commit b2691f3

Please sign in to comment.