Skip to content

Non-recursive GADT gets a different error depending on which constructor is a GADT #9067

Closed

Description

@cknitt

A GADT constructor in a type declared without rec is reported in two different ways.

When the first constructor is a GADT constructor:

type t<'a> = A(int): t<int>
GADTs require recursive type syntax.
Define your type using `type rec` instead of `type`.
Example: type rec t = ...

When a later constructor is one, or in a signature:

type t<_> = Plain | Indexed(int): t<int>
GADT case syntax cannot be used in a 'nonrec' block.

nonrec is not ReScript syntax. The first message comes from a check in bs_ast_invariant.ml that only looks at the first constructor of a structure item; the second is the type checker's own error (Nonrec_gadt in typedecl.ml), which covers every case. The first message also isn't indented like the rest of the error.

Activity

  1. added theissue type on Oct 27, 2026
  2. added a commit that references this issue on Oct 28, 2026
    b661068
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