Skip to content

Unsound reduction of match type where the scrutinee's prefix is a param ref #20518

@smarter

Description

@smarter

Compiler version

3.5.1-RC1-bin-20240602-c6fbe6f-NIGHTLY

Minimized code

This is a variation of @EugeneFlesselle's #19746:

trait V:
  type X = this.type match
    case W[x] => x

class W[+Y] extends V

trait Outer[+T]:
  val t: T

object Test:
  extension (self: Any) def as[T]: T =
    def asX(o: Outer[W[Any]]): o.t.X /* <- reduces to Any */ = self
    asX(new Outer[W[T]] { val t = W[T]() }) /* <- reduces to T */

  @main def run =
    0.as[Boolean] // ClassCastException

The fix for #19746 in 0a3497b should be generalized to check is(Param) in prefixes too (and maybe that should also apply to TypeRef and not just TermRef).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:match-typesitype:bugitype:soundnessSoundness bug (it lets us compile code that crashes at runtime with a ClassCastException)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions