Skip to content

Empty array as default parameter doesn't work as expected #10117

@Lanayx

Description

@Lanayx

Please provide a succinct description of the issue.

Repro steps

open System.Runtime.InteropServices

type C() =
    member _.M ([<Optional; DefaultParameterValue([||]:byte[])>]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

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

Metadata

Metadata

Assignees

Labels

Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.good first issue

Type

Projects

Status

New

Relationships

None yet

Development

No branches or pull requests

Issue actions