Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-9880

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

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: Scala 2.11.8, Scala 2.12.0-M5
    • Fix Version/s: Backlog
    • Component/s: Repl / Interpreter
    • Labels:
      None

      Description

      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
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                jasonxh Hao Xia
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: