-
Notifications
You must be signed in to change notification settings - Fork 833
Description
There is an inconsistency in how an incorrect placement of [<DefaultParameterValue>]
is handled. Usually, in most situations, the parameter is simply not treated as optional at all, but if it is of type obj
, it seems it is still considered optional.
Repro steps
open System.Runtime.InteropServices
type C =
static member Foo([<Optional>][<DefaultParameterValue("hello")>] obj: obj) =
printfn "%A" obj
C.Foo()
Expected behavior
C.Foo()
should fail to compile, since the attribute has mismatched type and thus even [<Optional>]
is ignored.
Actual behavior
The code compiles and passes null
to Foo
, in contrary to the warning:
FS3211 The default value does not have the same type as the argument. The DefaultParameterValue attribute and any Optional attribute will be ignored. Note: 'null' needs to be annotated with the correct type, e.g. 'DefaultParameterValue(null:obj)'.
Known workarounds
Providing a different type than obj
(as far as I can tell) correctly stops the code from being compilable at all.
Related information
Metadata
Metadata
Assignees
Labels
Type
Projects
Status