Skip to content

Match.tag crashes on union type including null/undefined #6017

@Hurtak

Description

@Hurtak

What version of Effect is running?

3.19.15

What steps can reproduce the bug?

When using Match.tag on union type that includes undefined/null, it will produce runtime error when the Match.tag is before Match.when(undefined, ...). The code type checks correctly.

Reproduciton steps

import { Match } from "effect"

const value = undefined as ({_tag: "A"} | undefined)

const res = Match.value(value).pipe(
  Match.tag('A', () => 'mached A'), // <- crashes with `Cannot read properties of undefined (reading '_tag')`
  Match.when(undefined, () => 'matched undefined'),
  Match.exhaustive
);
console.log(res);

Or in playground: https://effect.website/play/#b2df3d05e29a

What is the expected behavior?

The code does not crash

What do you see instead?

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions