dotnet / dotnet/fsharp

Prohibit `OptionaArgumentAttribute` on interface members

Open
#16,059 10 comments 0 reactions 1 assignee Claimed by @edgarfgp View on GitHub
Bug Impact-Medium Needs-design
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

When I declared such interface

``` F#
type IDocumentServiceClient =
abstract member CreateDocument: fileName:string * [] cancellationToken:CancellationToken -> CreateDocument Task
abstract member UploadDocument: signedUrl:string * stream:Stream * [] cancellationToken:CancellationToken -> Result Task
abstract member GetDocument: documentId:string * [] cancellationToken:CancellationToken -> GetDocument Task
```

On call a method call without `cancellationToken` I got `Common Language Runtime detected an invalid program`.
This led to a long debugging to figure out what is wrong

**Repro steps**

1. Declare interface
2. Declare member in it with 2 tupled input parameters with names
3. Apply `[]` to the last parameter
4. Implement interface
5. Call interface method on implementation with the first only parameter
6. See exception with the message as above

**Expected behavior**

Compiler prohibits applying `OptionaArgumentAttribute` to interface member with clear compile-time error

**Actual behavior**

Compiler tells nothing and weird exception appears in runtime

**Related information**

Provide any related information (optional):

.NET 7.0.401
F# Core 7.0.401

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.