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 crash when using package private modifiers and abstract types. #4559

Closed
scabug opened this issue May 9, 2011 · 7 comments
Closed
Milestone

Comments

@scabug
Copy link

scabug commented May 9, 2011

The following code compiles under Scala-2.8.1.final but causes the compiler to crash under Scala-2.9.0.RC4.

package mypkg {

  trait M { type C <: M }
  trait F extends M { type C = F }

  // requires private[mypkg] to reproduce
  private[mypkg] abstract class Private[E <: M] {
    type Sub <: Private[E#C]
    final val sub: Sub = null.asInstanceOf[Sub]

    def foo: E
  }

  trait Public[E <: M] extends Private[E] {
    type Sub = Public[E#C]
  }
}

import mypkg._

object Test {
  val seq = null.asInstanceOf[Public[F]]
  seq.sub.foo
}

The only workaround I can think of is to strip all the package private modifiers. Of course that would expose internal implementation as public API.

=== Versions ===

  • Scala: 2.9.0.RC4
  • Java: 1.6.0_u24
  • Operating system: GNU/Linux 2.6.38
@scabug
Copy link
Author

scabug commented May 9, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4559?orig=1
Reporter: @lexn82
See #4312

@scabug
Copy link
Author

scabug commented May 9, 2011

@paulp said:
I think the bug is that it ever compiled. If you make Private just plain private, it gives the message I would expect.

./a.scala:15: error: private class Private escapes its defining scope as part of type mypkg.Private[E]
   trait Public[E <: M] extends Private[E] {
                                ^
one error found

That is just as true a statement if Private is private[mypkg] as if it's private.

I've never heard of public classes with private parents. Is this supported in the spec?

@scabug
Copy link
Author

scabug commented May 9, 2011

@lexn82 said:
The class should probably be public. However the compiler should give a proper warning instead of crashing with an assertion error.

@scabug
Copy link
Author

scabug commented May 10, 2011

@dragos said:
Adriaan, you added this assert in r22508. Can you please have a look?

@scabug
Copy link
Author

scabug commented May 10, 2011

@dragos said:
Sorry, I noticed now that you only added a proper message.. however, you may know more about erasure.

@scabug
Copy link
Author

scabug commented Jun 2, 2011

@adriaanm said (edited on Jun 2, 2011 12:44:04 AM UTC):
I have a fix for the crash and an improvement of a situation that was clearly wrong.
However, I can't find where the specs defines when it's ok for a symbol to escape its defining scope, and how we avoid such problematic types.

Martin, re-assigning to you for clarification. Feel free to bounce back for the actual implementation.

@scabug scabug added the crash label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
@som-snytt
Copy link

Compiles without crashing in 2.13. Also compiles in dotc after tweaking. No escaping defining scope message.

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

No branches or pull requests

5 participants