Skip to content

Commit

Permalink
Fix Issue 3913 - Emit better lookup diagnostics for enum members
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrejMitrovic committed Oct 11, 2015
1 parent d2c607f commit 4817e50
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/mtype.d
Expand Up @@ -8323,7 +8323,20 @@ public:
{
return getProperty(e.loc, ident, flag);
}
return sym.getMemtype(Loc()).dotExp(sc, e, ident, flag);

Expression res = sym.getMemtype(Loc()).dotExp(sc, e, ident, 1);
if (flag != 1 && !res)
{
if (auto ns = sym.search_correct(ident))
e.error("no property '%s' for type '%s'. Did you mean '%s.%s' ?", ident.toChars(), toChars(), toChars(),
ns.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
14 changes: 14 additions & 0 deletions test/fail_compilation/diag3913.d
@@ -0,0 +1,14 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag3913.d(12): Error: no property 'foobardoo' for type 'Foo'
fail_compilation/diag3913.d(13): Error: no property 'secon' for type 'Foo'. Did you mean 'Foo.second' ?
---
*/

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

0 comments on commit 4817e50

Please sign in to comment.