dotnet / dotnet/fsharp

Empty array as default parameter doesn't work as expected

Open
#10,117 3 comments 0 reactions 1 assignee Claimed by @edgarfgp View on GitHub
Area-Compiler-Checking Bug good first issue Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Please provide a succinct description of the issue.

**Repro steps**

```
open System.Runtime.InteropServices

type C() =
member _.M ([]keyBytes:byte[]) =
keyBytes
```

**Expected behavior**

The code either passes empty array as default argument or doesn't compile

**Actual behavior**

The code compiles, but parameter is not optional anymore, I can't call M() without parameters [sharplab](https://sharplab.io/#v2:DYLgZgzgNAJiDUAfA9gBwKYDsAEBlAnhAC7oC2AsAFBpZ6EmkB0ASgK6ZECWp6jAkh3QAnNLmEA3TgGN0EKlSL4M2AMIAKAJTYAvFWz7sPUgCNh2APqMAstjUBtADwB5VF2SYAhsADc2ACLoYB6swEQACh5CHjwkQgBqXqzo9oiIALogxvgkdmkaAHxpANbo+ABC2bKZlbla2th6Bk0l5ZVylE1GpkLYRAAWnBCMAGKaOo1N+v2D1ppAA===)

**Known workarounds**

Use null instead of empty array. Fsharp-style optional argument won't work, since the method is exposed from library

**Related information**

.NET Core SDK (reflecting any global.json):
Version: 3.1.101
Commit: b377529961

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows

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.