Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 3913 - Emit better diagnostics for invalid enum member lookups #3252

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/mtype.c
Expand Up @@ -7261,7 +7261,22 @@ Expression *TypeEnum::dotExp(Scope *sc, Expression *e, Identifier *ident, int fl
{
return getProperty(e->loc, ident, flag);
}
return sym->getMemtype(Loc())->dotExp(sc, e, ident, flag);

if (flag == 0)
flag = 1; // silence lookup errors for memtype

Expression *res = sym->getMemtype(Loc())->dotExp(sc, e, ident, flag);
if (!res)
{
Dsymbol *s = sym->search_correct(ident);
if (s)
e->error("no property '%s' for type '%s'. Did you mean '%s.%s' ?", ident->toChars(), toChars(), toChars(), s->toChars());
else
e->error("no property '%s' for type '%s'", ident->toChars(), toChars());

return new ErrorExp();
}
return res;
}
EnumMember *m = s->isEnumMember();
return m->getVarExp(e->loc, sc);
Expand Down
15 changes: 15 additions & 0 deletions test/fail_compilation/diag3913.d
@@ -0,0 +1,15 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag3913.d(13): Error: no property 'foobardoo' for type 'Foo'
fail_compilation/diag3913.d(14): Error: no property 'secon' for type 'Foo'. Did you mean 'Foo.second' ?
---
*/

module diag3913;
void main()
{
enum Foo { first, second }
auto a = Foo.foobardoo;
auto b = Foo.secon;
}