Skip to content

Conversation

@mrdziuban
Copy link

@mrdziuban mrdziuban commented Jan 27, 2026

Closes #24990

This aims to fix an issue with erased definitions in the presence of opaque types. The expression generated in the test here is:

{
  val $proxy1: test.type{type Foo = Int} =
    test.$asInstanceOf[test.type{type Foo = Int}]
  val test$_this: ($proxy1 : test.type{type Foo = Int}) = $proxy1
  new test$_this.Bar[Int]():test$_this.Bar[Int]
}

This is not considered pure due to the creation of val $proxy1, an opaque proxy. Specifically the call to asInstanceOf is not considered pure.

This updates TypedTreeInfo#statPurity to consider all opaque proxies pure, which allows the whole expression to be considered pure.

This aims to fix an issue with erased definitions in the presence of `opaque type`s. The expression generated in the test here is:

```scala
{
  val $proxy1: test.type{type Foo = Int} =
    test.$asInstanceOf[test.type{type Foo = Int}]
  val test$_this: ($proxy1 : test.type{type Foo = Int}) = $proxy1
  new test$_this.Bar[Int]():test$_this.Bar[Int]
}
```

This is not considered pure due to the creation of `val $proxy1`, an opaque proxy. Specifically the call to `asInstanceOf` is not considered pure.

This updates `TypedTreeInfo#statPurity` to consider all opaque proxies pure, which allows the whole expression to be considered pure.

Closes scala#24990
@mrdziuban mrdziuban changed the title Treat creation of erased class instance in presence of opaque type as pure Treat opaque proxies as pure Jan 28, 2026
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.

Presence of opaque type causes erased class instance to not be a pure expression

1 participant