Skip to content

Check for mismatched argument type length in PatternMatcher due to Named Tuple :* syntax #23602

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aherlihy
Copy link
Contributor

@aherlihy aherlihy commented Jul 25, 2025

Fixes #23155

After discussing at the compiler meeting, it was decided that the Named Tuple behavior should be the same as the Tuple behavior with respect to pattern matching with the :* syntax. To error in the exact same way, it should be caught here:

report.error(UnapplyInvalidNumberOfArguments(qual, argTypes), pos)

For regular tuples, argTypes is an AppliedType of :* and is not yet reduced, so has length 1, so the arity check will fail. However, at this point Named Tuple types are fully reduced by tupleElementTypes here:

So for Named Tuples, argTypes at the time of the check will be (Int, Int) so the arity check will pass, causing a later crash in PatternMatcher here:

val sym :: syms1 = syms: @unchecked

We cannot un-reduce or fail to reduce for Named Tuple types because it will cause a host of other tests to fail that rely on the fully reduced Named Tuple-value types. For now I have added a check in PatternMatcher because it’s better to fix the compiler crash ASAP, but I think we could revisit if we want something like Int :* Int :* EmptyTuple to really behave differently from (Int, Int) here, since pattern matching currently works for both Tuples and Named Tuples using (Int, Int) or Tuple2[Int, Int] , just not :*.

@aherlihy aherlihy requested a review from EugeneFlesselle July 25, 2025 18:50
@WojciechMazur WojciechMazur added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Jul 29, 2025
@WojciechMazur WojciechMazur added this to the 3.7.3 milestone Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler crash using Tuple :* syntax for a NamedTuple in unapply
3 participants