Skip to content

Commit

Permalink
Merge pull request #3779 from 9rnsr/fix13142
Browse files Browse the repository at this point in the history
Issue 13142 - Enums on different classes confuse the compiler
  • Loading branch information
WalterBright authored and 9rnsr committed Jul 17, 2014
1 parent cad191c commit 5b9f27c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
13 changes: 11 additions & 2 deletions src/enum.c
Expand Up @@ -306,7 +306,7 @@ Expression *EnumDeclaration::getMaxMinValue(Loc loc, Identifier *id)
goto Lerrors;
}
if (*pval)
return *pval;
goto Ldone;

if (scope)
semantic(scope);
Expand Down Expand Up @@ -360,7 +360,16 @@ Expression *EnumDeclaration::getMaxMinValue(Loc loc, Identifier *id)
*pval = e;
}
}
return *pval;
Ldone:
{
Expression *e = *pval;
if (e->op != TOKerror)
{
e = e->copy();
e->loc = loc;
}
return e;
}

Lerrors:
*pval = new ErrorExp();
Expand Down
9 changes: 5 additions & 4 deletions src/mtype.c
Expand Up @@ -7415,18 +7415,19 @@ Expression *TypeEnum::dotExp(Scope *sc, Expression *e, Identifier *ident, int fl
}

Expression *TypeEnum::getProperty(Loc loc, Identifier *ident, int flag)
{ Expression *e;

{
Expression *e;
if (ident == Id::max || ident == Id::min)
{
{
return sym->getMaxMinValue(loc, ident);
}
else if (ident == Id::init)
{
e = defaultInitLiteral(loc);
}
else if (ident == Id::stringof)
{ char *s = toChars();
{
char *s = toChars();
e = new StringExp(loc, s, strlen(s), 'c');
Scope sc;
e = e->semantic(&sc);
Expand Down
27 changes: 27 additions & 0 deletions test/fail_compilation/diag13142.d
@@ -0,0 +1,27 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag13142.d(25): Error: cannot implicitly convert expression (3) of type int to TYPE
---
*/

class Button
{
enum TYPE // button type
{
COMMAND,
CHECK,
OPTION,
}
}

class Toolbar
{
enum ButtonTYPE // button type
{
COMMAND = Button.TYPE.COMMAND,
CHECK = Button.TYPE.CHECK,
OPTION = Button.TYPE.OPTION,
DELIMETER = Button.TYPE.max + 1
}
}

0 comments on commit 5b9f27c

Please sign in to comment.