Skip to content

Conversation

@mpalat
Copy link
Contributor

@mpalat mpalat commented Jan 2, 2026

Fixes #1361

What it does

  • The type inference in record pattern was more restrictive in implementation compared to what was mentioned in spec.

In JLS Section 18.5.5, item 5 says "Unlike normal resolution, in this case resolution skips the step that attempts to produce an instantiation for an inference variable from its proper lower bounds or proper upper bounds; instead, any new instantiations are created by skipping directly to the step that introduces fresh type variables."

However, the entire processing was missed via the !recordTypeInference condition which implied that the " α1 = T1, ..., αn = Tn" were consequently missed being incorporated with the current bound set as per this line in JLS Section 18.4

The fix addresses this part.

Fixes issue #1361

How to test

The reviewer can use the code mentioned in issue #1361 to test the fix.

Author checklist

@mpalat
Copy link
Contributor Author

mpalat commented Jan 2, 2026

@stephan-herrmann : requesting for a review both for the reasoning and the implementation (thanks!) - one clarification here (assuming that you find the logic above correct), is whether a similar skip is required at the Capture conversion part in the second attempt.

@stephan-herrmann
Copy link
Contributor

I would need some help to follow the reasoning.

"Unlike normal resolution, in this case resolution skips the step that attempts to produce an instantiation for an inference variable from its proper lower bounds or proper upper bounds; instead, any new instantiations are created by skipping directly to the step that introduces fresh type variables"

At a quick look this seems to correspond directly to the block being skipped based on recordTypeInference. Inside that block each inference variable is treated by one of three branches for (a) proper lower bounds, (b) inThrows, (c) proper upper bounds. Each branch has its specific definition for Ti, which is then used in

The bounds α1 = T1, ..., αn = Tn are incorporated with the current bound set.

Hence we directly skip to the "second attempt" for which no skipping is defined in the spec. All this looks fine to me in master.

Am I missing anything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[21] Record type inference fails when 'var' and <> mixed

2 participants