Skip to content

Commit

Permalink
Merge branch 'master' of github.com:D-Programming-Language/dmd
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jul 18, 2012
2 parents d702b04 + bc83600 commit b98d9e2
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/aliasthis.c
Expand Up @@ -18,6 +18,7 @@
#include "aggregate.h"
#include "dsymbol.h"
#include "mtype.h"
#include "declaration.h"

#if DMDV2

Expand Down Expand Up @@ -78,9 +79,32 @@ void AliasThis::semantic(Scope *sc)
::error(loc, "%s is not a member of %s", s->toChars(), ad->toChars());
else
::error(loc, "undefined identifier %s", ident->toChars());
return;
}
else if (ad->aliasthis && s != ad->aliasthis)
error("there can be only one alias this");

/* disable the alias this conversion so the implicit conversion check
* doesn't use it.
*/
/* This should use ad->aliasthis directly, but with static foreach and templates
* ad->type->sym might be different to ad.
*/
AggregateDeclaration *ad2 = ad->type->toDsymbol(NULL)->isAggregateDeclaration();
Dsymbol *save = ad2->aliasthis;
ad2->aliasthis = NULL;

if (Declaration *d = s->isDeclaration())
{
Type *t = d->type;
assert(t);
if (ad->type->implicitConvTo(t))
{
::error(loc, "alias this is not reachable as %s already converts to %s", ad->toChars(), t->toChars());
}
}

ad2->aliasthis = save;
ad->aliasthis = s;
}
else
Expand Down
2 changes: 2 additions & 0 deletions src/expression.c
Expand Up @@ -8452,6 +8452,7 @@ Expression *AddrExp::semantic(Scope *sc)
if (e1->op == TOKdotvar)
{
DotVarExp *dve = (DotVarExp *)e1;
checkDeprecated(sc, dve->var);
FuncDeclaration *f = dve->var->isFuncDeclaration();

if (f)
Expand All @@ -8467,6 +8468,7 @@ Expression *AddrExp::semantic(Scope *sc)
{
VarExp *ve = (VarExp *)e1;

checkDeprecated(sc, ve->var);
VarDeclaration *v = ve->var->isVarDeclaration();
if (v)
{
Expand Down
10 changes: 7 additions & 3 deletions src/statement.c
Expand Up @@ -3146,6 +3146,10 @@ Statement *SwitchStatement::semantic(Scope *sc)
return this; // already run
condition = condition->semantic(sc);
condition = resolveProperties(sc, condition);
TypeEnum *te = NULL;
// preserve enum type for final switches
if (condition->type->ty == Tenum)
te = (TypeEnum *)condition->type;
if (condition->type->isString())
{
// If it's not an array, cast it to one
Expand Down Expand Up @@ -3210,8 +3214,8 @@ Statement *SwitchStatement::semantic(Scope *sc)
{ // Don't use toBasetype() because that will skip past enums
t = ((TypeTypedef *)t)->sym->basetype;
}
if (condition->type->ty == Tenum)
{ TypeEnum *te = (TypeEnum *)condition->type;
if (te)
{
EnumDeclaration *ed = te->toDsymbol(sc)->isEnumDeclaration();
assert(ed);
size_t dim = ed->members->dim;
Expand All @@ -3222,7 +3226,7 @@ Statement *SwitchStatement::semantic(Scope *sc)
{
for (size_t j = 0; j < cases->dim; j++)
{ CaseStatement *cs = (*cases)[j];
if (cs->exp->equals(em->value))
if (cs->exp->equals(em->value) || cs->exp->toInteger() == em->value->toInteger())
goto L1;
}
error("enum member %s not represented in final switch", em->toChars());
Expand Down
15 changes: 15 additions & 0 deletions test/fail_compilation/fail4517.d
@@ -0,0 +1,15 @@

enum E : ushort
{
A, B
}

void main()
{
E e;
final switch(e)
{
case E.A:
break;
}
}
10 changes: 10 additions & 0 deletions test/fail_compilation/fail5851.d
@@ -0,0 +1,10 @@

class Foo
{
Object o;
alias o this;
}

void main()
{
}
7 changes: 7 additions & 0 deletions test/fail_compilation/fail7322.d
@@ -0,0 +1,7 @@

deprecated void fun() {}

void main()
{
auto x = &fun;
}

0 comments on commit b98d9e2

Please sign in to comment.