From 9c83d4c8efb64bce803e8e292b79dde86d53db2a Mon Sep 17 00:00:00 2001 From: 0-v-0 Date: Sat, 27 Jun 2026 08:10:22 +0800 Subject: [PATCH] Fix #17749 - Ignore failing overload candidates --- compiler/src/dmd/templatesem.d | 26 ++++++++++++++++++++++---- compiler/test/compilable/test15801.d | 10 ++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 compiler/test/compilable/test15801.d diff --git a/compiler/src/dmd/templatesem.d b/compiler/src/dmd/templatesem.d index 8221c2bed6fd..489eae089e52 100644 --- a/compiler/src/dmd/templatesem.d +++ b/compiler/src/dmd/templatesem.d @@ -3713,9 +3713,17 @@ bool findBestMatch(TemplateInstance ti, Scope* sc, ArgumentList argumentList) TemplateDeclaration td_best; TemplateDeclaration td_ambig; MATCH m_best = MATCH.nomatch; + uint candidateCount = 0; Dsymbol dstart = tovers ? tovers.a[oi] : ti.tempdecl; overloadApply(dstart, (Dsymbol s) + { + if (s.isTemplateDeclaration()) + ++candidateCount; + return 0; + }); + const gagCandidates = candidateCount > 1; + overloadApply(dstart, (Dsymbol s) { auto td = s.isTemplateDeclaration(); if (!td) @@ -3736,9 +3744,11 @@ bool findBestMatch(TemplateInstance ti, Scope* sc, ArgumentList argumentList) dedtypes.zero(); assert(td.semanticRun != PASS.initial); + const olderrors = gagCandidates ? global.startGagging() : 0u; MATCH m = matchWithInstance(sc, td, ti, dedtypes, argumentList, 0); + const errors = gagCandidates && global.endGagging(olderrors); //printf("matchWithInstance = %d\n", m); - if (m == MATCH.nomatch) // no match at all + if (errors || m == MATCH.nomatch) // no match at all return 0; if (m < m_best) goto Ltd_best; if (m > m_best) goto Ltd; @@ -5511,9 +5521,17 @@ bool TemplateInstance_semanticTiargs(Loc loc, Scope* sc, Objects* tiargs, int fl } else { - sc = sc.startCTFE(); - ea = ea.expressionSemantic(sc); - sc = sc.endCTFE(); + const mightBeAlias = ea.op == EXP.variable || !definitelyValueParameter(ea); + if (mightBeAlias) + { + ea = ea.expressionSemantic(sc); + } + else + { + sc = sc.startCTFE(); + ea = ea.expressionSemantic(sc); + sc = sc.endCTFE(); + } if (auto varExp = ea.isVarExp()) { diff --git a/compiler/test/compilable/test15801.d b/compiler/test/compilable/test15801.d new file mode 100644 index 000000000000..dc27024b153b --- /dev/null +++ b/compiler/test/compilable/test15801.d @@ -0,0 +1,10 @@ +enum foo(alias sym) = 3; + +string str; + +static assert(foo!str == 3); + +enum bar(int n) = 2; +enum bar(alias sym) = 3; + +static assert(bar!str == 3);