dotnet / dotnet/fsharp

Indexer setters don't work with optional parameters

Open
#20,046 0 comments 1 reaction 0 assignees View on GitHub
Bug Needs-Triage
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

F#'s Indexer setters don't work with optional parameters, but C#'s do.

Related #9369

**Repro steps**

```fsharp
open System.Runtime.CompilerServices

type A() =
member this.Item
with get (key: string, []?path: string, []?line: int) =
printfn "%A" (key, path, line)
"_"

// error FS1212: Optional arguments must come at the end of the argument list, after any non-optional arguments
and set (key: string, []?path: string, []?line: int) (value: string) =
printfn "%A" (key, path, line)

let t = A()
t["a"]
```

**Related information**

Provide any related information (optional):

* .NET Runtime kind: .NET 11
* Editing Tools: dotnet fsi

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied indexer-setter example in dotnet fsi and compare its behavior with the getter and the stated C# behavior. Trace the compiler handling for optional parameters in indexer setters; done means the example compiles and the setter accepts optional parameters without FS1212.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.