Skip to content

Unsound type widening for setters with wildcard types #2928

Closed
@liufengyun

Description

@liufengyun

This might be a known problem. The following code compiles in dotc and produces run-time exception. Scalac compiler rejects the code.

class Box[T](var v: T)

object Test {
 def main(args: Array[String]): Unit = {
   val s = new Box[String]("")
   val i = new Box[Int](3)

   var box: Box[_] = s
   val sv = box.v
   box = i
   box.v = sv

   val c: Int = i.v
 }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions