Fix ICE on named-arg indexer setter (#16034)#19851
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
❗ Release notes requiredCaution No release notes found for the changed paths (see table below). Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format. The following format is recommended for this repository:
If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request. You can open this PR in browser to add release notes: open in github.dev
|
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
UnnamedCalledArgs >= 2 and fall back to the regular path otherwise.
Tests
Added IndexedSetterNamedArgTests.fs covering:
All variants compile and typecheck without error.