Skip to content

Wrong type constructor parameter inference of Nothing when using contra-variant implicit parameter. #9842

Closed
@Sciss

Description

@Sciss

Minimized code

trait Measure[-C, M]

implicit object PathMeasure extends Measure[Long, (Int, Long)]

object FingerTree {
  def empty[V, A](implicit m: Measure[A, V]): FingerTree[V, A] = ???
}
trait FingerTree[V, +A] {
  def :+[A1 >: A](b: A1)(implicit m: Measure[A1, V]): FingerTree[V, A1]
}

trait Test {
  def readPathComponent(): Long
  
  def read(sz: Int): Any = {
    var tree  = FingerTree.empty(PathMeasure)  // problem origin
    var i = 0
    while (i < sz) {
      tree = tree :+ readPathComponent()   // problem shows here
      i += 1
    }
    ???
  }
}

Output

In the line 'problem shows here':

Found:    Long
Required: Nothing

Thus var tree has type FingerTree[?, Nothing] instead of FingerTree[(Int, Long), Long]

Expectation

Should not infer Nothing (no problem in Scala 2.13)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions