Skip to content

fix: parameter diagnostics correctly resolve extension functions#158

Open
Hessesian wants to merge 4 commits into
mainfrom
feature/unified-resolution
Open

fix: parameter diagnostics correctly resolve extension functions#158
Hessesian wants to merge 4 commits into
mainfrom
feature/unified-resolution

Conversation

@Hessesian
Copy link
Copy Markdown
Owner

Summary

Fixes parameter diagnostics to correctly resolve extension functions (both same-file and cross-file/JAR) when checking argument counts. Previously, diagnostics could report wrong parameter counts from member functions instead of the correct extension function.

Changes

src/indexer/infer/sig.rs — Simplified resolve_qualified

  • Replaced 141-line implementation (cognitive complexity 36) with clean 80-line version
  • Reuses existing build_result helper for deduplication
  • Two-phase approach:
    1. Search definitions index filtering by receiver type (container for members, extension_receiver for extensions)
    2. Fall back to extension_by_receiver for JAR-only extensions

src/features/call_arg_diagnostics_tests.rs — Cross-file extension tests

  • `extension_fn_cross_file_resolved): verifies no diagnostic for correct arg count
  • `extension_fn_cross_file_wrong_arg_count): verifies diagnostic for wrong arg count

Test Results

  • 1253 tests pass, 0 failures
  • Clippy clean (zero warnings, including cognitive_complexity and too_many_lines)

Hessesian added a commit that referenced this pull request Jun 3, 2026
@Hessesian Hessesian force-pushed the feature/unified-resolution branch from dd03b63 to fd375f8 Compare June 3, 2026 16:12
Hessesian added 2 commits June 3, 2026 19:01
Replaced the complex resolve_qualified (141 lines, cognitive complexity 36)
with a clean 80-line implementation that reuses the existing build_result
helper for deduplication.

Two-phase approach:
1. Search definitions index filtering by receiver type (container for members,
   extension_receiver for extensions)
2. Fall back to extension_by_receiver for JAR-only extensions

1253 tests pass, clippy clean (zero warnings).
Comment thread src/indexer/infer/sig.rs Outdated

// Phase 1: definitions index — source-indexed members and extensions.
if let Some(locs) = idx.definitions.get(call.name) {
for loc in locs.iter() {
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

no shortcuts

Comment thread src/indexer/infer/sig.rs Outdated
.filter(|s| {
if s.name != call.name {
return false;
let type_name = rt.leaf.as_str();
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

shortcut

Comment thread src/indexer/infer/sig.rs
let params_text = if !sym.params.is_empty() {
sym.params.clone()
} else if let Some(p) = extract_params_from_detail(&sym.detail) {
p
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

fix shortcuts in this whole file

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes call-argument diagnostics for qualified calls so they resolve the correct target when both member functions and extension functions exist—especially for cross-file/JAR extensions—preventing incorrect parameter-count diagnostics.

Changes:

  • Refactors resolve_qualified in signature inference to prefer receiver-type matching for members/extensions and adds an extension-by-receiver fallback.
  • Adds new diagnostics regression tests covering same-file and cross-file extension function argument counts.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/indexer/infer/sig.rs Rewrites qualified-call signature resolution to filter candidates by inferred receiver type and reuse shared result-building logic.
src/features/call_arg_diagnostics_tests.rs Adds regression tests for qualified extension functions (same-file and cross-file) to validate correct arg-count diagnostics behavior.

Comment thread src/indexer/infer/sig.rs Outdated
Comment on lines +778 to +779
let matches = sym.container.as_deref() == Some(type_name)
|| (sym.container.is_none() && sym.extension_receiver == type_name);
Comment thread src/indexer/infer/sig.rs
Comment on lines +801 to +804
if entry.name != call.name {
continue;
}
let Some(data) = idx
Comment on lines +802 to +808
let src = [
"class IMockProvider",
"inline fun <reified T> IMockProvider.loadJSONFromAssets(path: String): T = TODO()",
"class Foo(private val context: IMockProvider) {",
" val result = context.loadJSONFromAssets(\"test\")",
"}",
]
Comment on lines +826 to +832
let src = [
"class IMockProvider",
"fun IMockProvider.loadJSONFromAssets(path: String): Any = TODO()",
"class Foo(private val context: IMockProvider) {",
" val result = context.loadJSONFromAssets()",
"}",
]
Hessesian added 2 commits June 3, 2026 19:17
…ing member tests

- Rename type_name → receiver_base to match resolver convention
- Replace rt.leaf.as_str() with &rt.leaf, deref comparisons via .as_str()
- Add comment explaining why leaf (not qualified) is correct for container/extension_receiver matching
- Split inline boolean into is_member / is_extension for readability (no shortcuts)
- Add competing member definitions to extension tests per Copilot review:
  - extension_fn_resolved_not_member: add unrelated Service.loadJSONFromAssets() member
  - extension_fn_wrong_arg_count_detected: add unrelated 0-arg competitor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants