diff --git a/src/dmd/access.d b/src/dmd/access.d index 2d531eebc130..daeb87d3bf52 100644 --- a/src/dmd/access.d +++ b/src/dmd/access.d @@ -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() {} @@ -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. @@ -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; } diff --git a/test/fail_compilation/imports/test18480a.d b/test/fail_compilation/imports/test18480a.d new file mode 100644 index 000000000000..f20cf8a42bc1 --- /dev/null +++ b/test/fail_compilation/imports/test18480a.d @@ -0,0 +1,3 @@ +public import imports.test18480b : TestTemplate; +alias TestTemplate = TestTemplate; + diff --git a/test/fail_compilation/imports/test18480b.d b/test/fail_compilation/imports/test18480b.d new file mode 100644 index 000000000000..aa3ebd1be8e6 --- /dev/null +++ b/test/fail_compilation/imports/test18480b.d @@ -0,0 +1 @@ +template TestTemplate() { } diff --git a/test/fail_compilation/test18480.d b/test/fail_compilation/test18480.d new file mode 100644 index 000000000000..45ab8b397624 --- /dev/null +++ b/test/fail_compilation/test18480.d @@ -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;