Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix Issue 8123 - alias declaration lookup is broken

  • Loading branch information...
commit 76543ef60f3b871612ddc0c87999859f427ba6f9 1 parent d5658a5
k-hara authored
28 src/declaration.c
@@ -122,6 +122,18 @@ void Declaration::checkModify(Loc loc, Scope *sc, Type *t)
122 122 }
123 123 #endif
124 124
  125 +Dsymbol *Declaration::search(Loc loc, Identifier *ident, int flags)
  126 +{
  127 + Dsymbol *s = Dsymbol::search(loc, ident, flags);
  128 + if (!s && type)
  129 + {
  130 + s = type->toDsymbol(NULL);
  131 + if (s)
  132 + s = s->search(loc, ident, flags);
  133 + }
  134 + return s;
  135 +}
  136 +
125 137
126 138 /********************************* TupleDeclaration ****************************/
127 139
@@ -497,18 +509,6 @@ void AliasDeclaration::semantic(Scope *sc)
497 509 else if (t)
498 510 {
499 511 type = t->semantic(loc, sc);
500   -
501   - /* If type is class or struct, convert to symbol.
502   - * See bugzilla 6475.
503   - */
504   - s = type->toDsymbol(sc);
505   - if (s
506   -#if DMDV2
507   - && ((s->getType() && type->equals(s->getType())) || s->isEnumMember())
508   -#endif
509   - )
510   - goto L2;
511   -
512 512 //printf("\talias resolved to type %s\n", type->toChars());
513 513 }
514 514 if (overnext)
@@ -617,7 +617,9 @@ const char *AliasDeclaration::kind()
617 617
618 618 Type *AliasDeclaration::getType()
619 619 {
620   - return type;
  620 + if (type)
  621 + return type;
  622 + return toAlias()->getType();
621 623 }
622 624
623 625 Dsymbol *AliasDeclaration::toAlias()
2  src/declaration.h
@@ -133,6 +133,8 @@ struct Declaration : Dsymbol
133 133 unsigned size(Loc loc);
134 134 void checkModify(Loc loc, Scope *sc, Type *t);
135 135
  136 + Dsymbol *search(Loc loc, Identifier *ident, int flags);
  137 +
136 138 void emitComment(Scope *sc);
137 139 void toJsonBuffer(OutBuffer *buf);
138 140 void toDocBuffer(OutBuffer *buf);
34 test/runnable/declaration.d
@@ -11,8 +11,13 @@ class Foo6475(Value)
11 11
12 12 void test6475()
13 13 {
14   - alias Foo6475!(int) C2;
15   - alias C2.T1!0 a1;
  14 + alias Foo6475!(int) C1;
  15 + alias C1.T1!0 X1;
  16 + static assert(is(X1 == int));
  17 +
  18 + alias const(Foo6475!(int)) C2;
  19 + alias C2.T1!0 X2;
  20 + static assert(is(X2 == int));
16 21 }
17 22
18 23 /***************************************************/
@@ -37,11 +42,36 @@ void test7239()
37 42 }
38 43
39 44 /***************************************************/
  45 +// 8123
  46 +
  47 +void test8123()
  48 +{
  49 + struct S { }
  50 +
  51 + struct AS
  52 + {
  53 + alias S Alias;
  54 + }
  55 +
  56 + struct Wrapper
  57 + {
  58 + AS as;
  59 + }
  60 +
  61 + Wrapper w;
  62 + static assert(is(typeof(w.as).Alias == S)); // fail
  63 + static assert(is(AS.Alias == S)); // ok
  64 + static assert(is(typeof(w.as) == AS)); // ok
  65 + static assert(is(typeof(w.as).Alias == AS.Alias)); // fail
  66 +}
  67 +
  68 +/***************************************************/
40 69
41 70 int main()
42 71 {
43 72 test6475();
44 73 test7239();
  74 + test8123();
45 75
46 76 printf("Success\n");
47 77 return 0;

0 comments on commit 76543ef

Please sign in to comment.
Something went wrong with that request. Please try again.