Prefer explicitly declared overloads over generic substitutions#1213
Merged
Conversation
When an explicitly declared (non-generic) function and a generic substitution match a call equally well, overload resolution reported an ambiguity. Mirror C++ semantics and prefer the non-template, applied as a secondary tie-break after qualifier specificity. A losing generic substitution that was only inserted for this match is de-registered again, so the IR generator never emits a manifestation that was never type-checked. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
FunctionManager::breakOverloadTie, applied after the existing qualifier-specificity narrowing.error-ambiguous-generic-functionstest (which encoded the old "this is ambiguous" behavior) intosuccess-generic-overload-prefers-explicit, which now asserts at runtime that the explicitfoo(byte*&)overload is selected over the genericfoo<byte>(byte*&).Why
Previously, declaring both a non-generic overload and a generic one that substitutes to the same signature made the call ambiguous. This is a common and legitimate pattern (e.g. a dedicated copy constructor alongside a generic value constructor), so the non-template should win rather than error.
How it was validated
cmake --build cmake-build-debug --target spice spicetest— builds cleancmake-build-debug/test/spicetest --gtest_filter='TypeCheckerTests.*:StdTests.*:-StdTests.bindings_llvm'— 296 passed, 1 skipped (net_socketsBasic)StdTests.bindings_llvmis excluded as it fails only due to a local environment issue (mold cannot find the LLVM AArch64 libs); it compiles cleanly.BootstrapCompilerTestsare a known local environment failure.Follow-up / known limitations
A follow-up PR adds a generic value constructor to
std/type/anythat relies on this overload-resolution behavior.