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

Regression on importing multiple wildcard in same line while booting Scala REPL #10102

Closed
scabug opened this issue Dec 11, 2016 · 12 comments
Closed

Comments

@scabug
Copy link

scabug commented Dec 11, 2016

I found sbt's initialCommands doesn't work for Scala 2.12. Affected versions are 2.12.0, 2.12.1.

The initialCommands is a feature by sbt but the same one works with Scala 2.11 and 2.10.
I'm afraid it is due to some issue on Scala 2.12. This is a blocker issue for us when upgrading to 2.12. I hope the issue will be fixed in the next patch release.

Procedure to reproduce the situation:

  • Prepare skinny blank app
# macOS
brew install skinny
skinny new skinny-blank-app

# others 
wget https://github.com/skinny-framework/skinny-framework/releases/download/2.3.1/skinny-blank-app-with-deps.zip
unzip skinny-blank-app-with-deps.zip
cd ./skinny-blank-app
  • Switch to Scala 2.12.1

Manually edit build.sbt.

  • invoke sbt console

In the project, sbt invokes the Scala REPL with the following initialCommands:

initialCommands := """
import skinny._
import _root_.controller._, model._
import org.joda.time._
import scalikejdbc._, config._
DBSettings.initialize()
""",

skinny console just does sbt dev/console internally. The dev is an sbt sub project.

./skinny console
  • outputs

It fails to run initialCommands and the REPL aborts after that.

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

scala>

scala> 2016-12-11 10:35:02.257 DEBUG   --- [     run-main-0] scalikejdbc.ConnectionPool$              : Registered connection pool : ConnectionPool(url:jdbc:h2:file:./db/development;MODE=PostgreSQL;AUTO_SERVER=TRUE, user:sa) using factory : <default>
import skinny._
import _root_.controller._
import model._
import org.joda.time._
import scalikejdbc._
import config._
Interpreter encountered errors during initialization!

[error] (Thread-38) java.lang.InterruptedException

java.lang.InterruptedException
	at java.util.concurrent.SynchronousQueue.put(SynchronousQueue.java:879)
	at scala.tools.nsc.interpreter.SplashLoop.run(InteractiveReader.scala:77)
	at java.lang.Thread.run(Thread.java:745)
[success] Total time: 36 s, completed Dec 11, 2016 10:35:10 AM
@scabug
Copy link
Author

scabug commented Dec 11, 2016

Imported From: https://issues.scala-lang.org/browse/SI-10102?orig=1
Reporter: Kazuhiro Sera (seratch)
Affected Versions: 2.12.0, 2.12.1
See #9881

@scabug
Copy link
Author

scabug commented Dec 15, 2016

@SethTisue said:
Are you able to reproduce the issue with something small and self-contained?

In order for this to even be actionable at our end, we'd need a much narrower description of exactly where you think the bug lies. Right now it really isn't clear at all whether the issue is in your sbt, or in Scala, or in your code, or in one of the libraries you're using, or what.

@scabug
Copy link
Author

scabug commented Dec 15, 2016

@SethTisue said:
Perhaps related to #9824 ?

@scabug
Copy link
Author

scabug commented Dec 16, 2016

@som-snytt said:
I think I verified this at the home office. I'll take a look.

@scabug
Copy link
Author

scabug commented Dec 17, 2016

Kazuhiro Sera (seratch) said:
I found the following initialComamnds instead works. The root case looks a regression on multiple wildcard imports in same line.

  initialCommands := """
import _root_.skinny._
import _root_.controller._
import _root_.model._
import _root_.org.joda.time._
import _root_.scalikejdbc._
import _root_.scalikejdbc.config._
DBSettings.initialize()
""",

@scabug
Copy link
Author

scabug commented Dec 17, 2016

@som-snytt said:
Maybe I didn't do it right. The shell script didn't work for me.

