Skip to content

Commit 351f4d3

Browse files
committed
fix Issue 18480 - dmd 2.079 hangs
1 parent 4e4d81a commit 351f4d3

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/dmd/access.d

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ public Dsymbol mostVisibleOverload(Dsymbol s)
547547
{
548548
if (!s.isOverloadable())
549549
return s;
550-
551-
Dsymbol next, fstart = s, mostVisible = s;
550+
Dsymbol next, fstart = s, mostVisible = s, previous = null;
551+
AliasDeclaration adOrig = null;
552552
for (; s; s = next)
553553
{
554554
// void func() {}
@@ -593,7 +593,13 @@ public Dsymbol mostVisibleOverload(Dsymbol s)
593593
*/
594594
auto aliasee = ad.toAlias();
595595
if (aliasee.isFuncAliasDeclaration || aliasee.isOverDeclaration)
596+
{
597+
if(ad.toChars() == aliasee.toChars())
598+
{
599+
adOrig = ad;
600+
}
596601
next = aliasee;
602+
}
597603
else
598604
{
599605
/* A simple alias can be at the end of a function or template overload chain.
@@ -613,6 +619,15 @@ public Dsymbol mostVisibleOverload(Dsymbol s)
613619

614620
if (next && mostVisible.prot().isMoreRestrictiveThan(next.prot()))
615621
mostVisible = next;
622+
623+
// fixes https://issues.dlang.org/show_bug.cgi?id=18480
624+
if(next && next == previous)
625+
{
626+
assert(adOrig);
627+
error(adOrig.loc, "`alias X = X` not allowed (with `X = %s`)", adOrig.toChars());
628+
return next;
629+
}
630+
previous = s;
616631
}
617632
return mostVisible;
618633
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public import test18480b : TestTemplate;
2+
alias TestTemplate = TestTemplate;
3+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
template TestTemplate() { }

test/fail_compilation/test18480.d

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
TEST_OUTPUT:
3+
---
4+
fail_compilation/imports/test18480a.d(2): Error: alias X = X not allowed (with X = TestTemplate)
5+
---
6+
https://issues.dlang.org/show_bug.cgi?id=18480
7+
*/
8+
9+
import test18480a;
10+
11+
alias TestTemplate = test18480a.TestTemplate;
12+
13+
void main() { }

0 commit comments

Comments
 (0)