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

Imported names are not respected when defining classes in REPL with -Yrepl-class-based #9880

Open
scabug opened this Issue Aug 6, 2016 · 2 comments

Comments

Projects
None yet
1 participant
@scabug
Copy link

scabug commented Aug 6, 2016

The following snippet illustrates the problem with -Yrepl-class-based:

$ scala -Yrepl-class-based
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.

scala> import java.util.Date
import java.util.Date

scala> class Test(date: Date) // show
class $read extends Serializable {
  def <init>() = {
    super.<init>;
    ()
  };
  class $iw extends Serializable {
    def <init>() = {
      super.<init>;
      ()
    };
    class $iw extends Serializable {
      def <init>() = {
        super.<init>;
        ()
      };
      class Test extends scala.AnyRef {
        <paramaccessor> private[this] val date: Date = _;
        def <init>(date: Date) = {
          super.<init>;
          ()
        }
      }
    };
    val $iw = new $iw.<init>
  };
  val $iw = new $iw.<init>
}
object $read extends scala.AnyRef {
  def <init>() = {
    super.<init>;
    ()
  };
  val INSTANCE = new $read.<init>
}
<console>:11: error: not found: type Date
       class Test(date: Date) // show
                        ^

Without -Yrepl-class-based it works as expected:

$ scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.

scala> import java.util.Date
import java.util.Date

scala> class Test(date: Date) // show
object $read extends scala.AnyRef {
  def <init>() = {
    super.<init>;
    ()
  };
  object $iw extends scala.AnyRef {
    def <init>() = {
      super.<init>;
      ()
    };
    import java.util.Date;
    object $iw extends scala.AnyRef {
      def <init>() = {
        super.<init>;
        ()
      };
      class Test extends scala.AnyRef {
        <paramaccessor> private[this] val date: Date = _;
        def <init>(date: Date) = {
          super.<init>;
          ()
        }
      }
    }
  }
}
defined class Test
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Aug 6, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9880?orig=1
Reporter: @jasonxh
Affected Versions: 2.11.8, 2.12.0-M5

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Aug 7, 2016

@jasonxh said:
After some digging, this seems to be caused by a deeper problem in how ImportHandler keeps track of importedNames. See [SI-9881]. We need to either fix that bug or remove the check on importedNames when computing imports (which may have undesirable consequences).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment