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

"polymorphic expression cannot be instantiated to expected type": foo: List[Int] inferred, foo: ListInt not. #6846

Closed
scabug opened this issue Dec 19, 2012 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Dec 19, 2012

ticket/6745-3 ~/code/scala scalac210 sandbox/test.scala
sandbox/test.scala:7: error: polymorphic expression cannot be instantiated to expected type;
 found   : [M[_], A]Test.Arb[M[A]]
 required: Test.Arb[Test.ListInt]
  foo: Arb[ListInt]
  ^
one error found
ticket/6745-3 ~/code/scala scalac29 sandbox/test.scala
ticket/6745-3 ~/code/scala cat !$
cat sandbox/test.scala
object Test {
  class Arb[_]
  implicit def foo[M[_], A]: Arb[M[A]] = null
  foo: Arb[List[Int]]

  type ListInt = List[Int]
  foo: Arb[ListInt]
}
@scabug
Copy link
Author

scabug commented Dec 19, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6846?orig=1
Reporter: @retronym
Affected Versions: 2.10.0-RC5

@scabug
Copy link
Author

scabug commented Dec 19, 2012

@paulp said:
Regressed in r25322 aka 658ba1b4e6.

@scabug
Copy link
Author

scabug commented Dec 19, 2012

@paulp said:
To make up for this, I threw in this one:

object Test2 {
  import scala.collection.immutable.List

  class Carb[+_]
  implicit def bar[M[_], A]: Carb[M[A]] = null

  type ListInt = List[Int]

  val x: List[Int] = List(1)
  val y: ListInt = List(1)

  type ListSingletonX = x.type
  type ListSingletonY = y.type

  bar: Carb[List[Int]]
  bar: Carb[ListInt]
  bar: Carb[ListSingletonX]
  bar: Carb[ListSingletonY]
}

Compiles with my imminent pull request, in 2.9 did this:

scalac29 -d /tmp test/files/pos/t6846.scala 
test/files/pos/t6846.scala:25: error: polymorphic expression cannot be instantiated to expected type;
 found   : [M[_], A]Test2.Carb[M[A]]
 required: Test2.Carb[Test2.ListSingletonX]
  bar: Carb[ListSingletonX]
  ^
test/files/pos/t6846.scala:26: error: polymorphic expression cannot be instantiated to expected type;
 found   : [M[_], A]Test2.Carb[M[A]]
 required: Test2.Carb[Test2.ListSingletonY]
  bar: Carb[ListSingletonY]
  ^
two errors found

@scabug
Copy link
Author

scabug commented Dec 19, 2012

@paulp said:
Oh, but I see now that type constructor inference is useless when combined variance - it appears to always choose Any/Nothing for the type argument if it can. Oh, in that case the invariant version is actually failing in the correct way. The 2.9 version also fails, but for the wrong reason.

test/files/pos/t6846.scala:25: error: type mismatch;
 found   : Test2.Carb[List[Int]]
 required: Test2.Carb[Test2.ListSingletonX]
Note: List[Int] >: Test2.ListSingletonX, but class Carb is invariant in type _.
You may wish to define _ as -_ instead. (SLS 4.5)
  bar: Carb[ListSingletonX]
  ^
test/files/pos/t6846.scala:26: error: type mismatch;
 found   : Test2.Carb[List[Int]]
 required: Test2.Carb[Test2.ListSingletonY]
Note: List[Int] >: Test2.ListSingletonY, but class Carb is invariant in type _.
You may wish to define _ as -_ instead. (SLS 4.5)
  bar: Carb[ListSingletonY]
  ^
two errors found

@scabug
Copy link
Author

scabug commented Jan 28, 2013

@adriaanm said:
scala/scala#1869

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

2 participants