-
Notifications
You must be signed in to change notification settings - Fork 833
Description
Related #5475.
What
The following code compiles with warnings which could be improved upon.
module DUs =
type Countries =
| CA
| US
| GB
let x = DUs.CA
let output =
match x with
| US -> "US"
| CA -> "CA"
| _ -> "XX"
output
There is a warning on | US -> "US" that the value US is unused.

The default pattern has a warning that the rule will never be matched.

Why
If when seeing the warnings you not taking into account that the pattern can be a value or a binding this is confusing in two ways.
- In the above example is is obvious that
USis out of scope. But in larger files this may not be obvious. Moreover normally referencingUSwithout openingDUswould result in "The value or constructor US is not defined..." The message that it will never be used does not really point in the right direction. - The warning that the default pattern will never be matched is also confusing. Why not, should they not always match. And if the
CAis never used why does the default not match?
And when this code is run it results in "US" which can also be confusing.
Finally because there are only warnings this could result in a bug.
How
The compiler is assuming that | CA is a binding of x to CA not used on the right and emits a message to explain that situation. It should also suggest that CA might be an undefined value. Something like
"Binding CA is not used in this rule or CA refers to a value not defined..."
Metadata
Metadata
Assignees
Labels
Type
Projects
Status