Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match no longer compatible with identity #4556

Open
thewilkybarkid opened this issue Mar 5, 2025 · 5 comments
Open

Match no longer compatible with identity #4556

thewilkybarkid opened this issue Mar 5, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@thewilkybarkid
Copy link
Contributor

thewilkybarkid commented Mar 5, 2025

What version of Effect is running?

3.13.6

What steps can reproduce the bug?

import { identity, Match, pipe } from "effect"

const withIdentity: (u: "foo" | "bar") => "foo" | "baz" = pipe(
  Match.type<"foo" | "bar">(),
  Match.when("foo", identity),
  Match.when("bar", () => "baz" as const),
  Match.exhaustive
)

const withoutIdentity: (u: "foo" | "bar") => "foo" | "baz" = pipe(
  Match.type<"foo" | "bar">(),
  Match.when("foo", (value) => value),
  Match.when("bar", () => "baz" as const),
  Match.exhaustive
)

https://effect.website/play#8b9250181318

What is the expected behavior?

Both are assignable.

What do you see instead?

withIdentity has a type error:

Type '(u: "foo" | "bar") => unknown' is not assignable to type '(u: "foo" | "bar") => "foo" | "baz"'.

Additional information

PREreview/prereview.org#2279 is failing, as some of our matchers now have an inferred return type of unknown (e.g. https://github.com/PREreview/prereview.org/blob/59804ce6fc1f444f0fa4ed579a94d01af6d1c6d1/src/Comments/Evolve.ts#L5-L17)

Could be related to #4530

@thewilkybarkid thewilkybarkid added the bug Something isn't working label Mar 5, 2025
@tim-smart
Copy link
Contributor

That PR didn't touch the .when signature, so I think the cause must be something else 🤔

@thewilkybarkid
Copy link
Contributor Author

I spent some time trying to debug, but I couldn't isolate the change that caused the failure.

It's working fine with 3.13.4 but starts failing with 3.13.5.

@gcanti
Copy link
Contributor

gcanti commented Mar 10, 2025

@thewilkybarkid I get the same error with 3.13.4

@thewilkybarkid
Copy link
Contributor Author

Looking at it closer, my reproduction isn't right: when using Match.tag it works in 3.13.4 but fails after. When using Match.when, it never seems to have worked...

@thewilkybarkid
Copy link
Contributor Author

thewilkybarkid commented Mar 10, 2025

Works in 3.13.4, but not newer versions:

import { identity, Match, pipe } from "effect"

type Foo = { _tag: 'foo' }
type Bar = { _tag: 'bar' }

const withIdentity: (u: Foo | Bar) => Foo | "baz" = pipe(
  Match.type<Foo | Bar>(),
  Match.tag("foo", identity),
  Match.tag("bar", () => "baz" as const),
  Match.exhaustive
)

const withoutIdentity: (u: Foo | Bar) => Foo | "baz" = pipe(
  Match.type<Foo | Bar>(),
  Match.tag("foo", (value) => value),
  Match.tag("bar", () => "baz" as const),
  Match.exhaustive
)

https://effect.website/play#2ddf17cdcbe1

thewilkybarkid added a commit to PREreview/prereview.org that referenced this issue Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants