-
Notifications
You must be signed in to change notification settings - Fork 833
Description
If a discriminated union case doesn't define a field, then a wildcard used in a matching pattern should raise an error, just as a variable reference would.
Repro steps
Consider the type:
type Help =
| Today
| Tomorrow
And the module:
module HelpMod =
let helpWhen =
function
| Today -> "help me Today!"
| Tomorrow -> "help me Tomorrow!"
Now consider the following module:
// compiles just fine, but shouldn't
module HelpMod =
let helpWhen =
function
| Today _ -> "help me Today!"
| Tomorrow _ -> "help me Tomorrow!"
And compare that with this:
// fails to compile: FS0019: This constructor is applied to 1 argument(s) but expects 0
module HelpMod =
let helpWhen =
function
| Today x -> "help me Today!"
| Tomorrow x -> "help me Tomorrow!"
Expected behavior
Neither should compile. The wildcard character is not ignorable. Compare, for instance, fun _ -> true, this is the same as fun a -> true. While the wildcard is more flexible in pattern matching, it is a replacement character for something, but here it seems to replace nothingness, which doesn't exist in F# (it isn't even unit here).
Actual behavior
The example with the wildcard compiles (but I think it shouldn't).
Known workarounds
None. Unless a workaround is to ignore this. But I think it is a syntax error that is ignored by the compiler.
Related information
Using F# 4.0, .NET 4.6 (didn't test with other .NET versions) with VS2015 Update 3.