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

The autoRefine macro crashes in the 2.10 REPL #295

Closed
fthomas opened this issue Jun 13, 2017 · 3 comments
Closed

The autoRefine macro crashes in the 2.10 REPL #295

fthomas opened this issue Jun 13, 2017 · 3 comments
Labels

Comments

@fthomas
Copy link
Owner

fthomas commented Jun 13, 2017

Reported by @vlovgr here: https://gitter.im/fthomas/refined?at=593afdcb7503e2b70629858d

For example

scala> 1: PosInt
<console>:47: error: exception during macro expansion: 
java.lang.ClassCastException: eu.timepit.refined.api.Validate$$anon$2 cannot be cast to eu.timepit.refined.api.Validate
    at eu.timepit.refined.macros.RefineMacro.impl(RefineMacro.scala:23)
    at eu.timepit.refined.macros.RefineMacro$.impl(RefineMacro.scala:9)

can be reproduced in the 2.10 REPL:

> ++2.10.6
> console
@fthomas fthomas added the bug label Jun 13, 2017
@fthomas
Copy link
Owner Author

fthomas commented Dec 18, 2017

I don't know why, but I can no longer reproduce this issue:

$ sbt
...
sbt:refined> ++2.10.6
[info] Setting Scala version to 2.10.6 on 17 projects.
...
sbt:refined> clean
sbt:refined> console
...
[info] Compiling 34 Scala sources to refined/modules/core/jvm/target/scala-2.10/classes ...
[info] Done compiling.
[info] Starting scala interpreter...
...
Welcome to Scala version 2.10.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_151).
Type in expressions to have them evaluated.
Type :help for more information.

scala> 1: PosInt
res0: eu.timepit.refined.types.all.PosInt = 1

@fthomas fthomas closed this as completed Dec 18, 2017
@vil1
Copy link

vil1 commented Mar 14, 2018

I managed to reproduce this issue on a project where the https://github.com/tek/splain plugin was activated.

scalaVersion in ThisBuild := "2.12.4"

libraryDependencies += "eu.timepit" %% "refined" % "0.8.7"

addCompilerPlugin("io.tryp" %% "splain" % "0.2.7" cross CrossVersion.patch)
[info] Starting scala interpreter...
Welcome to Scala 2.12.4 (OpenJDK 64-Bit Server VM, Java 1.8.0_151).
Type in expressions for evaluation. Or try :help.

scala> import eu.timepit.refined._, api._, auto._, char._, generic._, collection._
import eu.timepit.refined._
import api._
import auto._
import char._
import generic._
import collection._

scala> val str: String Refined Forall[UpperCase] = "FOO"
<console>:29: error: exception during macro expansion:
java.lang.ClassCastException: eu.timepit.refined.api.Validate$$anon$1 cannot be cast to eu.timepit.refined.api.Validate
	at eu.timepit.refined.macros.RefineMacro.$anonfun$validateInstance$1(RefineMacro.scala:57)
	at scala.Option.getOrElse(Option.scala:121)
	at eu.timepit.refined.macros.RefineMacro.validateInstance(RefineMacro.scala:57)
	at eu.timepit.refined.macros.RefineMacro.impl(RefineMacro.scala:27)

       val str: String Refined Forall[UpperCase] = "FOO"

The ClassCastException only shows up in the scala REPL, the same code compiles just fine when put in a scala file. Everything is back to normal when I remove splain.

@fthomas
Copy link
Owner Author

fthomas commented Mar 14, 2018

Thanks for the report @vil1. I've no immediate idea what we could do differently in refined to avoid that exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants