fix Issue 21622 - Ambiguous template instantiation without parens crashes compiler#22550
fix Issue 21622 - Ambiguous template instantiation without parens crashes compiler#22550TANAY-BARGIR wants to merge 1 commit intodlang:masterfrom
Conversation
|
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 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 referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
|
please add the test case for that issue |
0f06c03 to
5f8eb24
Compare
5f8eb24 to
35b79a1
Compare
|
@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. |
7154a1b to
56e9af4
Compare
Bugzilla Issue 21622 doesn't seem related, I think you mean GitHub Issue 21622. |
328b941 to
8b29b40
Compare
|
@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. |
CyberShadow
left a comment
There was a problem hiding this comment.
@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 |
There was a problem hiding this comment.
@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.
8b29b40 to
a3de47a
Compare
| import dmd.dtemplate; | ||
| import dmd.dsymbol; |
There was a problem hiding this comment.
imports should be in alphabetic order
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 aScopeExpinstead of aCallExp).Previous Behavior:
The compiler's
sideeffect.dlogic ignoredEXP.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 rawScopeExp.New Behavior:
The
discardValuefunction insideeffect.dnow interceptsEXP.scope_. It specifically checks if theScopeExpresolves to aTemplateInstancethat:aliasdecl(meaning it failed to resolve to a single symbol).tempdecl(meaning the template itself was found).In this specific ambiguous state, it now correctly issues the error:
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!