Skip to content

Destructuring an existential with let reports "this switch" #9069

Description

@cknitt

Destructuring a GADT constructor with an existential type in a let reports a switch that isn't in the source:

type rec any = Any('a, 'a => string): any

let get = value => {
  let Any(x, _) = value
  x
}
This has type: $Any_'a
But this switch is expected to return: 'a
The type constructor $Any_'a would escape its scope

All branches in a switch must return the same type.
To fix this, change your branch to return the expected type.

The let is checked as a match internally, but the hint about switch branches doesn't apply here. (See also the $Any_'a naming in the related issue.)

Activity

  1. added theissue type on Oct 27, 2026
  2. added a commit that references this issue on Oct 28, 2026
    829f98b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions