Skip to content

Wrong type inferred for Array ++ #6126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nicolasstucki opened this issue Mar 20, 2019 · 0 comments
Closed

Wrong type inferred for Array ++ #6126

nicolasstucki opened this issue Mar 20, 2019 · 0 comments

Comments

@nicolasstucki
Copy link
Contributor

The following code compiles under scalac but not in dotty.

class Test {
  class Foo[+T](val x: T)

  def unfoo[T](foo: Foo[T]): T = foo.x

  def fooArray: Foo[Array[Object]] = new Foo(Array.empty[Object])

  unfoo(fooArray) ++ unfoo(fooArray)
}

It infers an imprecise type for one of the type argument of the second unfoo

-- [E007] Type Mismatch Error: foo.scala:9:27 --------
9 |  unfoo(fooArray) ++ unfoo(fooArray)
  |                           ^^^^^^^^
  |         Found:    Test.this.Foo[Array[Object]]
  |         Required: Test.this.Foo[scala.collection.GenTraversableOnce[Any]]
result of foo.scala after frontend:
package <empty> {
  class Test() extends Object() { 
    class Foo[T >: Nothing <: Any](x: T) extends Object() { 
       +T
      val x: T
    }
    def unfoo[T >: Nothing <: Any](foo: Test.this.Foo[T]): T = foo.x
    def fooArray: Test.this.Foo[Array[Object]] = 
      new Test.this.Foo[Array[Object]](
        Array.empty[Object](
          scala.reflect.ClassTag.apply[Object](classOf[Object])
        )
      )
    refArrayOps[Object](this.unfoo[Array[Object]](this.fooArray)).++[Object, 
      Array[Object]
    ](this.unfoo[scala.collection.GenTraversableOnce[Object]](this.fooArray))(
      Array.canBuildFrom[Object](
        scala.reflect.ClassTag.apply[Object](classOf[Object])
      )
    )
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant