Skip to content

fix Issue 21622 - Ambiguous template instantiation without parens crashes compiler#22550

Open
TANAY-BARGIR wants to merge 1 commit intodlang:masterfrom
TANAY-BARGIR:fix-bug-21622
Open

fix Issue 21622 - Ambiguous template instantiation without parens crashes compiler#22550
TANAY-BARGIR wants to merge 1 commit intodlang:masterfrom
TANAY-BARGIR:fix-bug-21622

Conversation

@TANAY-BARGIR
Copy link

@TANAY-BARGIR TANAY-BARGIR commented Feb 10, 2026

Fixes Issue 21622

What this PR does:

It fixes a compiler crash/silent failure when an ambiguous template instantiation (e.g., foo!0) matches multiple overloads exactly but is not called with parentheses (which results in a ScopeExp instead of a CallExp).

Previous Behavior:

The compiler's sideeffect.d logic ignored EXP.scope_ nodes derived from these ambiguous templates. This caused the node to fall through to the backend, resulting in either a misleading "has no effect" error or an internal compiler error (Error: unknown) because the backend cannot generate code for a raw ScopeExp.

New Behavior:

The discardValue function in sideeffect.d now intercepts EXP.scope_. It specifically checks if the ScopeExp resolves to a TemplateInstance that:

  1. Has no aliasdecl (meaning it failed to resolve to a single symbol).
  2. Has a valid tempdecl (meaning the template itself was found).

In this specific ambiguous state, it now correctly issues the error:

foo!0 matches multiple overloads exactly

This aligns the behavior with standard function call resolution and prevents the backend crash.

This patch has been verified against the reproduction case provided in the issue. I am happy to adjust the logic if there are preferred ways to handle ScopeExp resolution in this context. Thanks for reviewing!

@dlang-bot
Copy link
Contributor

dlang-bot commented Feb 10, 2026

Thanks for your pull request and interest in making D better, @TANAY-BARGIR! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

  • In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. Please add the word "Bugzilla" to issue references. For example, Fix Bugzilla Issue 12345 or Fix Bugzilla 12345.(Reminder: the edit needs to be done in the Git commit message, not the GitHub pull request.)

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#22550"

@thewilsonator
Copy link
Contributor

please add the test case for that issue

@TANAY-BARGIR
Copy link
Author

@thewilsonator I have added the test case as requested (compiler/test/fail_compilation/issue21622.d).

I also squashed the commits and updated the message format, so the bot has now correctly linked this to Bugzilla Issue 21622.

@TANAY-BARGIR TANAY-BARGIR force-pushed the fix-bug-21622 branch 2 times, most recently from 7154a1b to 56e9af4 Compare February 10, 2026 14:29
@CyberShadow
Copy link
Member

Fixes Bugzilla Issue 21622

Bugzilla Issue 21622 doesn't seem related, I think you mean GitHub Issue 21622.

@TANAY-BARGIR TANAY-BARGIR force-pushed the fix-bug-21622 branch 2 times, most recently from 328b941 to 8b29b40 Compare February 12, 2026 09:52
@TANAY-BARGIR
Copy link
Author

@CyberShadow Thanks for pointing that out. I've updated the PR description and commit message to reference the correct GitHub Issue (#21622) instead of Bugzilla.

I also updated the test case to be path-agnostic, which should fix the Windows CI failure.

Copy link
Member

@CyberShadow CyberShadow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TANAY-BARGIR Could you please disclose the use of any AI/LLM tools used in creating this pull request?

---
*/

// https://issues.dlang.org/show_bug.cgi?id=21622
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link is still wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CyberShadow I missed the link inside the file when updating the description. I've pushed the fix again.

Regarding your question: Yes, I am using LLMs to help me navigate the DMD codebase and understand the test suite structure as I learn the compiler internals. The incorrect Bugzilla ID was an oversight on my part where I relied on a generated reference without verifying it against the actual tracker. I apologize for the noise that caused.

…verloads

Fixes dlang#21622. This fixes a crash when an ambiguous template instantiation (e.g., foo!0) matches multiple overloads exactly.
Comment on lines +14 to +15
import dmd.dtemplate;
import dmd.dsymbol;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imports should be in alphabetic order

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants