Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/dmd/access.d
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ public Dsymbol mostVisibleOverload(Dsymbol s)
{
if (!s.isOverloadable())
return s;

Dsymbol next, fstart = s, mostVisible = s;
Dsymbol next, fstart = s, mostVisible = s, previous = null;
AliasDeclaration adOrig = null;
for (; s; s = next)
{
// void func() {}
Expand Down Expand Up @@ -593,7 +593,13 @@ public Dsymbol mostVisibleOverload(Dsymbol s)
*/
auto aliasee = ad.toAlias();
if (aliasee.isFuncAliasDeclaration || aliasee.isOverDeclaration)
{
if(ad.toChars() == aliasee.toChars())
{
adOrig = ad;
}
next = aliasee;
}
else
{
/* A simple alias can be at the end of a function or template overload chain.
Expand All @@ -613,6 +619,15 @@ public Dsymbol mostVisibleOverload(Dsymbol s)

if (next && mostVisible.prot().isMoreRestrictiveThan(next.prot()))
mostVisible = next;

// fixes https://issues.dlang.org/show_bug.cgi?id=18480
if(next && next == previous)
{
assert(adOrig);
error(adOrig.loc, "`alias X = X` not allowed (with `X = %s`)", adOrig.toChars());
return next;
}
previous = s;
}
return mostVisible;
}
3 changes: 3 additions & 0 deletions test/fail_compilation/imports/test18480a.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public import imports.test18480b : TestTemplate;
alias TestTemplate = TestTemplate;

1 change: 1 addition & 0 deletions test/fail_compilation/imports/test18480b.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
template TestTemplate() { }
10 changes: 10 additions & 0 deletions test/fail_compilation/test18480.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// REQUIRED_ARGS: -i
/*
TEST_OUTPUT:
---
fail_compilation/imports/test18480a.d(2): Error: `alias X = X` not allowed (with `X = TestTemplate`)
---
https://issues.dlang.org/show_bug.cgi?id=18480
*/

import imports.test18480a : TestTemplate;