Scala Programming Language
  1. Scala Programming Language
  2. SI-4853

Compiler wants a unit-method to return another (not-unit) type

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.0, Scala 2.9.1
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:
      None

      Description

      ====================================
      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

        Activity

        Hide
        Paul Phillips added a comment -

        Heh, thanks for accommodating my reading disability with your =====================s.

        Show
        Paul Phillips added a comment - Heh, thanks for accommodating my reading disability with your =====================s.
        Hide
        Paul Phillips added a comment -

        As penance for the poor reception I gave you yesterday, I fixed this.

        Show
        Paul Phillips added a comment - As penance for the poor reception I gave you yesterday, I fixed this.
        Hide
        Commit Message Bot added a comment -

        (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 SI-4853, review by odersky.

        Show
        Commit Message Bot added a comment - (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 SI-4853 , review by odersky.
        Hide
        Heiko Seeberger added a comment -

        Excellent!

        Show
        Heiko Seeberger added a comment - Excellent!

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Heiko Seeberger
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development