Skip to content

Commit

Permalink
Merge pull request #3019 from 9rnsr/fix11767
Browse files Browse the repository at this point in the history
[REG2.060] Issue 11767 - doubly mixed-in struct "failed semantic analysis"
  • Loading branch information
WalterBright committed Dec 26, 2013
2 parents dc70741 + e8b3503 commit 4369b6d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/template.c
Expand Up @@ -7491,7 +7491,31 @@ void TemplateMixin::semantic(Scope *sc)
assert(tempdecl);

if (!ident)
ident = genIdent(tiargs);
{
/* Assign scope local unique identifier, as same as lambdas.
*/
const char *s = "__mixin";

DsymbolTable *symtab;
if (FuncDeclaration *func = sc->parent->isFuncDeclaration())
{
symtab = func->localsymtab;
if (symtab)
{
// Inside template constraint, symtab is not set yet.
goto L1;
}
}
else
{
symtab = sc->parent->isScopeDsymbol()->symtab;
L1:
assert(symtab);
int num = (int)_aaLen(symtab->tab) + 1;
ident = Lexer::uniqueId(s, num);
symtab->insert(this);
}
}

inst = this;
parent = sc->parent;
Expand Down Expand Up @@ -7815,7 +7839,7 @@ void TemplateMixin::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
tqual->toCBuffer(buf, NULL, hgs);
toCBufferTiargs(buf, hgs);

if (ident)
if (ident && memcmp(ident->string, "__mixin", 7) != 0)
{
buf->writebyte(' ');
buf->writestring(ident->toChars());
Expand Down
27 changes: 27 additions & 0 deletions test/runnable/mixin1.d
Expand Up @@ -1233,6 +1233,32 @@ class C11487
mixin M.Mix!(M.R);
}

/*******************************************/
// 11767

mixin template M11767()
{
struct S11767 {}
}
mixin M11767!();
mixin M11767!(); // OK
static assert(!__traits(compiles, S11767));

void test11767()
{
mixin M11767!();
alias S1 = S11767;
{
mixin M11767!();
alias S2 = S11767;
static assert(!is(S1 == S2));
static assert(S1.mangleof == "S6mixin19test11767FZv8__mixin16S11767");
static assert(S2.mangleof == "S6mixin19test11767FZv8__mixin26S11767");
}
mixin M11767!();
static assert(!__traits(compiles, S11767));
}

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

int main()
Expand Down Expand Up @@ -1282,6 +1308,7 @@ int main()
test2740();
test42();
test9417();
test11767();

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

0 comments on commit 4369b6d

Please sign in to comment.