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

constructor val disrupts singleton type continuity #4663

Open
scabug opened this issue Jun 2, 2011 · 1 comment
Open

constructor val disrupts singleton type continuity #4663

scabug opened this issue Jun 2, 2011 · 1 comment

Comments

@scabug
Copy link

scabug commented Jun 2, 2011

The following code compiles:

abstract class Power[G <: Global](intp: IMain) {
  val global: G
}
object Power {
  def apply[G <: Global](intp: IMain { val global: G }) =
    new Power[G](intp) { val global: G = intp.global }
}

This variation, differing only by "val intp: Main" instead of "intp: Main", fails:

abstract class Power2[G <: Global](val intp: IMain) {
  val global: G
}
object Power2 {
  def apply[G <: Global](intp: IMain { val global: G }) =
    new Power2[G](intp) { val global: G = intp.global }
}
// error: type mismatch;
//  found   : this.intp.global.type (with underlying type Global)
//  required: G
//     new Power2[G](intp) { val global: G = intp.global }
//                                                ^
// one error found

As evidence, should any be needed, that there is no fundamental reason for it, this compiles:

abstract class Power3[G <: Global](intp: IMain) {
  val global: G
  val intp2 = intp
}
object Power3 {
  def apply[G <: Global](intp: IMain { val global: G }) =
    new Power3[G](intp) { val global: G = intp.global }
}
@scabug
Copy link
Author

scabug commented Jun 2, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4663?orig=1
Reporter: @paulp
See #5712, #6139

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

4 participants