apm@mara:~/clones/skinny-framework$ git diff
diff --git a/build.sbt b/build.sbt
index a0528ee..ffb6f49 100644
--- a/build.sbt
+++ b/build.sbt
@@ -28,7 +28,7 @@ lazy val baseSettings = Seq(
   ),
   publishTo := _publishTo(version.value),
   sbtPlugin := false,
-  scalaVersion := "2.12.0",
+  scalaVersion := "2.12.1",
   ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) },
   scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature"),
   publishMavenStyle := true,
diff --git a/skinny-blank-app/build.sbt b/skinny-blank-app/build.sbt
index 35dd6e9..3174b23 100644
--- a/skinny-blank-app/build.sbt
+++ b/skinny-blank-app/build.sbt
@@ -14,7 +14,7 @@ val appName = "skinny-blank-app"
 val appVersion = "0.1.0-SNAPSHOT"
 
 val skinnyVersion = "2.3.1"
-val theScalaVersion = "2.11.8" // 2.12.0 is available if you don't mind if `skinn
+val theScalaVersion = "2.12.1" // "2.11.8" // 2.12.0 is available if you don't mi
 val jettyVersion = "9.3.14.v20161028"
 
 lazy val baseSettings = servletSettings ++ Seq(
apm@mara:~/clones/skinny-framework$ sbt example/console
[info] Loading project definition from /home/apm/clones/skinny-framework/project
[info] Resolving key references (13264 settings) ...
[info] Set current project to skinny-framework (in build file:/home/apm/clones/skinny-framework/)
[info] Compiling Templates in Template Directory: /home/apm/clones/skinny-framework/./src/main/webapp/WEB-INF
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[info] Starting scala interpreter...
[info] 
Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.

scala> import _root_.controller._
import model._
import org.joda.time._
import scalikejdbc._
import SQLInterpolation._
import config._
session: scalikejdbc.AutoSession.type = AutoSession(scalikejdbc.SettingsProvider@6518de26)


scala> model.
AdminUser   CompanyId        PlainPassword     Skill                 
Comment     HashedPassword   Programmer        SnakeCaseKeyExample   
Company     HourlyStat       ProgrammerSkill                         

scala> model.

@scabug
Copy link
Author

scabug commented Dec 17, 2016

Kazuhiro Sera (seratch) said:
@apm The blank project has the issue. Try the following procedure:

cd skinny-blank-app/
# edit build.sbt
sbt dev/console

@scabug
Copy link
Author

scabug commented Dec 17, 2016

Kazuhiro Sera (seratch) said:
But I'm going to apply a workaround for this issue on master branch.

skinny-framework/skinny-framework#341

Try the package file which was already released after I will merge the PR.

wget https://github.com/skinny-framework/skinny-framework/releases/download/2.3.1/skinny-blank-app.zip
unzip skinny-blank-app.zip
cd skinny-blank-app
# edit build.sbt
cd skinny-blank-app/
sbt dev/console

@scabug
Copy link
Author

scabug commented Dec 17, 2016

@som-snytt said:
Thanks, I got it now.

@scabug
Copy link
Author

scabug commented Jan 18, 2017

Thomas Dufour (thomas_d) said:
Hi, I just happened to google this issue, and from the comments I'm not sure if a better repro is still needed.

Just in case, though, you can start sbt without a project and type the following commands to trigger the issue

set scalaVersion := "2.12.1"
set initialCommands in console := "import scala.concurrent._, duration._"
console

Results in

scala> import scala.concurrent._
import duration._
Interpreter encountered errors during initialization!

[error] (Thread-3) java.lang.InterruptedException

java.lang.InterruptedException
        at java.util.concurrent.SynchronousQueue.put(SynchronousQueue.java:879)
        at scala.tools.nsc.interpreter.SplashLoop.run(InteractiveReader.scala:77)
        at java.lang.Thread.run(Thread.java:745)
[success] Total time: 5 s, completed 18 janv. 2017 15:47:22
>

HTH

@scabug
Copy link
Author

scabug commented Jan 19, 2017

@som-snytt said:
sbt runs the initialCommands early for legacy reasons; the import leaves the reporter with an error due to a separate bug.

Normal scala -i loads init code only after compiler initialization is complete.

Here is a view of the error, which occurs when text-based REPL is trying to figure out what is imported by duration._ (in order to enter it into its scope mechanism):

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

scala> :pa -raw
// Entering paste mode (ctrl-D to finish)

package a { package b { class C }}

// Exiting paste mode, now interpreting.


scala> import a._
import a._

scala> (new sys.SystemProperties) += "scala.repl.trace" -> "true"
res0: scala.sys.SystemProperties =
Map(env.emacs -> "", java.runtime.name -> Java(TM) SE Runtime Environment, sun.boot.library.path -> /home/apm/jdk8/jdk1.8.0_111/jre/lib/amd64, java.vm.version -> 25.111-b14, scala.color -> "", java.vm.vendor -> Oracle Corporation, java.vendor.url -> http://java.oracle.com/, path.separator -> :, java.vm.name -> Java HotSpot(TM) 64-Bit Server VM, file.encoding.pkg -> sun.io, user.country -> US, sun.java.launcher -> SUN_STANDARD, sun.os.patch.level -> unknown, java.vm.specification.name -> Java Virtual Machine Specification, user.dir -> /home/apm/projects/scala, java.runtime.version -> 1.8.0_111-b14, java.awt.graphicsenv -> sun.awt.X11GraphicsEnvironment, java.endorsed.dirs -> /home/apm/jdk8/jdk1.8.0_111/jre/lib/endorsed, os.arch...
scala> import b._
parse("import b._") Success(List(import b._))
  0: Import
  7: Ident

parse("

object $read {
  ;

object $iw {
// $line3.$read definedNames List(), curImps Set()
object $iw {
import a._
object $iw {
object $iw {

       import b._


}
[snip]
              val $ires8 = b
            }
          }
        }
      }
    }
  }
}
[silent] <console>:20: error: package a.b is not a value
       b
       ^

