Skip to content

Missing checks for existential types leads to unsoundness #583

Closed
@smarter

Description

@smarter

this should not compile:

import scala.collection.mutable.ListBuffer

object Test {
  def main(args: Array[String]): Unit = {
    val f: ListBuffer[Int] = ListBuffer(1,2)
    val g: ListBuffer[Double] = ListBuffer(3.0,4.0)
    val lb: ListBuffer[ListBuffer[_ <: AnyVal]] = ListBuffer(f, g)
    lb(0)(0) = lb(1)(0)
    val x: Int = f(0) // ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
  }
}

In scalac it fails with:

t583.scala:8: error: type mismatch;
 found   : (some other)_$1(in method main) where type (some other)_$1(in method main) <: AnyVal
 required: _$1(in method main) where type _$1(in method main) <: AnyVal
    lb(0)(0) = lb(1)(0)
                    ^
one error found

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions