You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
====================================
This is a bug and related to 2.9.0.1
(Well, under 2.9.1.RC1 and 2.10 nightly it behaves the same)
OK, Animal.main (see below) is clearly a Unit-method. At least clear for me. But not for the compiler:
issue.scala:3: error: polymorphic expression cannot be instantiated to expected type;
found : [B >: Awake <: Awake]Animal[Asleep]
required: Unit
new Animal[Awake].goToSleep
^
object Animal {
def main(args: Array[String]): Unit = {
new Animal[Awake].goToSleep
}
}
class Animal[A <: AwakeOrAsleep] {
def goToSleep[B >: A <: Awake]: Animal[Asleep] = new Animal[Asleep]
def wakeUp[B >: A <: Asleep]: Animal[Awake] = new Animal[Awake]
}
Commit Message Bot (anonymous) said:
(extempore in r25407) Expression type argument instantiation should not fail in a context
expecting Unit if there is any valid instantiation, because value discarding
should kick in and offer a literal (). Closes #4853, review by odersky.
====================================
This is a bug and related to 2.9.0.1
(Well, under 2.9.1.RC1 and 2.10 nightly it behaves the same)
OK, Animal.main (see below) is clearly a Unit-method. At least clear for me. But not for the compiler:
issue.scala:3: error: polymorphic expression cannot be instantiated to expected type;
found : [B >: Awake <: Awake]Animal[Asleep]
required: Unit
new Animal[Awake].goToSleep
^
object Animal {
def main(args: Array[String]): Unit = {
new Animal[Awake].goToSleep
}
}
class Animal[A <: AwakeOrAsleep] {
def goToSleep[B >: A <: Awake]: Animal[Asleep] = new Animal[Asleep]
def wakeUp[B >: A <: Asleep]: Animal[Awake] = new Animal[Awake]
}
sealed trait AwakeOrAsleep
trait Awake extends AwakeOrAsleep
trait Asleep extends AwakeOrAsleep
The text was updated successfully, but these errors were encountered: