Skip to content

Suspect inference incorrectly fails with type parameter #11056

Closed
@hmf

Description

@hmf

Minimized code

  object data {

    trait OfType[T]
    case object IntT extends OfType[Int]
    case object DoubleT extends OfType[Double]
    case object FloatT extends OfType[Float]

    type DSeq[X] = scala.collection.immutable.AbstractSeq[X]

    case class ColumnName[T](n:String, t: OfType[T])
    case class Column[T,F[_]<:DSeq[_]](n:F[T], of: ColumnName[T])
  }

  def min[T,F[_]<:data.DSeq[_]](col: data.Column[T,F])(using o:Ordering[T]): T = {
    col.n.min(o)
  }

  def min0[T,F[_]<:data.DSeq[T]](col: data.Column[T,F])(using o:Ordering[T]): T = {
    col.n.min[T](o)
  }

  def min1[T,F[_]<:data.DSeq[T]](col: data.Column[T,F])(using o:Ordering[T]): T = {
    col match {
      case data.Column(n:F[T],data.ColumnName(_,data.IntT)) => n.min[T](o)
      case data.Column(n,data.ColumnName(_,data.DoubleT)) => ???
      case data.Column(n,data.ColumnName(_,data.FloatT)) => ???

    }
  }

  def min2[T,F[_]<:data.DSeq[T]](col: data.Column[T,F])(using o:Ordering[T]): T = {
    col match {
      case data.Column(n:F[T],data.ColumnName(_,data.IntT)) => n.min[T](Ordering[Int])
      case data.Column(n,data.ColumnName(_,data.DoubleT)) => ???
      case data.Column(n,data.ColumnName(_,data.FloatT)) => ???

    }
  }

  def min3[T,F[X]<:data.DSeq[X]](col: data.Column[T,F])(using o:Ordering[T]): T = {
    col match {
      case data.Column(n:F[T],data.ColumnName(_,data.IntT)) => n.min[T](Ordering[Int])
      case data.Column(n,data.ColumnName(_,data.DoubleT)) => ???
      case data.Column(n,data.ColumnName(_,data.FloatT)) => ???

    }
  }

Output

I get in:

  def min[T,F[_]<:data.DSeq[_]](col: data.Column[T,F])(using o:Ordering[T]): T = {
    col.n.min[T](o)
  }

the error:

[error] 25 |    col.n.min(o)
[error]    |              ^
[error]    |              Found:    (o : Ordering[T])
[error]    |              Required: Ordering[B]
[error]    |
[error]    |              where:    B is a type variable which is an alias of Any
[error] one error found

Even when I use:

  def min[T,F[_]<:data.DSeq[_]](col: data.Column[T,F])(using o:Ordering[T]): T = {
    col.n.min[T](o)
  }

I still get:

[error] 25 |    col.n.min[T](o)
[error]    |    ^^^^^^^^^^^^^^^
[error]    |    Found:    Any
[error]    |    Required: T
[error] one error found

Expectation

I expected min to compile without explicitly setting the DSeq type parameter. The same should be true of all other versions, but I have to use either F[_]<:data.DSeq[T] or even F[X]<:data.DSeq[X]. Maybe I am expecting to much from the inference system?

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