scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

failure to infer hk type parameter #10653

Open martijnhoekstra opened 6 years ago

martijnhoekstra commented 6 years ago
object Foo {
  case class Baz[F[_]](f: F[Int])
  type ListOption[A] = List[Option[A]]

  val l: List[Option[Int]] = List(Option(7))
  val l2: ListOption[Int] = l
  val l3: ({type l[a] = List[Option[a]]})#l[Int] = l
  val baz = Baz(l) //infers Baz[Any]
  val bup = Baz(l2) //correctly infers Baz[ListOption] 
  val bur = Baz(l3) //infers Baz[Any] again
}

val l: List[Option[Int]] = Foo.baz should compile but gives

type mismatch;
 found   : Any
 required: List[Option[Int]]

possibly related to https://github.com/scala/bug/issues/5075 ?

reproduced in 2.12.3

in dotty the error is

 found:    scala.collection.TraversableOnce.FlattenOps[Int](Foo.baz.f)
   |   required: scala.collection.immutable.List[Option[Int]]

repro: https://scastie.scala-lang.org/martijnhoekstra/k9RFNIjCQk2pcI5vvanzow

martijnhoekstra commented 6 years ago

maybe fixed by https://github.com/scala/scala/pull/6069

I can't verify due to my personal incompetence with the sbt runner (

> scalac -Xsource:2.13 ./sandbox/test.scala
[error] Expected non-whitespace character

)

SethTisue commented 1 year ago

it compiles in 2.12.3 (and 2.12.17)

but then 2.13.10 gives:

On line 8: error: inferred kinds of the type arguments (AnyVal) do not conform to the expected kinds of the type parameters (type F).
       AnyVal's type parameters do not match type F's expected parameters:
       class AnyVal has no type parameters, but type F has one
         val baz = Baz(l) //infers Baz[Any]
                       ^
On line 8: error: type mismatch;
        found   : List[Option[Int]]
        required: F[Int]
         val bur = Baz(l3) //infers Baz[Any] again
                   ^

and Scala 3.3.0-RC3 agrees:

8 |  val baz = Baz(l) //infers Baz[Any]
  |                ^
  |Found:    (Foo.l : List[Option[Int]])
  |Required: F[Int]
  |
  |where:    F is a type variable with constraint <: [_] =>> Any