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

NullPointerException in REPL when a type and an singleton object share name under a package #4991

Closed
scabug opened this issue Sep 12, 2011 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Sep 12, 2011

The following code compiles, but gives NullPointerException when foo.Foo.bar is called in REPL.

package object foo {
  type Foo = Int
}

package foo {
  object Foo {
    def bar = 1
  }
}
  • Case 1
scala> import foo._
import foo._

scala> import Foo._
import Foo._

scala> bar
java.lang.NullPointerException
  • Case 2
scala> foo.Foo.bar
java.lang.NullPointerException
  • Case 3
    Running "println(foo.Foo.bar)" as a single Scala script gives the correct result and does not crash the compiler.
@scabug
Copy link
Author

scabug commented Sep 12, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4991?orig=1
Reporter: ngukho
See #5031

@scabug
Copy link
Author

scabug commented May 3, 2012

@som-snytt said:
Same example {foo => t4991}. One source file.

Under separate compilation of a client using 2.10, scalac emits the same class file error; but compiling together works.

# footnote, 2.9.1 is unhappy compiling pkg obj after 2.10 without cleaning
$ scalac t4991.scala
??? base trait ScalaObject not found in basetypes of object t4991

# 2.10
$ spala
Welcome to Scala version 2.10.0-20120501-234146-b27abca41a (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.

scala> t4991.Foo.bar
error: error while loading Foo, class file '.\t4991\Foo.class' contains wrong class Int

scala> import t4991._
import t4991._

scala> import Foo._
<console>:10: error: erroneous or inaccessible type
       import Foo._
              ^

@scabug
Copy link
Author

scabug commented May 5, 2012

@paulp said:
We need a determination on what's supposed to happen when there is a type alias with a name which would be an object's companion class if it had one. Right now there are a bunch of ways for it to fail, because none of the code which hops between related classes was written to take this into account. It is made yet buggier by the fact that the type alias and object have different owners (the package object class and the package class.)

@scabug
Copy link
Author

scabug commented May 8, 2012

@adriaanm said (edited on May 8, 2012 3:20:57 PM UTC):
Martin: only classes can be companions, type alias should not be considered
top-level type aliased (in package objects) conflict with the top-level class that's created speculatively before parsing a class file

synonymous class and type alias in the same scope is not allowed -- can we delay creating the class symbol without knowing we need to?

object and type alias should be allowed to co-exist (however, class and type alias is not allowed)

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

Duplicate was fixed.

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

3 participants