Skip to content

Commit

Permalink
Merge pull request #1681 from 9rnsr/fix9538
Browse files Browse the repository at this point in the history
Issue 9538 - Regression (2.062): Can't use typeid on .ptr of static array
  • Loading branch information
MartinNowak committed Feb 21, 2013
2 parents d15c1d9 + 5b17d1f commit ba82274
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 54 deletions.
83 changes: 29 additions & 54 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -6480,11 +6480,6 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
Dsymbol *s, Dsymbol *scopesym,
Expression **pe, Type **pt, Dsymbol **ps)
{
VarDeclaration *v;
EnumMember *em;
Expression *e;
TemplateInstance *ti;

#if 0
printf("TypeQualified::resolveHelper(sc = %p, idents = '%s')\n", sc, toChars());
if (scopesym)
Expand All @@ -6506,40 +6501,18 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
//printf("\t3: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
//printf("\tgetType = '%s'\n", s->getType()->toChars());
if (!sm)
{ Type *t;

v = s->isVarDeclaration();
ti = s->isTemplateInstance();
if (v && id == Id::length)
{
e = new VarExp(loc, v);
t = e->type;
if (!t)
goto Lerror;
goto L3;
}
else if ((v && (id == Id::stringof || id == Id::offsetof))
|| (ti && (id == Id::stringof || id == Id::mangleof)))
{
e = new DsymbolExp(loc, s, 0);
do
{
id = idents[i];
e = new DotIdExp(loc, e, id);
} while (++i < idents.dim);
e = e->semantic(sc);
*pe = e;
return;
}

t = s->getType();
if (!t && s->isDeclaration())
{ t = s->isDeclaration()->type;
if (!t && s->isTupleDeclaration())
{
Type *t = s->getType(); // type symbol, type alias, or type tuple?
if (!t)
{ if (s->isDeclaration()) // var, func, or tuple declaration?
{ t = s->isDeclaration()->type;
if (!t && s->isTupleDeclaration()) // expression tuple?
goto L3;
}
else if (s->isTemplateInstance() ||
s->isImport() || s->isPackage() || s->isModule())
{
e = new TupleExp(loc, s->isTupleDeclaration());
e = e->semantic(sc);
t = e->type;
goto L3;
}
}
if (t)
Expand All @@ -6550,17 +6523,25 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
if (sm)
goto L2;
}
//e = t->getProperty(loc, id);
e = new TypeExp(loc, t);
e = t->dotExp(sc, e, id);
i++;
L3:
Expression *e = new DsymbolExp(loc, s);
e = e->semantic(sc);
for (; i < idents.dim; i++)
{
id = idents[i];
//printf("e: '%s', id: '%s', type = %s\n", e->toChars(), id->toChars(), e->type->toChars());
e = new DotIdExp(e->loc, e, id);
e = e->semantic(sc);
if (id->dyncast() == DYNCAST_IDENTIFIER)
{
DotIdExp *die = new DotIdExp(e->loc, e, id);
e = die->semantic(sc, 1); // don't see UFCS
}
else
{ assert(id->dyncast() == DYNCAST_DSYMBOL);
TemplateInstance *ti = ((Dsymbol *)id)->isTemplateInstance();
assert(ti);
DotTemplateInstanceExp *dte = new DotTemplateInstanceExp(e->loc, e, ti->name, ti->tiargs);
e = dte->semantic(sc, 1); // don't see UFCS
}
}
if (e->op == TOKtype)
*pt = e->type;
Expand Down Expand Up @@ -6591,8 +6572,7 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
s = sm->toAlias();
}

v = s->isVarDeclaration();
if (v)
if (VarDeclaration *v = s->isVarDeclaration())
{
if (v && v->inuse && (!v->type || !v->type->deco)) // Bugzilla 9494
{ error(loc, "circular reference to '%s'", v->toPrettyChars());
Expand All @@ -6603,15 +6583,13 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
return;
}
#if 0
fd = s->isFuncDeclaration();
if (fd)
if (FuncDeclaration *fd = s->isFuncDeclaration())
{
*pe = new DsymbolExp(loc, fd, 1);
return;
}
#endif
em = s->isEnumMember();
if (em)
if (EnumMember *em = s->isEnumMember())
{
// It's not a type, it's an expression
*pe = em->value->copy();
Expand All @@ -6623,10 +6601,7 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
if (!t)
{
// If the symbol is an import, try looking inside the import
Import *si;

si = s->isImport();
if (si)
if (Import *si = s->isImport())
{
s = si->search(loc, s->ident, 0);
if (s && s != si)
Expand Down
22 changes: 22 additions & 0 deletions test/compilable/test9554.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// REQUIRED_ARGS: -o-

module pkg.test9554;
alias mod = pkg.test9554;

template Test(alias name) { enum Test = name; }
void fun() {}

static assert(fun.stringof == Test!(fun.stringof));
static assert(fun.stringof == "fun()");
static assert(fun.mangleof == Test!(fun.mangleof));
static assert(fun.mangleof == "_D3pkg8test95543funFZv");

static assert(mod.stringof == Test!(mod.stringof));
static assert(mod.stringof == "module test9554");
static assert(mod.mangleof == Test!(mod.mangleof));
static assert(mod.mangleof == "3pkg8test9554");

static assert(pkg.stringof == Test!(pkg.stringof));
static assert(pkg.stringof == "package pkg");
static assert(pkg.mangleof == Test!(pkg.mangleof));
static assert(pkg.mangleof == "3pkg");
10 changes: 10 additions & 0 deletions test/runnable/xtest46.d
Original file line number Diff line number Diff line change
Expand Up @@ -5868,6 +5868,15 @@ Bar9504 test9504()
return Bar9504();
}

/***************************************************/
// 9538

void test9538()
{
void*[1] x;
auto ti = typeid(x.ptr);
}

/***************************************************/

int main()
Expand Down Expand Up @@ -6125,6 +6134,7 @@ int main()
test8917();
test163();
test9428();
test9538();

printf("Success\n");
return 0;
Expand Down

0 comments on commit ba82274

Please sign in to comment.