Skip to content

Fix #2078: Generic local functions not highlighted properly - #3857

Merged
siegfriedpammer merged 1 commit into
masterfrom
fix-2078-local-function-highlighting
Jul 5, 2026
Merged

Fix #2078: Generic local functions not highlighted properly#3857
siegfriedpammer merged 1 commit into
masterfrom
fix-2078-local-function-highlighting

Conversation

@siegfriedpammer

@siegfriedpammer siegfriedpammer commented Jul 4, 2026

Copy link
Copy Markdown
Member

Fixes #2078.

LocalFunctionMethod.MemberDefinition returned the (possibly specialized) instance itself, so the declaration of a generic local function and its use sites never compared equal, and the text view could not group them for click-highlighting: the declaration's base method is an identity specialization, while every call/ldftn site carries the use-site substitution.

Changes:

  • LocalFunctionMethod.MemberDefinition now returns a LocalFunctionMethod wrapping baseMethod.MemberDefinition (or this when the base method already is the definition).
  • TextTokenWriter.GetCurrentLocalDefinition/GetCurrentLocalReference record that MemberDefinition, so the declaration and all use sites share equal reference objects. Method-group references to local functions (delegate conversions) are now surfaced as local references at all: GetSymbol() returns null for a MethodGroupResolveResult, so they previously were not clickable.
  • Tests: a token-writer test asserting reference-object equality (including hash codes) for a generic local function in a non-generic and in a generic enclosing method, plus a headless UI test that clicks a use site and asserts the definition and every use are highlighted as one group. The token-writer test helpers now keep the PEFile alive while assertions run; formatting a recorded type-system object after disposal crashed with an AccessViolationException.

Verified on Linux: full ICSharpCode.Decompiler.Tests (2305) and ILSpy.Tests (977) suites green.

This PR was prepared by an AI agent (Claude Code) operated by @siegfriedpammer.

🤖 Generated with Claude Code

LocalFunctionMethod.MemberDefinition returned the instance itself, so the
declaration of a generic local function (whose base method is an identity
specialization) and its use sites (whose base methods carry the use-site
substitutions) never compared equal, and click-highlighting could not group
them. Returning a wrapper around the unspecialized base method lets the
token writer record the same definition object for the declaration and all
use sites. Method-group references to local functions additionally need
their own lookup, because GetSymbol() does not surface a
MethodGroupResolveResult.

The token-writer tests now keep the PEFile alive for the duration of each
test: recorded references are type-system entities that lazily read from
the PE image, and formatting one in an assertion message after disposal
crashed with an AccessViolationException.

Assisted-by: Claude:claude-fable-5:Claude Code
@siegfriedpammer
siegfriedpammer force-pushed the fix-2078-local-function-highlighting branch from 5261483 to f1b2737 Compare July 4, 2026 19:06
@siegfriedpammer
siegfriedpammer merged commit f2b51d2 into master Jul 5, 2026
13 checks passed
@siegfriedpammer
siegfriedpammer deleted the fix-2078-local-function-highlighting branch July 7, 2026 13:50
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.

Generic local functions not highlighted properly

1 participant