Skip to content

Unsound reduction of match types  #19746

Closed
@EugeneFlesselle

Description

@EugeneFlesselle

Compiler version

3.4.2-RC1

Minimized example

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

trait W[+Y] extends V

extension (self: Any) def as[T]: T =
  def asX(w: W[Any]): w.X /* <- reduces to Any */ = self
  asX(new W[T] {}) /* <- reduces to T */

0.as[Boolean] // java.lang.ClassCastException

The issue is that w.X reduces to Any because the scrutinee w is widened to W[Any] before attempting the reduction of the match type.

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions