Skip to content

Commit

Permalink
fix Issue 18480 - dmd hangs with self-alias declaration
Browse files Browse the repository at this point in the history
- fixed by detecting `alias sym = sym;` during semantic
- small adoption of assertion in mostVisibleOverload to deal with
  alias error expression (type = Type.terror) in overload
  • Loading branch information
MartinNowak committed Feb 24, 2018
1 parent 4a03c0e commit 414ae99
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/dmd/access.d
Expand Up @@ -571,7 +571,8 @@ public Dsymbol mostVisibleOverload(Dsymbol s)
// private void name(int) {}
else if (auto ad = s.isAliasDeclaration())
{
assert(ad.isOverloadable, "Non overloadable Aliasee in overload list");
assert(ad.isOverloadable || ad.type && ad.type.ty == Terror,
"Non overloadable Aliasee in overload list");
// Yet unresolved aliases store overloads in overnext.
if (ad.semanticRun < PASS.semanticdone)
next = ad.overnext;
Expand Down
13 changes: 13 additions & 0 deletions src/dmd/dsymbolsem.d
Expand Up @@ -5492,6 +5492,19 @@ void aliasSemantic(AliasDeclaration ds, Scope* sc)
global.gag = 0;
}

// https://issues.dlang.org/show_bug.cgi?id=18480
// Detect `alias sym = sym;` to prevent creating loops in overload overnext lists.
// Selective imports are allowed to alias to the same name `import mod : sym=sym`.
if (ds.type.ty == Tident && !ds._import)
{
auto tident = cast(TypeIdentifier)ds.type;
if (tident.ident is ds.ident && !tident.idents.dim)
{
error(ds.loc, "`alias %s = %s;` cannot alias itself, use a qualified name to create an overload set",
ds.ident.toChars(), tident.ident.toChars());
ds.type = Type.terror;
}
}
/* This section is needed because Type.resolve() will:
* const x = 3;
* alias y = x;
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/test18480.d
Expand Up @@ -2,7 +2,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/imports/test18480a.d(2): Error: `alias X = X` not allowed (with `X = TestTemplate`)
fail_compilation/imports/test18480a.d(2): Error: `alias TestTemplate = TestTemplate;` cannot alias itself, use a qualified name to create an overload set
---
https://issues.dlang.org/show_bug.cgi?id=18480
*/
Expand Down

0 comments on commit 414ae99

Please sign in to comment.