Skip to content

Commit

Permalink
Fix Issue 22054 - Referencing a fwd-declared field results in many er…
Browse files Browse the repository at this point in the history
…ror messages
  • Loading branch information
RazvanN7 committed Jul 2, 2021
1 parent 5d2ad86 commit da37a70
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2209,7 +2209,17 @@ Expression getProperty(Type t, Scope* scope_, const ref Loc loc, Identifier iden
if (mt.ty == Tstruct || mt.ty == Tclass || mt.ty == Tenum)
s = mt.toDsymbol(null);
if (s)
{
// https://issues.dlang.org/show_bug.cgi?id=22054
// At this point, a forward referenced struct or class
// has already issued an error.
auto aggDecl = s.isAggregateDeclaration();
if (aggDecl && !aggDecl.members)
{
return ErrorExp.get;
}
s = s.search_correct(ident);
}
if (s && !symbolIsVisible(scope_, s))
s = null;
if (mt != Type.terror)
Expand Down Expand Up @@ -3569,7 +3579,11 @@ Expression dotExp(Type mt, Scope* sc, Expression e, Identifier ident, int flag)
assert(mt.ty == Tstruct || mt.ty == Tclass);
auto sym = mt.toDsymbol(sc).isAggregateDeclaration();
assert(sym);
if (ident != Id.__sizeof &&
if (// https://issues.dlang.org/show_bug.cgi?id=22054
// if a class or struct is forward referenced
// there is no point in searching for its members
sym.members &&
ident != Id.__sizeof &&
ident != Id.__xalignof &&
ident != Id._init &&
ident != Id._mangleof &&
Expand Down
15 changes: 15 additions & 0 deletions test/fail_compilation/test22054.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// https://issues.dlang.org/show_bug.cgi?id=22054

/*
TEST_OUTPUT:
---
fail_compilation/test22054.d(10): Error: class `test22054.exception` is forward referenced when looking for `what`
---
*/

class exception;

void main ()
{
assert(exception.what() == "Hello");
}

0 comments on commit da37a70

Please sign in to comment.