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

Shapeless' narrow method crashes the compiler 2.12.x (only in REPL) #10358

Closed
n4to4 opened this issue Jun 6, 2017 · 4 comments
Closed

Shapeless' narrow method crashes the compiler 2.12.x (only in REPL) #10358

n4to4 opened this issue Jun 6, 2017 · 4 comments

Comments

@n4to4
Copy link

n4to4 commented Jun 6, 2017

Scala version: 2.12.2 and 2.12.1

Shapeless' 42.narrow seems to crash the compiler only in REPL.
It seems fine when running in a program with sbt run.

build.sbt:

scalaVersion := "2.12.2"

libraryDependencies ++= Seq("com.chuusai" %% "shapeless" % "2.3.2")

How to reproduce:

$ sbt
sbt> console
[info] Starting scala interpreter...
[info]
Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_60).
Type in expressions for evaluation. Or try :help.

scala> import shapeless.syntax.singleton._
import shapeless.syntax.singleton._

scala> 42.narrow
scala.reflect.internal.Types$TypeError: assignment to non variable
        at scala.tools.nsc.typechecker.Contexts$ThrowingReporter.handleError(Contexts.scala:1402)
        at scala.tools.nsc.typechecker.Contexts$ContextReporter.issue(Contexts.scala:1254)
        at scala.tools.nsc.typechecker.Contexts$Context.issue(Contexts.scala:576)
        at scala.tools.nsc.typechecker.ContextErrors$ErrorUtils$.issueTypeError(ContextErrors.scala:106)
        at scala.tools.nsc.typechecker.ContextErrors$ErrorUtils$.issueNormalTypeError(ContextErrors.scala:99)
        at scala.tools.nsc.typechecker.ContextErrors$TyperContextErrors$TyperErrorGen$.AssignmentError(ContextErrors.scala:323)
        at scala.tools.nsc.typechecker.Typers$Typer.fail$2(Typers.scala:4338)
        at scala.tools.nsc.typechecker.Typers$Typer.typedAssign$1(Typers.scala:4341)
        at scala.tools.nsc.typechecker.Typers$Typer.typedOutsidePatternMode$1(Typers.scala:5491)
        at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5520)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5527)
        at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5563)
        at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5593)
        at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5537)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5541)
        at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5624)
[...]
        at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply(Console.scala:23)
        at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply(Console.scala:23)
        at sbt.Logger$$anon$4.apply(Logger.scala:84)
        at sbt.TrapExit$App.run(TrapExit.scala:248)
        at java.lang.Thread.run(Thread.java:745)

That entry seems to have slain the compiler.  Shall I replay
your session? I can re-run each line except the last one.
@n4to4 n4to4 changed the title Shapeless' narrow method crashes the compiler 2.12.x (only in REPL) Shapeless' narrow method crashes the compiler 2.12.x (only in REPL) Jun 6, 2017
@xuwei-k
Copy link

xuwei-k commented Jun 6, 2017

milessabin/shapeless#674

@som-snytt
Copy link

It's the same result with 23.narrow.

It trips up on a lazy val that is not ordinarily visible.

// currently lazy
//<stable> <accessor> lazy val $result: Int(23) = $line6.$read.$iw.$iw.$iw.$iw.res2;

package narrowly

import shapeless.syntax.singleton._

object Main extends App {
  lazy val x = 23.narrow
}

Mr Fields comments, "Lazy vals do not receive constant types (anymore)."

@lihaoyi
Copy link

lihaoyi commented Jun 17, 2017

Notably, this seems to work in Ammonite

$ amm
Loading...
Welcome to the Ammonite Repl 1.0.0-RC6
(Scala 2.12.2 Java 1.8.0_112)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ import $ivy.`com.chuusai::shapeless:2.3.2`
import $ivy.$
@  import shapeless.syntax.singleton._
import shapeless.syntax.singleton._
@ 42.narrow
res2: 42 = 42

Not sure what we're doing differently; Ammonite compiles these things in pretty simple object wrappers, but I thought the Scala REPL did too

@SethTisue
Copy link
Member

let's consolidate at #10768

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