Skip to content

Narrow 'No matching overload' error range to method name only#19505

Draft
Copilot wants to merge 1 commit intomainfrom
copilot/fix-9141961-29048891-ac83c611-04a8-4bbc-9d1f-393ac1d7c4ba
Draft

Narrow 'No matching overload' error range to method name only#19505
Copilot wants to merge 1 commit intomainfrom
copilot/fix-9141961-29048891-ac83c611-04a8-4bbc-9d1f-393ac1d7c4ba

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

The "No overloads match for method" error (Error 41) previously covered the entire expression including object access chains and arguments. For example, T.Instance.Method("") would underline everything from T to "). This is especially problematic on larger expressions where the wide error range hides other errors and warnings.

Changes Made

  • src/Compiler/Checking/Expressions/CheckExpressions.fs: After ResolveOverloadingForCall returns, intercept UnresolvedOverloading errors and narrow the range from the whole expression (mMethExpr) to just the method name identifier. The method-name-only range is computed from mItem.End and methodName.Length.

  • tests/FSharp.Compiler.ComponentTests/ErrorMessages/OverloadResolutionErrorRangeTests.fs: Added 4 regression tests verifying the error range covers only the method name for:

    • Instance method calls (T.Instance.Method(""))
    • Static method calls (T.Method(""))
    • Chained expressions (T.Instance.Next.Next.Method(""))
    • Lambda arguments (T.Instance.Method(fun () -> ""))

Before

Error underlines the entire T.Instance.Method("") expression.

After

Error underlines only Method, leaving the rest of the expression clean for other diagnostics.


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

@T-Gro
Copy link
Copy Markdown
Member

T-Gro commented Mar 27, 2026

@copilot : Try again

@T-Gro
Copy link
Copy Markdown
Member

T-Gro commented Mar 27, 2026

@copilot : Try again.

@abonie
Copy link
Copy Markdown
Member

abonie commented Mar 31, 2026

@copilot Try again

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot Try again

Implemented the fix in commit aa4c1a9. The UnresolvedOverloading error range is now narrowed from the whole expression (mMethExpr) to just the method name identifier by computing the method-name-only range from mItem.End and methodName.Length in TcMethodApplication.

For T.Instance.Method(""), the error now covers only Method (Col 12-18) instead of the entire T.Instance.Method("") expression (Col 1-22). Added 4 regression tests covering instance calls, static calls, chained expressions, and lambda arguments. Tests and compiler build pass. Release notes and full test suite validation still pending.

Copilot AI changed the title [WIP] Copilot Request Narrow 'No matching overload' error range to method name only Mar 31, 2026
Copilot AI requested a review from abonie March 31, 2026 14:46
@T-Gro T-Gro force-pushed the copilot/fix-9141961-29048891-ac83c611-04a8-4bbc-9d1f-393ac1d7c4ba branch from aa4c1a9 to 7d2f1e9 Compare April 9, 2026 12:56
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.100.md

Comment on lines +10404 to +10407
// Narrow the error range for unresolved overloading from the whole expression (mMethExpr)
// to just the method name. For instance calls like T.Instance.Method(""), mItem covers
// the entire "T.Instance.Method" range, so we compute the method-name-only range from
// the end of mItem and the method name length. See https://github.com/dotnet/fsharp/issues/14190.
Copy link
Copy Markdown
Member

@auduchinok auduchinok Apr 9, 2026

Choose a reason for hiding this comment

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

@T-Gro Have you considered changing how mItem is calculated instead? I think we can get it from the syntax at an earlier stage instead of trying to compute it here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a related issue: #3920

If proper ranges are used during type checking, we won't have to trim them later in the tooling (like it's done for Find Usages and symbol highlighting) or trim them on a case-by-case basis like here.

@T-Gro T-Gro force-pushed the copilot/fix-9141961-29048891-ac83c611-04a8-4bbc-9d1f-393ac1d7c4ba branch 2 times, most recently from 04c3c67 to 49d2bbf Compare April 9, 2026 15:19
Narrows the error range for FS0041 (No overloads match for method) from
covering the entire expression to just the method name. For example,
T.Instance.Method(""") now highlights only 'Method' instead of the
whole 'T.Instance.Method(""")'.

The narrowing is applied in TcMethodApplication after overload resolution
fails. It computes the method-name-only range from the end of mItem,
with guards for multi-line expressions and generic constructors whose
internal names may be longer than the source text.

Includes:
- New OverloadResolutionErrorRangeTests with 4 test cases
- Updated 35+ baseline files for narrowed FS0041 error ranges
- Release notes entry

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro T-Gro force-pushed the copilot/fix-9141961-29048891-ac83c611-04a8-4bbc-9d1f-393ac1d7c4ba branch from 3420474 to 2751d6e Compare April 10, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

4 participants