Repository navigation
fix(resolve): bind an extension's own type param from a plain receiver - #328
Merged
Merged
Conversation
…r (T?.required)
`fun <T : Any> T?.required(): T` inferred its return as the literal "T", so
`textModel.required("x").title` looked `title` up on a class named "T".
Two causes, both hidden by #318's test (its mock supplied data a real index
never does, and it exercised the wrong strategy):
- the parser stores extension_receiver_type only for generic receivers, so a
plain `T?` receiver was empty and CallableInfo carried nothing to bind T
against; CallableInfo now uses SymbolEntry::declared_extension_receiver
- a real extension is not a method of its receiver's type, so the return came
from the SignatureDerived strategy, which never substituted from the
receiver; it now does, for `.`-calls
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Receiver nullability and same-named callable collisions can produce incorrect inferred types.
Review effort: Balanced
Findings: 2
Open (3)
What changed in this PR
Adds generic return-type substitution for extension functions with plain type-parameter receivers.
Changes:
- Adds declared extension-receiver lookup.
- Applies receiver substitution to signature-derived returns.
- Adds regression tests for
T?.required().
| File | Description |
|---|---|
src/types.rs |
Adds declared receiver accessor. |
src/indexer.rs |
Uses declared receivers in callable metadata. |
src/indexer/infer/chain.rs |
Extends receiver-based substitution. |
src/indexer/infer/mod_tests.rs |
Tests signature-derived substitution. |
src/indexer_tests.rs |
Tests plain receiver metadata. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…hable callable info, naming) - T? vs T receivers bind a whole-receiver type param by declared nullability; the parser now keeps the receiver's ? marker (CACHE_VERSION 33) - find_fun_callable_info prefers the declaration reachable from the call site over an unrelated same-named generic - rename subst -> substitution in the new code Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.


Problem
fun <T : Any> T?.required(field: String): T(Moneta'sNullableScope) inferred its return type as the literal"T", sotextModel.required("textModel").titlesearched fortitleon a class namedTand missed.Root cause (two independent bugs, both hidden by #318's test)
extension_receiver_typeonly when the receiver has generics, so a plainT?receiver was empty andCallableInfohad nothing to bindTagainst.CallableInfonow usesSymbolEntry::declared_extension_receiver()(full type if generic, else base name).receiver_based_methodnever matched and the return came fromSignatureDerived, which never substituted from the receiver. It now does for.-calls (callee_receiver_typeextracted and shared).Tests
callable_info_reports_a_non_generic_type_param_receiver(red before)resolve_call_expr_type_substitutes_extension_receiver_for_a_signature_derived_return(red before)cargo test(2015),clippy -D warnings,fmtcleanVerification
Literal repro
InitUseCase.kt:56:47in Moneta now resolves (was a Gap); minimal fixture went FilteredCandidate -> resolved. Aggregate Moneta recall is flat (~91.9% member): this is one small slice of thetitlegap; the rest are separate causes being handled in follow-up PRs.🤖 Generated with Claude Code