Skip to content

Match.type handlers receive the matched input twice #10873

In review

Description

@jasonkuhrt

Written by an AI agent (Amp) on behalf of @jasonkuhrt.

What version of Effect is running?

effect 4.1.5, the latest release, and main at 0d2bb4a. 4.0.0-rc.110 is not affected.

What steps can reproduce the bug?

Since 4.0.0-rc.111, a Match.type handler receives the matched input twice. A handler with an optional second parameter, such as parseInt and its radix, reads the input as that parameter.

npm init -y && npm pkg set type=module
npm install --save-exact [email protected]
// repro.mjs
import { Match } from "effect"

const parse = Match.type().pipe(
  Match.when(Match.string, parseInt),
  Match.orElse(() => -1)
)

const argumentCount = Match.type().pipe(
  Match.when(Match.string, function() {
    return arguments.length
  }),
  Match.orElse(function() {
    return arguments.length
  })
)

console.log(parse("8"), argumentCount("x"), argumentCount(1))
node repro.mjs # Node 24.22.3

What is the expected behavior?

8 1 1

This is what 4.0.0-rc.110 prints (npm install --save-exact [email protected]). Each handler gets the matched value alone, as the handler type declares: Match.when takes (_: WhenMatch<R, P>, ...args: Args) => Ret, and Args is [] for a Match.type matcher.

What do you see instead?

NaN 2 2

parseInt is called as parseInt("8", "8") and parses in base 8. Both the when handler and the orElse handler get two arguments.

Additional information

#7363 added Match.fn in 4.0.0-rc.111, and its description says it carries the selector's arguments "without changing Match.type or Match.value". Since then the terminals call each case as evaluate(input, ...args) and orElse calls its handler as f(failure, ...args), with the arguments the matcher was called with. A Match.type matcher's selector is identity, so that one argument is the input itself, and every handler gets (input, input). Match.value is not affected.

Activity

  1. self-assigned this
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions