Skip to content

Commit

Permalink
Merge pull request #453 from 9rnsr/fix2856
Browse files Browse the repository at this point in the history
Issue 2856 - static opIndex does not compile for a templated struct/class
  • Loading branch information
WalterBright committed Nov 16, 2011
2 parents 57db617 + e1966b1 commit 8857ba8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -4058,6 +4058,10 @@ Expression *ScopeExp::semantic(Scope *sc)
//printf("sds = %s, '%s'\n", sds->kind(), sds->toChars());
//printf("\tparent = '%s'\n", sds->parent->toChars());
sds->semantic(sc);

AggregateDeclaration *ad = sds->isAggregateDeclaration();
if (ad)
return (new TypeExp(loc, ad->type))->semantic(sc);
}
type = Type::tvoid;
//printf("-2ScopeExp::semantic() %s\n", toChars());
Expand Down
15 changes: 15 additions & 0 deletions test/runnable/xtest46.d
Original file line number Diff line number Diff line change
Expand Up @@ -4118,6 +4118,20 @@ void test6868()
char[0] s; // need
}

/***************************************************/
// 2856

struct foo2856 { static void opIndex(int i) { printf("foo\n"); } }
struct bar2856(T) { static void opIndex(int i) { printf("bar\n"); } }

void test2856()
{
foo2856[1];
bar2856!(float)[1]; // Error (# = __LINE__)
alias bar2856!(float) B;
B[1]; // Okay
}

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

int main()
Expand Down Expand Up @@ -4316,6 +4330,7 @@ int main()
test6902();
test6330();
test6868();
test2856();

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

0 comments on commit 8857ba8

Please sign in to comment.