The fix is to ignore the error when running under sbt.

$ sbt
[info] Loading project definition from /home/apm/tmp/dummy/project
[info] Set current project to dummy (in build file:/home/apm/tmp/dummy/)
> ++ /home/apm/projects/scala/build/pack
[info] Setting Scala home to /home/apm/projects/scala/build/pack with actual version 2.12.2-20170110-140852-827d69d
[info] 	and using 2.12.2-20170110-140852-827d69d for resolving dependencies.
[info] Reapplying settings...
[info] Set current project to dummy (in build file:/home/apm/tmp/dummy/)
> console
[info] Starting scala interpreter...
[info] 
Welcome to Scala 2.12.2-20170110-140852-827d69d (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.

scala> 42
res0: Int = 42

scala> 
[success] Total time: 8 s, completed Jan 19, 2017 1:55:42 PM
> set initialCommands in console := "import scala.concurrent._, duration._"
[info] Defining *:console::initialCommands
[info] The new value will be used by compile:console, compile:consoleQuick and 1 others.
[info] 	Run `last` for details.
[info] Reapplying settings...
[info] Set current project to dummy (in build file:/home/apm/tmp/dummy/)
> console
[info] Starting scala interpreter...
[info] 
Welcome to Scala 2.12.2-20170110-140852-827d69d (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.

scala> import scala.concurrent._
import duration._


scala> 42
res0: Int = 42

scala> Duration
res1: scala.concurrent.duration.Duration.type = scala.concurrent.duration.Duration$@2338e345

scala> 

@scabug
Copy link
Author

scabug commented Jan 19, 2017

@som-snytt said (edited on Jan 23, 2017 7:16:39 AM UTC):
Linked to the issue that causes the error.

scala/scala#5655

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

3 participants