Skip to content

Conversation

@jchyb
Copy link
Contributor

@jchyb jchyb commented Jan 15, 2026

When simplifying an inline match, the compiler intentionally recalculates the type of the scrutinee by removing Typed nodes. However, after that recalculation, it uses that type to define a scrutinee proxy symbol, which would cause typing errors, when it would try to point to the original tree eg:
it would generate:

val b: B // B <: A
val scrutinee$: B // type recalculated from (b: A)
  = (b: A) // original tree; after this fix we add .asInstanceOf[B]

The reason this issue has been unnoticed before is because for the proxy symbol to appear, the scrutinee has to be used on the right hand side (directly or through an unapply pattern) which the original tests didn't have.

Fixes #24479
Some additional context: #11291

jchyb added 2 commits January 15, 2026 18:36
When simplifying an inline match, the compiler intentionally
recalculates the type of the scrutinee by removing Typed nodes.
However, after that recalculation, it uses that type to define
a scrutinee proxy symbol, which would cause typing errors, when it would
try to point to the original tree eg:
it would generate:
```
val b: B // B <: A
val scrutinee$: B // type recalculated from (b: A)
  = (b: A) // original tree; after this fix we add .asInstanceOf[B]
```
The reason this issue has been unnoticed before is because for the proxy
symbol to appear, the scrutinee has to be used on the right hand side
(directly or through a unapply pattern) which the original tests didn't
have.
@jchyb jchyb force-pushed the fix-i24479-inline-match-ascription branch from 5166282 to 5abb96c Compare January 16, 2026 12:25
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.

Incorrect type error after inlining

1 participant