Skip to content

Untagged variant puts one typed array in another typed array's case #8955

Open

Description

@cristianoc

An untagged variant with cases for two typed arrays accepts a value of one typed array in the case of the other, and the value then matches the other case.

@unboxed type ta = I8(Int8Array.t) | U8(Uint8Array.t)
let f = v => switch v { | I8(_) => "i8" | U8(_) => "u8" }
Console.log(f(I8(Uint8Array.fromArray([1]))))

Output: u8.

The typed-array types are abbreviations of one type, so I8(Uint8Array…) type-checks. The cases are classified by the type name as written, so the run-time check is instanceof Uint8Array.

Expected: either the cases are distinct types, so that I8(Uint8Array…) is a type error, or the variant is rejected because two cases share one type.

The rule is compiler/ml/UntaggedVariants.md rule 5, in #8952. #8950 changes how these types are recognized.

Activity

  1. added theissue type on Oct 23, 2026
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