Potential Bug in `Match.tags` with Undefined Input

Seems like there might be a bug in Match.tags:

I would expect the second to not throw but fallback onto orElse case and return null:

import { Match } from 'effect'

type MyTepe = { _tag: 'A' } | undefined

const ok = Match.type<MyTepe>().pipe(
  Match.when({ _tag: 'A' }, () => 'A'),
  Match.orElse(() => null),
)(undefined)

// Prints: { ok: null }
console.log({ ok })

// Throws:
// node_modules/effect/src/internal/matcher.ts:390
//   (_: any) => _[field] in fields,
// TypeError: Cannot read properties of undefined (reading '_tag')
const boom = Match.type<MyTepe>().pipe(
  Match.tags({ A: x => x._tag }),
  Match.orElse(() => null),
)(undefined)

console.log({ boom })
Was this page helpful?