Type a let destructuring a GADT without switch diagnostics
Why
A let whose pattern contains a GADT constructor is typed as a one-case match. Its body was then checked as a switch branch, so a type error there said "But this switch is expected to return" and added the hint about switch branches, although the source has no switch. The synthesized match is now marked like the one for optional argument defaults and gets function-style diagnostics.
modifiedDiagnostic let destructuring a GADT
type rec any = Any('a, 'a => string): any let get = value => { let Any(x, _) = value x}
diagnostic
Before
After
This has type: $aThis has type: $aBut this switch is expected to return: 'aBut it's expected to have type: 'a$a is an existential type bound by the constructor Any.$a is an existential type bound by the constructor Any.It is only known in the scope of the pattern that matches Any.It is only known in the scope of the pattern that matches Any. All branches in a switch must return the same type.To fix this, change your branch to return the expected type.