fix Issue 22975 - ICE: 3 cyclic aliases with meaningful overloads not caught

This commit is contained in:
Iain Buclaw 2022-12-27 17:19:39 +01:00
parent 4b5a7826a7
commit 6a406a59fe
2 changed files with 86 additions and 63 deletions

View file

@ -2924,6 +2924,15 @@ Expression addInvariant(AggregateDeclaration ad, VarDeclaration vthis)
*/
extern (D) int overloadApply(Dsymbol fstart, scope int delegate(Dsymbol) dg, Scope* sc = null)
{
Dsymbols visited;
int overloadApplyRecurse(Dsymbol fstart, scope int delegate(Dsymbol) dg, Scope* sc)
{
// Detect cyclic calls.
if (visited.contains(fstart))
return 0;
visited.push(fstart);
Dsymbol next;
for (auto d = fstart; d; d = next)
{
@ -2940,11 +2949,11 @@ extern (D) int overloadApply(Dsymbol fstart, scope int delegate(Dsymbol) dg, Sco
{
if (checkSymbolAccess(sc, od))
{
if (int r = overloadApply(od.aliassym, dg, sc))
if (int r = overloadApplyRecurse(od.aliassym, dg, sc))
return r;
}
}
else if (int r = overloadApply(od.aliassym, dg, sc))
else if (int r = overloadApplyRecurse(od.aliassym, dg, sc))
return r;
next = od.overnext;
}
@ -2952,7 +2961,7 @@ extern (D) int overloadApply(Dsymbol fstart, scope int delegate(Dsymbol) dg, Sco
{
if (fa.hasOverloads)
{
if (int r = overloadApply(fa.funcalias, dg, sc))
if (int r = overloadApplyRecurse(fa.funcalias, dg, sc))
return r;
}
else if (auto fd = fa.toAliasFunc())
@ -3007,6 +3016,8 @@ extern (D) int overloadApply(Dsymbol fstart, scope int delegate(Dsymbol) dg, Sco
}
}
return 0;
}
return overloadApplyRecurse(fstart, dg, sc);
}
/**

View file

@ -0,0 +1,12 @@
// https://issues.dlang.org/show_bug.cgi?id=22975
void test22975a(int) {};
alias test22975b = test22975a;
void test22975b(bool) {}
alias test22975c = test22975b;
alias test22975a = test22975c;
void test22975c(float) {}