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

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

Closed
scabug opened this issue Jul 28, 2011 · 5 comments
Closed

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

scabug opened this issue Jul 28, 2011 · 5 comments
Assignees

Comments

@scabug
Copy link

@scabug scabug commented Jul 28, 2011

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

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 28, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4853?orig=1
Reporter: @hseeberger
Affected Versions: 2.9.0, 2.9.1

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 28, 2011

@paulp said:
Heh, thanks for accommodating my reading disability with your =====================s.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 28, 2011

@paulp said:
As penance for the poor reception I gave you yesterday, I fixed this.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 28, 2011

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.

@scabug scabug closed this Jul 28, 2011
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 29, 2011

@hseeberger said:
Excellent!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.