Skip to content

Commit 7cc5d67

Browse files
committed
fix Issue 21622 - Ambiguous template instantiation without parens crashes compiler
When a template instantiation matches multiple overloads exactly but is not called with parentheses, the compiler generated a ScopeExp that fell through sideeffect.d. This fix detects if a ScopeExp resolves to a TemplateInstance with no matching aliasdecl or an OverloadSet, and correctly reports the ambiguity instead of crashing.
1 parent 9e57074 commit 7cc5d67

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

compiler/src/dmd/sideeffect.d

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
* Documentation: https://dlang.org/phobos/dmd_sideeffect.html
99
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/sideeffect.d
1010
*/
11-
1211
module dmd.sideeffect;
13-
12+
import dmd.dtemplate;
13+
import dmd.dsymbol;
1414
import dmd.astenums;
1515
import dmd.declaration;
1616
import dmd.dscope;
@@ -391,6 +391,25 @@ bool discardValue(Expression e)
391391
}
392392
}
393393
return !seenSideEffect;
394+
case EXP.scope_:
395+
{
396+
if (auto se = e.isScopeExp())
397+
{
398+
if (auto ti = se.sds.isTemplateInstance())
399+
{
400+
if (!ti.aliasdecl && ti.tempdecl)
401+
{
402+
error(e.loc, "`%s` matches multiple overloads exactly", se.sds.toChars());
403+
}
404+
}
405+
else if (se.sds && se.sds.isOverloadSet())
406+
{
407+
error(e.loc, "`%s` matches multiple overloads exactly", se.sds.toChars());
408+
}
409+
}
410+
error(e.loc, "`%s` has no effect", e.toErrMsg());
411+
return true;
412+
}
394413
default:
395414
break;
396415
}

0 commit comments

Comments
 (0)