Skip to content
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

2.13 regression: "polymorphic expression cannot be instantiated to expected type" #11537

Open
lrytz opened this issue May 16, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@lrytz
Copy link
Member

commented May 16, 2019

This compiles on 2.12, but not on 2.13:

object t {
  def foo(a: String, b: collection.Seq[String]) = 0
  def foo(a: Int, b: collection.Seq[String]) = 1
}

t.foo(1, collection.Set("").toArray)

2.13 error:

scala> t.foo(1, collection.Set("").toArray)
                                   ^
       error: polymorphic expression cannot be instantiated to expected type;
        found   : [B >: String]Array[B]
        required: scala.collection.Seq[String]

Pulling collection.Set("").toArray into a local variable fixes it.

However, if foo is not overloaded, the example fails on both 2.12 and 2.13. Here's the error in 2.12:

scala> object t {
     |   def foo(a: Int, b: collection.Seq[String]) = 1
     | }

scala> t.foo(1, collection.Set("").toArray)
<console>:13: error: polymorphic expression cannot be instantiated to expected type;
 found   : [B >: String]Array[B]
 required: Seq[String]
       t.foo(1, collection.Set("").toArray)
                                   ^
@adriaanm

This comment has been minimized.

Copy link
Member

commented May 24, 2019

This is a consequence of the second argument now being typed with an expected type, since the types collapse. Once you eliminate that difference, it fails on 2.12 as well, as shown in the non-overloaded case, or even more distilled:

Welcome to Scala 2.12.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_181).
Type in expressions for evaluation. Or try :help.

scala> collection.Set("").toArray: collection.Seq[String]
<console>:12: error: polymorphic expression cannot be instantiated to expected type;
 found   : [B >: String]Array[B]
 required: Seq[String]
       collection.Set("").toArray: collection.Seq[String]

Welcome to Scala 2.13.0-RC2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_181).
Type in expressions for evaluation. Or try :help.

scala> collection.Set("").toArray: collection.Seq[String]
                          ^
       error: polymorphic expression cannot be instantiated to expected type;
        found   : [B >: String]Array[B]
        required: scala.collection.Seq[String]
@adriaanm

This comment has been minimized.

Copy link
Member

commented May 24, 2019

I think this is actually a duplicate of #2394, dating from the last collection rewrite :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.