Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix ICE on named-arg indexer setter (#16034)#19851

Merged
T-Gro merged 12 commits into
mainfrom
fix/issue-16034
Jun 12, 2026
Merged

Fix ICE on named-arg indexer setter (#16034)#19851
T-Gro merged 12 commits into
mainfrom
fix/issue-16034

Conversation

@T-Gro

@T-Gro T-Gro commented May 28, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #16034 — calling an indexed property setter with a named argument (e.g. .indexed1(a1="ok") <- 1) caused an internal compiler error (FS0193 / ArgumentException: The input must be non-negative).

Root Cause

When a named argument matches one of the indexer arguments of a property setter, the remaining unnamed called args may number fewer than 2. The ParamArray detection in MethodCalls.fs used UnnamedCalledArgs - 2 unconditionally for indexer setters, leading to a negative index into calledArgs.

Fix

  • Gate the setter-shape indexing on UnnamedCalledArgs >= 2 and fall back to the regular path otherwise.
  • Skip the unnamed-arg-prefix deprecation check for indexer setters, since the trailing 'value' arg breaks the strict (i, j) position match when an indexer arg is supplied by name.

Tests

Added IndexedSetterNamedArgTests.fs covering:

  • Single-index setter with named arg
  • Multi-index setter with one named arg
  • Named value arg on setter
  • Extension-method indexed setter with named arg

All variants compile and typecheck without error.

Copilot and others added 3 commits May 28, 2026 15:17
When a named argument matches one of the indexer arguments of a property setter, the remaining unnamed called args may number fewer than 2. The ParamArray detection used nUnnamedCalledArgs-2 unconditionally for indexer setters, leading to a negative index and FS0193. Gate the setter-shape indexing on nUnnamedCalledArgs >= 2 and fall back to the regular path otherwise. Also skip the unnamed-arg-prefix deprecation check for indexer setters, since the trailing 'value' arg breaks the strict (i,j) position match when an indexer arg is supplied by name.

Co-authored-by: Copilot <[email protected]>
@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

❗ Release notes required

You can open this PR in browser to add release notes: open in github.dev


✅ 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

@github-actions github-actions Bot added the AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed label May 28, 2026
@T-Gro T-Gro requested a review from abonie May 29, 2026 11:08
@T-Gro T-Gro enabled auto-merge (squash) May 29, 2026 11:08
T-Gro and others added 3 commits May 29, 2026 13:08
- Moved release note entry from 9.0.300.md to 11.0.100.md (correct version)
- Replaced 4-line prose comment with a single-line code example

Co-authored-by: Copilot <[email protected]>

@T-Gro T-Gro left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Review of PR #19851 — Fix ICE on named-arg indexer setter (#16034)

Overall: This is a clean, well-targeted fix for a genuine ICE (internal compiler error). The core logic is correct and the tests are comprehensive. Approving with minor observations.


✅ What works well

  1. MethodCalls.fs guard — The useIndexerSetterShape variable cleanly separates the concern: only use the setter-specific ParamArray path when there are actually ≥2 unnamed called args. This prevents the negative-index crash without changing behavior for the common case.

  2. Tests — Good coverage of the exact repro (single-index named arg), multi-index scenarios, extension properties, getter verification, and multiple call shapes via [<Theory>].

  3. Minimal surface area — The new IsIndexerSetter member is a simple delegation of existing state, well-placed next to IsIndexParamArraySetter.


📝 Observations (non-blocking)

  1. PR description mentions ConstraintSolver.fs — The body states "Fix a minor issue in ConstraintSolver.fs where a property-setter indexer arg count was off-by-one" but no such change appears in the diff. This should be removed from the description to avoid confusion for future readers.

  2. Deprecation check suppression breadth (CheckExpressions.fs:10575) — The new not finalCalledMeth.IsIndexerSetter guard suppresses the tcUnnamedArgumentsDoNotFormPrefix warning for all indexer setters, not only those with named args. This is safe in practice — without named args the unnamed positions will match (i, j) anyway and the check passes — but a comment explaining why the blanket suppression is harmless would help future readers:

    // Indexer setters: when index args are named, the remaining unnamed args'
    // Position values won't form a prefix (the 'value' arg has a non-zero j).
    // Without named args the check passes naturally, so blanket skip is safe.
  3. Missing doc comment on IsIndexerSetter (MethodCalls.fsi:274) — A one-line XML doc like /// True when this method call is for a property indexer setter (set_Item or named indexer set) would align with the surrounding style.


Summary

The fix correctly guards the ParamArray detection against the case where named arguments reduce the unnamed-arg count below the expected minimum for indexer setters, and correctly suppresses a false-positive deprecation warning. No functional issues found.

@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label Jun 3, 2026
@github-project-automation github-project-automation Bot moved this from New to In Progress in F# Compiler and Tooling Jun 11, 2026
abonie and others added 3 commits June 12, 2026 10:31
- Add XML doc comment on IsIndexerSetter in MethodCalls.fsi
- Add comment explaining why blanket indexer setter suppression is safe
- PR description updated to remove incorrect ConstraintSolver.fs mention

Co-authored-by: Copilot <[email protected]>
@T-Gro

T-Gro commented Jun 12, 2026

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Copilot and others added 3 commits June 12, 2026 17:46
The merge with main inadvertently dropped the NoWarn;MSB3277 entries from
fsc.targets and fsi.targets. These suppress a build-time conflict between
System.ValueTuple 4.0.2.0 (.NET Framework 4.7.2 facade) and 4.0.5.0
(pulled transitively by System.Text.Json/System.Formats.Nrbf). Binding
redirects handle this at runtime; the warning is harmless.

Co-authored-by: Copilot <[email protected]>
@T-Gro T-Gro merged commit aa00b17 into main Jun 12, 2026
50 checks passed
T-Gro added a commit that referenced this pull request Jun 15, 2026
Branch was behind main again. Auto-merge resolved IlxGen.fs, Optimizer.fs,
TypedTreeOps.ExprConstruction.fs, and one baseline cleanly.

Verified post-merge: SEQ=PAR FCS.dll byte-identical, sin/abs quotation passes.

(#19928)

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-reviewed PR reviewed by AI review council AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

SNAFU with indexed properties & type extensions: internal error & inconsistency over shadowing

2 participants