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

nondeterministic compiler crash ¯\_(ツ)_/¯ #260

Open
tpolecat opened this issue Feb 28, 2017 · 33 comments · Fixed by #262
Open

nondeterministic compiler crash ¯\_(ツ)_/¯ #260

tpolecat opened this issue Feb 28, 2017 · 33 comments · Fixed by #262
Labels

Comments

@tpolecat
Copy link

I saw this on Travis, compiling doobie at commit b2f02078d0162827b93a1d3408c2a9950ce477d4 under ++2.11.8. I restarted the build and it worked fine, so it's nondeterministic. I'm offering this on the chance that you will find it useful, but I don't expect a fix so feel free to close.

[error] /home/travis/build/tpolecat/doobie/modules-cats/refined/target/scala-2.11/src_managed/test/scala/doobie/refined/refinedtypes.scala:82: exception during macro expansion: 
[error] java.lang.AssertionError: assertion failed: import failure: cannot determine unique overloaded method alternative from
[error]  final package eu
[error] final package eu
[error]  that matches package eu:eu.type
[error] 	at scala.Predef$.assert(Predef.scala:186)
[error] 	at scala.reflect.internal.Importers$StandardImporter.disambiguate$1(Importers.scala:181)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:188)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:169)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:166)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:166)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreatedTreeCompleter(Importers.scala:298)
[error] 	at scala.reflect.internal.Importers$StandardImporter$$anonfun$importTree$1.apply$mcV$sp(Importers.scala:417)
[error] 	at scala.reflect.internal.Importers$StandardImporter$$anonfun$tryFixup$1.apply(Importers.scala:49)
[error] 	at scala.reflect.internal.Importers$StandardImporter$$anonfun$tryFixup$1.apply(Importers.scala:49)
[error] 	at scala.collection.immutable.List.foreach(List.scala:381)
[error] 	at scala.reflect.internal.Importers$StandardImporter.tryFixup(Importers.scala:49)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:418)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:383)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:383)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:367)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:370)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:29)
[error] 	at scala.reflect.macros.contexts.Evals$class.eval(Evals.scala:19)
[error] 	at scala.reflect.macros.contexts.Context.eval(Context.scala:6)
[error] 	at eu.timepit.refined.macros.MacroUtils$$anonfun$eval$1.apply(MacroUtils.scala:20)
[error] 	at scala.Option.getOrElse(Option.scala:121)
[error] 	at eu.timepit.refined.macros.MacroUtils$class.tryN(MacroUtils.scala:24)
[error] 	at eu.timepit.refined.macros.RefineMacro.tryN(RefineMacro.scala:9)
[error] 	at eu.timepit.refined.macros.MacroUtils$class.eval(MacroUtils.scala:20)
[error] 	at eu.timepit.refined.macros.RefineMacro.eval(RefineMacro.scala:9)
[error] 	at eu.timepit.refined.macros.RefineMacro.impl(RefineMacro.scala:23)
[error]       val somePositiveInt: Option[PositiveInt] = Some(5)
[error]                                                       ^

And again nearby.

[error] /home/travis/build/tpolecat/doobie/modules/refined/target/scala-2.11/src_managed/test/scala/doobie/refined/refinedtypes.scala:84: exception during macro expansion: 
[error] java.lang.AssertionError: assertion failed: import failure: cannot determine unique overloaded method alternative from
[error]  final package eu
[error] final package eu
[error]  that matches package eu:eu.type
[error] 	at scala.Predef$.assert(Predef.scala:186)
[error] 	at scala.reflect.internal.Importers$StandardImporter.disambiguate$1(Importers.scala:181)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:188)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:169)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:166)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:166)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreatedTreeCompleter(Importers.scala:298)
[error] 	at scala.reflect.internal.Importers$StandardImporter$$anonfun$importTree$1.apply$mcV$sp(Importers.scala:417)
[error] 	at scala.reflect.internal.Importers$StandardImporter$$anonfun$tryFixup$1.apply(Importers.scala:49)
[error] 	at scala.reflect.internal.Importers$StandardImporter$$anonfun$tryFixup$1.apply(Importers.scala:49)
[error] 	at scala.collection.immutable.List.foreach(List.scala:381)
[error] 	at scala.reflect.internal.Importers$StandardImporter.tryFixup(Importers.scala:49)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:418)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:383)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:383)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:367)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415)
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:370)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415)
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:29)
[error] 	at scala.reflect.macros.contexts.Evals$class.eval(Evals.scala:19)
[error] 	at scala.reflect.macros.contexts.Context.eval(Context.scala:6)
[error] 	at eu.timepit.refined.macros.MacroUtils$$anonfun$eval$1.apply(MacroUtils.scala:20)
[error] 	at scala.Option.getOrElse(Option.scala:121)
[error] 	at eu.timepit.refined.macros.MacroUtils$class.tryN(MacroUtils.scala:24)
[error] 	at eu.timepit.refined.macros.RefineMacro.tryN(RefineMacro.scala:9)
[error] 	at eu.timepit.refined.macros.MacroUtils$class.eval(MacroUtils.scala:20)
[error] 	at eu.timepit.refined.macros.RefineMacro.eval(RefineMacro.scala:9)
[error] 	at eu.timepit.refined.macros.RefineMacro.impl(RefineMacro.scala:23)
[error]       val somePositiveInt: Option[PositiveInt] = Some(5)
[error]                                                       ^```
@fthomas
Copy link
Owner

fthomas commented Feb 28, 2017

Oh dear! I haven't seen this one yet. Stack traces I've seen so far are #3 and scalacenter/scalafix#47.

fthomas added a commit that referenced this issue Mar 6, 2017
by calling `duplicate` before untypechecking the tree.

This is an attempt to fix #260
@fthomas
Copy link
Owner

fthomas commented Mar 17, 2017

@tpolecat I've just released refined 0.8.0 which contains a potential fix for these compiler crashes. If you see them again after the upgrade, please reopen this issue.

@tpolecat
Copy link
Author

Will do, still seeing it with 0.7. I'll let you know. Thanks!

@tpolecat
Copy link
Author

tpolecat commented Mar 21, 2017

Sadly this is still happening. Only in 2.11, if that helps. It always compiles ok in 2.10 and 2.12.

(I am unable to re-open.)

fthomas added a commit to fthomas/doobie that referenced this issue Mar 21, 2017
Using refined's macro in doobies tests leads to nondeterministic
compiler crashes (fthomas/refined#260).
Fortunately these macros are not essential for testing doobie-refined,
so I removed its usage from the tests.
@fthomas fthomas reopened this Mar 21, 2017
fthomas added a commit that referenced this issue May 4, 2017
@fthomas
Copy link
Owner

fthomas commented Oct 5, 2017

This isn't fixed, but because of #332 and #334 these crashes will hopefully happen less often since we now try to avoid calling scala.reflect.macros.contexts.Context.eval if possible.

@NeQuissimus
Copy link
Contributor

I have started seeing this as well (refined 0.9.0).

All I have been able to notice is that a slower build slave seems to run into this more often. But that may be purely coincidental.

Sample stack trace [error] java.lang.AssertionError: assertion failed: import failure: cannot determine unique overloaded method alternative from [error] final package eu [error] final package eu [error] that matches package eu:eu.type [error] at scala.reflect.internal.Importers$StandardImporter.disambiguate$1(Importers.scala:183) [error] at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:188) [error] at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210) [error] at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:169) [error] at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210) [error] at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:166) [error] at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210) [error] at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:166) [error] at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210) [error] at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:166) [error] at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210) [error] at scala.reflect.internal.Importers$StandardImporter.recreatedTreeCompleter(Importers.scala:298) [error] at scala.reflect.internal.Importers$StandardImporter.$anonfun$importTree$1(Importers.scala:417) [error] at scala.reflect.internal.Importers$StandardImporter.tryFixup(Importers.scala:49) [error] at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:418) [error] at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:383) [error] at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415) [error] at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:383) [error] at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415) [error] at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:367) [error] at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415) [error] at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:370) [error] at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415) [error] at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:29) [error] at scala.reflect.macros.contexts.Evals.eval(Evals.scala:19) [error] at scala.reflect.macros.contexts.Evals.eval$(Evals.scala:14) [error] at scala.reflect.macros.contexts.Context.eval(Context.scala:6) [error] at eu.timepit.refined.macros.MacroUtils.$anonfun$eval$1(MacroUtils.scala:24) [error] at scala.Option.getOrElse(Option.scala:121) [error] at eu.timepit.refined.macros.MacroUtils.tryN(MacroUtils.scala:28) [error] at eu.timepit.refined.macros.MacroUtils.tryN$(MacroUtils.scala:27) [error] at eu.timepit.refined.macros.RefineMacro.tryN(RefineMacro.scala:11) [error] at eu.timepit.refined.macros.MacroUtils.eval(MacroUtils.scala:24) [error] at eu.timepit.refined.macros.MacroUtils.eval$(MacroUtils.scala:17) [error] at eu.timepit.refined.macros.RefineMacro.eval(RefineMacro.scala:11) [error] at eu.timepit.refined.macros.RefineMacro.$anonfun$validateInstance$1(RefineMacro.scala:57) [error] at scala.Option.getOrElse(Option.scala:121) [error] at eu.timepit.refined.macros.RefineMacro.validateInstance(RefineMacro.scala:57) [error] at eu.timepit.refined.macros.RefineMacro.impl(RefineMacro.scala:27) [error] at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source) [error] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [error] at java.lang.reflect.Method.invoke(Method.java:498) [error] at scala.reflect.macros.runtime.JavaReflectionRuntimes$JavaReflectionResolvers.$anonfun$resolveJavaReflectionRuntime$4(JavaReflectionRuntimes.scala:34) [error] at scala.tools.nsc.typechecker.Macros.macroExpandWithRuntime(Macros.scala:772)

@fthomas
Copy link
Owner

fthomas commented Jul 5, 2018

@NeQuissimus Do you know the predicate for which the macro is called in this case? If it is provided by the library, we can fix this for this particular predicate by adding the appropriate Validate instance to https://github.com/fthomas/refined/blob/master/modules/core/shared/src/main/scala/eu/timepit/refined/macros/RefineMacro.scala#L59.

@NeQuissimus
Copy link
Contributor

@fthomas I had multiple of these, I can look them up tomorrow.

@NeQuissimus
Copy link
Contributor

Alright, so I had the following instances over the last couple of days:

  • "_" and "A" refinement into type ShortString = String Refined (NonEmpty And MaxSize[W.255.T])
  • "0.0.0.0" into type IPAddress = String Refined (IPv4 Or IPv6)
  • "2018-05-21T00:50:00.239Z" into type ISO8601 = String Refined MatchesRegex[ W.`"^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\\\\.[0-9]+)?(Z)?$"`.T]

None of these are built-in, I suppose :(

@fthomas fthomas added the bug label Jul 13, 2018
@fthomas
Copy link
Owner

fthomas commented Jul 13, 2018

@NeQuissimus They are not primitive predicates but composed of primitive predicates that are defined by the library so in principle we could add their Validate instances to the cache of precomputed instances. But this is an ugly band-aid and I'd much prefer an actual solution for this problem. I'll try again to find a more general fix.

@oleg-py
Copy link

oleg-py commented Dec 8, 2018

I just received the same error compiling this exact file:
https://github.com/oleg-py/arcomage-challenge/blob/d47b70cfb5521ad22bab88488c830d69569c0da6/core/src/main/scala/ac/game/GameConditions.scala

It only uses Greater refinement and automatic conversions. Restarting sbt made the problem go away.

@SethTisue
Copy link
Contributor

I'm seeing this in the Scala community build at scala/community-build#1039

@fthomas
Copy link
Owner

fthomas commented Jan 15, 2020

I've just read this comment by @retronym in scala/bug#9218 (comment):

class Predicate[A, B] {
  self => // self type needed to trigger the bug
}

I think we can get rid of the self type in Validate and if we're lucky not trigger this bug anymore. That would be wonderful!

@fthomas
Copy link
Owner

fthomas commented Jan 25, 2020

The self type is now gone in 0.9.12. If anyone observes this compiler crash with 0.9.12 or a newer version, please leave a comment here.

@ferhtaydn
Copy link

The self type is now gone in 0.9.12. If anyone observes this compiler crash with 0.9.12 or a newer version, please leave a comment here.

Hey, just saw it again with 0.9.12 and scalaVersion := "2.12.10"

@jgogstad
Copy link

jgogstad commented Apr 7, 2020

Seeing this on 2.12.11, refined 0.9.12

@jeffmay
Copy link

jeffmay commented May 1, 2020

I'm seeing the following error on Jenkins with Scala 2.13.1 and Refined 0.9.14:

[2020-05-01T17:08:29.858Z] [error] /home/jenkins/workspace/ization_Kerna_build-kerna_PR-546/mongo/src/main/scala/com/rallyhealth/mongo/models/InferenceType.scala:62:58: exception during macro expansion: 

[2020-05-01T17:08:29.858Z] [error] java.lang.AssertionError: assertion failed: import failure: cannot determine unique overloaded method alternative from

[2020-05-01T17:08:29.858Z] [error]  final package eu

[2020-05-01T17:08:29.858Z] [error] final package eu

[2020-05-01T17:08:29.858Z] [error]  that matches package eu:eu.type

[2020-05-01T17:08:29.858Z] [error] 	at scala.reflect.internal.SymbolTable.throwAssertionError(SymbolTable.scala:170)

[2020-05-01T17:08:29.858Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.disambiguate$1(Importers.scala:195)

[2020-05-01T17:08:29.858Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:200)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:181)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreatedTreeCompleter(Importers.scala:310)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.$anonfun$importTree$1(Importers.scala:429)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.tryFixup(Importers.scala:61)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:430)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:395)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:395)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:379)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:382)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:41)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.macros.contexts.Evals.eval(Evals.scala:31)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.macros.contexts.Evals.eval$(Evals.scala:26)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.macros.contexts.Context.eval(Context.scala:18)

[2020-05-01T17:08:29.859Z] [error] 	at eu.timepit.refined.macros.MacroUtils.$anonfun$eval$1(MacroUtils.scala:22)

[2020-05-01T17:08:29.859Z] [error] 	at scala.Option.getOrElse(Option.scala:201)

[2020-05-01T17:08:29.859Z] [error] 	at eu.timepit.refined.macros.MacroUtils.tryN(MacroUtils.scala:26)

[2020-05-01T17:08:29.859Z] [error] 	at eu.timepit.refined.macros.MacroUtils.tryN$(MacroUtils.scala:25)

[2020-05-01T17:08:29.859Z] [error] 	at eu.timepit.refined.macros.RefineMacro.tryN(RefineMacro.scala:10)

[2020-05-01T17:08:29.859Z] [error] 	at eu.timepit.refined.macros.MacroUtils.eval(MacroUtils.scala:22)

[2020-05-01T17:08:29.859Z] [error] 	at eu.timepit.refined.macros.MacroUtils.eval$(MacroUtils.scala:15)

[2020-05-01T17:08:29.859Z] [error] 	at eu.timepit.refined.macros.RefineMacro.eval(RefineMacro.scala:10)

[2020-05-01T17:08:29.859Z] [error] 	at eu.timepit.refined.macros.RefineMacro.$anonfun$validateInstance$2(RefineMacro.scala:55)

[2020-05-01T17:08:29.859Z] [error] 	at scala.Option.getOrElse(Option.scala:201)

[2020-05-01T17:08:29.859Z] [error] 	at eu.timepit.refined.macros.RefineMacro.validateInstance(RefineMacro.scala:55)

[2020-05-01T17:08:29.859Z] [error] 	at eu.timepit.refined.macros.RefineMacro.impl(RefineMacro.scala:25)

[2020-05-01T17:08:29.859Z] [error] 	at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)

[2020-05-01T17:08:29.859Z] [error] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

[2020-05-01T17:08:29.859Z] [error] 	at java.lang.reflect.Method.invoke(Method.java:498)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.macros.runtime.JavaReflectionRuntimes$JavaReflectionResolvers.$anonfun$resolveJavaReflectionRuntime$5(JavaReflectionRuntimes.scala:45)

[2020-05-01T17:08:29.859Z] [error] 	at scala.tools.nsc.typechecker.Macros.macroExpandWithRuntime(Macros.scala:758)

[2020-05-01T17:08:29.859Z] [error]       s"Cannot find InferenceType with ${LogView.withKey("id", id)}, valid options are $validValuesString (${pos.show})"

[2020-05-01T17:08:29.859Z] [error]                                                          ^

[2020-05-01T17:08:29.859Z] [error] /home/jenkins/workspace/ization_Kerna_build-kerna_PR-546/mongo/src/main/scala/com/rallyhealth/mongo/models/InferenceType.scala:71:20: exception during macro expansion: 

[2020-05-01T17:08:29.859Z] [error] java.lang.AssertionError: assertion failed: import failure: cannot determine unique overloaded method alternative from

[2020-05-01T17:08:29.859Z] [error]  final package eu

[2020-05-01T17:08:29.859Z] [error] final package eu

[2020-05-01T17:08:29.859Z] [error]  that matches package eu:eu.type

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.SymbolTable.throwAssertionError(SymbolTable.scala:170)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.disambiguate$1(Importers.scala:195)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:200)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:181)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreatedTreeCompleter(Importers.scala:310)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.$anonfun$importTree$1(Importers.scala:429)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.tryFixup(Importers.scala:61)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:430)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:395)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:395)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:379)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:382)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:41)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.macros.contexts.Evals.eval(Evals.scala:31)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.macros.contexts.Evals.eval$(Evals.scala:26)

[2020-05-01T17:08:29.859Z] [error] 	at scala.reflect.macros.contexts.Context.eval(Context.scala:18)

[2020-05-01T17:08:29.860Z] [error] 	at eu.timepit.refined.macros.MacroUtils.$anonfun$eval$1(MacroUtils.scala:22)

[2020-05-01T17:08:29.860Z] [error] 	at scala.Option.getOrElse(Option.scala:201)

[2020-05-01T17:08:29.860Z] [error] 	at eu.timepit.refined.macros.MacroUtils.tryN(MacroUtils.scala:26)

[2020-05-01T17:08:29.860Z] [error] 	at eu.timepit.refined.macros.MacroUtils.tryN$(MacroUtils.scala:25)

[2020-05-01T17:08:29.860Z] [error] 	at eu.timepit.refined.macros.RefineMacro.tryN(RefineMacro.scala:10)

[2020-05-01T17:08:29.860Z] [error] 	at eu.timepit.refined.macros.MacroUtils.eval(MacroUtils.scala:22)

[2020-05-01T17:08:29.860Z] [error] 	at eu.timepit.refined.macros.MacroUtils.eval$(MacroUtils.scala:15)

[2020-05-01T17:08:29.860Z] [error] 	at eu.timepit.refined.macros.RefineMacro.eval(RefineMacro.scala:10)

[2020-05-01T17:08:29.860Z] [error] 	at eu.timepit.refined.macros.RefineMacro.$anonfun$validateInstance$2(RefineMacro.scala:55)

[2020-05-01T17:08:29.860Z] [error] 	at scala.Option.getOrElse(Option.scala:201)

[2020-05-01T17:08:29.860Z] [error] 	at eu.timepit.refined.macros.RefineMacro.validateInstance(RefineMacro.scala:55)

[2020-05-01T17:08:29.860Z] [error] 	at eu.timepit.refined.macros.RefineMacro.impl(RefineMacro.scala:25)

[2020-05-01T17:08:29.860Z] [error] 	at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)

[2020-05-01T17:08:29.860Z] [error] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

[2020-05-01T17:08:29.860Z] [error] 	at java.lang.reflect.Method.invoke(Method.java:498)

[2020-05-01T17:08:29.860Z] [error] 	at scala.reflect.macros.runtime.JavaReflectionRuntimes$JavaReflectionResolvers.$anonfun$resolveJavaReflectionRuntime$5(JavaReflectionRuntimes.scala:45)

[2020-05-01T17:08:29.860Z] [error] 	at scala.tools.nsc.typechecker.Macros.macroExpandWithRuntime(Macros.scala:758)

[2020-05-01T17:08:29.860Z] [error]           .withKey("name", lowercaseName)}, valid options are $validValuesString (${pos.show})"

[2020-05-01T17:08:29.860Z] [error]                    ^

[2020-05-01T17:08:29.860Z] [info] String("probability_to_engage") <: com.rallyhealth.mongo.models.InferenceType.Name?

[2020-05-01T17:08:29.860Z] [info] false

[2020-05-01T17:08:29.860Z] [error] /home/jenkins/workspace/ization_Kerna_build-kerna_PR-546/mongo/src/main/scala/com/rallyhealth/mongo/models/InferenceType.scala:82:7: no arguments allowed for nullary constructor Object: ()Object

[2020-05-01T17:08:29.860Z] [error]       1,

[2020-05-01T17:08:29.860Z] [error]       ^

[2020-05-01T17:08:29.860Z] [info] String("unnecessary_er_visit") <: com.rallyhealth.mongo.models.InferenceType.Name?

[2020-05-01T17:08:29.860Z] [info] false

[2020-05-01T17:08:29.860Z] [error] /home/jenkins/workspace/ization_Kerna_build-kerna_PR-546/mongo/src/main/scala/com/rallyhealth/mongo/models/InferenceType.scala:91:7: no arguments allowed for nullary constructor Object: ()Object

[2020-05-01T17:08:29.860Z] [error]       2,

[2020-05-01T17:08:29.860Z] [error]       ^

[2020-05-01T17:08:29.860Z] [info] String("has_cost_estimate") <: com.rallyhealth.mongo.models.InferenceType.Name?

[2020-05-01T17:08:29.860Z] [info] false

[2020-05-01T17:08:29.860Z] [error] /home/jenkins/workspace/ization_Kerna_build-kerna_PR-546/mongo/src/main/scala/com/rallyhealth/mongo/models/InferenceType.scala:100:7: no arguments allowed for nullary constructor Object: ()Object

[2020-05-01T17:08:29.860Z] [error]       3,

[2020-05-01T17:08:29.860Z] [error]       ^

[2020-05-01T17:08:29.860Z] [info] String("search_urgent_care") <: com.rallyhealth.mongo.models.InferenceType.Name?

[2020-05-01T17:08:29.860Z] [info] false

[2020-05-01T17:08:29.860Z] [error] /home/jenkins/workspace/ization_Kerna_build-kerna_PR-546/mongo/src/main/scala/com/rallyhealth/mongo/models/InferenceType.scala:110:7: no arguments allowed for nullary constructor Object: ()Object

[2020-05-01T17:08:29.860Z] [error]       4,

[2020-05-01T17:08:29.860Z] [error]       ^

[2020-05-01T17:08:29.860Z] [info] String("search_behavioral_health_care") <: com.rallyhealth.mongo.models.InferenceType.Name?

[2020-05-01T17:08:29.860Z] [info] false

[2020-05-01T17:08:29.860Z] [error] /home/jenkins/workspace/ization_Kerna_build-kerna_PR-546/mongo/src/main/scala/com/rallyhealth/mongo/models/InferenceType.scala:120:7: no arguments allowed for nullary constructor Object: ()Object

[2020-05-01T17:08:29.860Z] [error]       5,

[2020-05-01T17:08:29.860Z] [error]       ^

[2020-05-01T17:08:29.860Z] [info] String("last_activity_engage_app") <: com.rallyhealth.mongo.models.InferenceType.Name?

[2020-05-01T17:08:29.860Z] [info] false

[2020-05-01T17:08:29.860Z] [error] /home/jenkins/workspace/ization_Kerna_build-kerna_PR-546/mongo/src/main/scala/com/rallyhealth/mongo/models/InferenceType.scala:130:7: no arguments allowed for nullary constructor Object: ()Object

[2020-05-01T17:08:29.860Z] [error]       6,

[2020-05-01T17:08:29.860Z] [error]       ^

I'm not able to reproduce it locally on sbt, so I'm not sure how to simplify the code much, but here a sample of where it seems to be choking:

object InferenceType extends IntEnum[InferenceType[InferenceShape]] {
  type Name = String Refined MatchesRegex[W.`"[a-z_0-9]+"`.T]

  override val values: immutable.IndexedSeq[InferenceType[InferenceShape]] = findValues

  private lazy val validValuesString: String = values.map(k => s"{name: '${k.name}', id: ${k.id}}").mkString(", ")

  def withId(id: Int)(implicit pos: Position): InferenceType[InferenceShape] = withValueOpt(id).getOrElse {
    // XXX This is where the compiler macro is choking...
    // It seems to have trouble auto refining the string "id" for the LogView.withKey method
    // TBD whether being inside string interpolation is the issue...
    throw new NoSuchElementException(
      s"Cannot find InferenceType with ${LogView.withKey("id", id)}, valid options are $validValuesString (${pos.show})"
    )
  }

  // ...
}

object LogKey {
  type Valid = MatchesRegex[W.`"[a-zA-Z_][a-zA-Z_0-9]+"`.T]
  type Name = String Refined Valid
}

object LogView {
  def withKey[V](
    key: LogKey.Name,
    value: V
  )(implicit
    format: LogFormat[V]
  ): String = {
    s"${key.value}=${format.write(value)}"
  }

  // ...
}

@jeffmay
Copy link

jeffmay commented May 1, 2020

Ok, update... it works after moving the LogView.withKey call outside of the string interpolation, however, this issue has been intermittent, so I'm not sure if it is fixed for good. I'll update this thread again if I see the issue come back.

@jeffmay
Copy link

jeffmay commented May 1, 2020

Another update: it is still broken 😢 Moving it out of the StringContext interpolation didn't help...

[2020-05-01T20:37:47.851Z] [error] java.lang.AssertionError: assertion failed: import failure: cannot determine unique overloaded method alternative from

[2020-05-01T20:37:47.851Z] [error]  final package eu

[2020-05-01T20:37:47.851Z] [error] final package eu

[2020-05-01T20:37:47.851Z] [error]  that matches package eu:eu.type

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.SymbolTable.throwAssertionError(SymbolTable.scala:170)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.disambiguate$1(Importers.scala:195)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:200)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:181)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreatedTreeCompleter(Importers.scala:310)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.$anonfun$importTree$1(Importers.scala:429)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.tryFixup(Importers.scala:61)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:430)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:395)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:395)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:379)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:382)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:41)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.macros.contexts.Evals.eval(Evals.scala:31)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.macros.contexts.Evals.eval$(Evals.scala:26)

[2020-05-01T20:37:47.851Z] [error] 	at scala.reflect.macros.contexts.Context.eval(Context.scala:18)

[2020-05-01T20:37:47.851Z] [error] 	at eu.timepit.refined.macros.MacroUtils.$anonfun$eval$1(MacroUtils.scala:22)

[2020-05-01T20:37:47.851Z] [error] 	at scala.Option.getOrElse(Option.scala:201)

[2020-05-01T20:37:47.851Z] [error] 	at eu.timepit.refined.macros.MacroUtils.tryN(MacroUtils.scala:26)

[2020-05-01T20:37:47.851Z] [error] 	at eu.timepit.refined.macros.MacroUtils.tryN$(MacroUtils.scala:25)

[2020-05-01T20:37:47.851Z] [error] 	at eu.timepit.refined.macros.RefineMacro.tryN(RefineMacro.scala:10)

[2020-05-01T20:37:47.851Z] [error] 	at eu.timepit.refined.macros.MacroUtils.eval(MacroUtils.scala:22)

[2020-05-01T20:37:47.851Z] [error] 	at eu.timepit.refined.macros.MacroUtils.eval$(MacroUtils.scala:15)

[2020-05-01T20:37:47.851Z] [error] 	at eu.timepit.refined.macros.RefineMacro.eval(RefineMacro.scala:10)

[2020-05-01T20:37:47.851Z] [error] 	at eu.timepit.refined.macros.RefineMacro.$anonfun$validateInstance$2(RefineMacro.scala:55)

[2020-05-01T20:37:47.851Z] [error] 	at scala.Option.getOrElse(Option.scala:201)

[2020-05-01T20:37:47.851Z] [error] 	at eu.timepit.refined.macros.RefineMacro.validateInstance(RefineMacro.scala:55)

[2020-05-01T20:37:47.852Z] [error] 	at eu.timepit.refined.macros.RefineMacro.impl(RefineMacro.scala:25)

[2020-05-01T20:37:47.852Z] [error] 	at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)

[2020-05-01T20:37:47.852Z] [error] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

[2020-05-01T20:37:47.852Z] [error] 	at java.lang.reflect.Method.invoke(Method.java:498)

[2020-05-01T20:37:47.852Z] [error] 	at scala.reflect.macros.runtime.JavaReflectionRuntimes$JavaReflectionResolvers.$anonfun$resolveJavaReflectionRuntime$5(JavaReflectionRuntimes.scala:45)

[2020-05-01T20:37:47.852Z] [error] 	at scala.tools.nsc.typechecker.Macros.macroExpandWithRuntime(Macros.scala:758)

[2020-05-01T20:37:47.852Z] [error]       val logName = LogView.withKey("name", lowercaseName)

@steinybot
Copy link
Contributor

I was just getting something very similar to this with Scala 2.12.10 and refined 0.9.14 (previously 0.9.4).

If I run sbt compile then it would fail but sbt runAll (lagom run task) it would work. Very strange.

@pacdaemon
Copy link

pacdaemon commented Jun 17, 2020

I just got one of those. I'm running Scala 2.12.11, SBT 1.13.10 and refined 0.9.14

[error] java.lang.AssertionError: assertion failed: import failure: cannot determine unique overloaded method alternative from
 
[error]  final package eu
 
[error] final package eu
 
[error]  that matches package eu:eu.type
 
[error] 	at scala.reflect.internal.SymbolTable.throwAssertionError(SymbolTable.scala:184)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.disambiguate$1(Importers.scala:195)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:200)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:181)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreatedTreeCompleter(Importers.scala:310)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.$anonfun$importTree$1(Importers.scala:429)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.tryFixup(Importers.scala:61)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:430)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:395)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:395)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:379)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:382)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)
 
[error] 	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:41)
 
[error] 	at scala.reflect.macros.contexts.Evals.eval(Evals.scala:31)
 
[error] 	at scala.reflect.macros.contexts.Evals.eval$(Evals.scala:26)
 
[error] 	at scala.reflect.macros.contexts.Context.eval(Context.scala:18)
 
[error] 	at eu.timepit.refined.macros.MacroUtils.$anonfun$eval$1(MacroUtils.scala:22)
 
[error] 	at scala.Option.getOrElse(Option.scala:189)
 
[error] 	at eu.timepit.refined.macros.MacroUtils.tryN(MacroUtils.scala:26)
 
[error] 	at eu.timepit.refined.macros.MacroUtils.tryN$(MacroUtils.scala:25)
 
[error] 	at eu.timepit.refined.macros.RefineMacro.tryN(RefineMacro.scala:10)
 
[error] 	at eu.timepit.refined.macros.MacroUtils.eval(MacroUtils.scala:22)
 
[error] 	at eu.timepit.refined.macros.MacroUtils.eval$(MacroUtils.scala:15)
 
[error] 	at eu.timepit.refined.macros.RefineMacro.eval(RefineMacro.scala:10)
 
[error] 	at eu.timepit.refined.macros.RefineMacro.$anonfun$validateInstance$2(RefineMacro.scala:55)
 
[error] 	at scala.Option.getOrElse(Option.scala:189)
 
[error] 	at eu.timepit.refined.macros.RefineMacro.validateInstance(RefineMacro.scala:55)
 
[error] 	at eu.timepit.refined.macros.RefineMacro.impl(RefineMacro.scala:25)
 

Right now I'm using just a single refined, this one:

object EmailModels {
  type EmailPred = MatchesRegex[W.`"""^([a-zA-Z0-9_\\-\\.\\+]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$"""`.T]
  type EmailRefinement = String Refined EmailPred
  @newtype
  case class Email(toStr: EmailRefinement)
  object Email {
    implicit val emailClass: ClassTag[Email] = deriving
    implicit val format: Format[Email] = deriving
  }
}

@kubukoz
Copy link
Contributor

kubukoz commented Jul 7, 2020

Seeing this on:
Refined 0.9.14
Scala 2.12.11
sbt 1.3.12 / bloop 1.4.3

exception during macro expansion: 
java.lang.AssertionError: assertion failed: import failure: cannot determine unique overloaded method alternative from
 final package eu
final package eu
 that matches package eu:eu.type
	at scala.reflect.internal.SymbolTable.throwAssertionError(SymbolTable.scala:184)
	at scala.reflect.internal.Importers$StandardImporter.disambiguate$1(Importers.scala:195)
	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:200)
	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)
	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:181)
	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)
	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)
	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)
	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)
	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)
	at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:178)
	at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:222)
	at scala.reflect.internal.Importers$StandardImporter.recreatedTreeCompleter(Importers.scala:310)
	at scala.reflect.internal.Importers$StandardImporter.$anonfun$importTree$1(Importers.scala:429)
	at scala.reflect.internal.Importers$StandardImporter.tryFixup(Importers.scala:61)
	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:430)
	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:395)
	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)
	at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:395)
	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:427)
	at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:41)
	at scala.reflect.macros.contexts.Evals.eval(Evals.scala:31)
	at scala.reflect.macros.contexts.Evals.eval$(Evals.scala:26)
	at scala.reflect.macros.contexts.Context.eval(Context.scala:18)
	at eu.timepit.refined.macros.MacroUtils.$anonfun$eval$1(MacroUtils.scala:22)
	at scala.Option.getOrElse(Option.scala:189)
	at eu.timepit.refined.macros.MacroUtils.tryN(MacroUtils.scala:26)
	at eu.timepit.refined.macros.MacroUtils.tryN$(MacroUtils.scala:25)
	at eu.timepit.refined.macros.RefineMacro.tryN(RefineMacro.scala:10)
	at eu.timepit.refined.macros.MacroUtils.eval(MacroUtils.scala:22)
	at eu.timepit.refined.macros.MacroUtils.eval$(MacroUtils.scala:15)
	at eu.timepit.refined.macros.RefineMacro.eval(RefineMacro.scala:10)
	at eu.timepit.refined.macros.RefineMacro.$anonfun$validateInstance$2(RefineMacro.scala:55)
	at scala.Option.getOrElse(Option.scala:189)
	at eu.timepit.refined.macros.RefineMacro.validateInstance(RefineMacro.scala:55)
	at eu.timepit.refined.macros.RefineMacro.impl(RefineMacro.scala:25)
	at jdk.internal.reflect.GeneratedMethodAccessor678.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at scala.reflect.macros.runtime.JavaReflectionRuntimes$JavaReflectionResolvers.$anonfun$resolveJavaReflectionRuntime$5(JavaReflectionRuntimes.scala:45)
	at scala.tools.nsc.typechecker.Macros.macroExpandWithRuntime(Macros.scala:823)

On code like this:

import eu.timepit.refined.auto._
val url: String Refined Url = "https://track.example.com/123456"

Update: it actually only happens in bloop...

@fthomas
Copy link
Owner

fthomas commented Jul 13, 2020

@kubukoz Can you deterministically reproduce this with bloop?

@kubukoz
Copy link
Contributor

kubukoz commented Jul 13, 2020

Not really deterministically, now everything is working fine... :(

@kubukoz
Copy link
Contributor

kubukoz commented Jul 21, 2020

aaaaand I got it again, on a codebase that used to compile... is there some diagnostic I can take when this happens?
Scala 2.12.12 this time.

Looks like I can refine things like PosInt and it usually (always?) works. Same for type Hour = Int Refined Positive. But type Hour = Int Refined Even breaks things...

@fthomas
Copy link
Owner

fthomas commented Jul 24, 2020

Looks like I can refine things like PosInt and it usually (always?) works. Same for type Hour = Int Refined Positive. But type Hour = Int Refined Even breaks things...

That's because some Validate instances are cached in RefineMacro (Validate[Int, Positive] is one of them) and are not reflectively evaluated at compile-time, see

private def validateInstance[T, P](v: c.Expr[Validate[T, P]])(implicit
T: c.WeakTypeTag[T],
P: c.WeakTypeTag[P]
): Validate[T, P] =
validateInstances
.collectFirst {
case (tpeT, instancesForT) if tpeT =:= T.tpe =>
instancesForT.collectFirst {
case (tpeP, validate) if tpeP =:= P.tpe =>
validate.asInstanceOf[Validate[T, P]]
}
}
.flatten
.getOrElse(eval(v))
private val validateInstances: List[(Type, List[(Type, Any)])] = {
def instance[T, P](implicit P: c.WeakTypeTag[P], v: Validate[T, P]): (Type, Validate[T, P]) =
P.tpe -> v
List(
weakTypeOf[Int] -> List(
instance[Int, Positive],
instance[Int, NonPositive],
instance[Int, Negative],
instance[Int, NonNegative]
),
weakTypeOf[Long] -> List(
instance[Long, Positive],
instance[Long, NonPositive],
instance[Long, Negative],
instance[Long, NonNegative]
),
weakTypeOf[Double] -> List(
instance[Double, Positive],
instance[Double, NonPositive],
instance[Double, Negative],
instance[Double, NonNegative]
),
weakTypeOf[String] -> List(
instance[String, NonEmpty]
),
weakTypeOf[Char] -> List(
instance[Char, Digit],
instance[Char, Letter],
instance[Char, LowerCase],
instance[Char, UpperCase],
instance[Char, Whitespace]
)
)
}

For Int Refined Even eval is called which is the source for this crash.

@jonathan-neufeld-asurion

I've noticed this fail sporadically with String Refined MatchesRegex[W."""[\w\-]+:[\w\-]+""".T], the compiler error reported cites the call site, not the refinement definition.

@tpolecat
Copy link
Author

I just saw this again, fwiw. Restarted sbt and it compiled fine. Confidence high! Maybe it will stop doing this in Scala 3 ;-)

@fthomas
Copy link
Owner

fthomas commented Mar 29, 2021

Yes, it won't happen with Scala 3 because that macro cannot be ported! :-)

@ThijsBroersen
Copy link

I am experiencing this same issue (Scala 2.13.7, jdk17) very randomly and rarely. Is there any other mitigation than compile twice?

@fthomas
Copy link
Owner

fthomas commented Jan 11, 2022

It seems that disabling parallel compilation might help, see scala/bug#10682 (comment) and gemini-hlsw/lucuma-core#449. The easier fix is to change compile-time checks of literals to runtime checks. This will also make it easier to port code to Scala 3, since the compile-time checks cannot be ported to Scala 3.

@strokyl
Copy link

strokyl commented Jan 12, 2023

Hello my team has encountered a lot flaky CI failure on GitHub action, scalac were failure with various and weird error. After a long search and isolating the first faulty commit. I found that removing all refineMV on the following constraint MatchesRegex["^#([0-9a-fA-F]{6})$"] resolved our issue.
We are using:

  • refined: 0.10.1
  • scala: 2.13.10
  • sbt: 1.8.2
  • JVM: temurin17 (same issue with Graal)
  • scalac option are set sbt-tpolecat (0.4.2).

Here some failure we got:

 [error] ## Exception when compiling 27 sources to /home/runner/work/conduktor-platform-api/conduktor-platform-api/modules/core/target/scala-2.13/classes
[error] java.lang.AssertionError: assertion failed: 
[error]   Tried to resolve io.conduktor.core.domain.auth.UserCreated to a  non local classes but the resolution works up to sbtDependency phase. We're at erasure
[error]      while compiling: /home/runner/work/conduktor-platform-api/conduktor-platform-api/modules/core/src/main/scala/io/conduktor/core/domain/auth/Users.scala


[error]   last tree to typer: Apply(method &&)
[error]        tree position: line 20 of /home/runner/work/conduktor-platform-api/conduktor-platform-api/modules/core/src/main/scala/io/conduktor/core/domain/permissions/package.scala
[error]             tree tpe: Boolean
[error]               symbol: method && in class Boolean
[error]    symbol definition: def &&(x: Boolean): Boolean (a MethodSymbol)
[error]       symbol package: scala
[error]        symbol owners: method && -> class Boolean
[error]            call site: trait UserRepository in package repository in package repository

[error]   last tree to typer: Apply(method &&)
[error]        tree position: line 20 of /home/runner/work/conduktor-platform-api/conduktor-platform-api/modules/core/src/main/scala/io/conduktor/core/domain/permissions/package.scala
[error]             tree tpe: Boolean
[error]               symbol: method && in class Boolean
[error]    symbol definition: def &&(x: Boolean): Boolean (a MethodSymbol)
[error]       symbol package: scala
[error]        symbol owners: method && -> class Boolean
[error]            call site: trait UserRepository in package repository in package repository
[error] Error while emitting Domain.scala
[error] io.estatico.newtype.Coercible[A,B] (of class scala.reflect.internal.Types$NullaryMethodType)
[error] Error while emitting Domain.scala
[error] assertion failed: 
[error]   Bad superClass for class Any: <none>
[error]      while compiling: /home/runner/work/conduktor-platform-api/conduktor-platform-api/modules/core/src/main/scala/io/conduktor/core/domain/Domain.scala
[error]         during phase: globalPhase=jvm, enteringPhase=parser
[error]      library version: version 2.13.10
[error]     compiler version: version 2.13.10


[error] Error while emitting Domain.scala
[error] (): Int (of class scala.reflect.internal.Types$MethodType)
[error] Error while emitting Domain.scala
[error] assertion failed: Bad superClass for trait Tag: class Any
[error] Error while emitting Domain.scala
[error] assertion failed: type TC
[error] Error while emitting Domain.scala
[error] assertion failed: type Type
[warn] an unexpected type representation reached the compiler backend while compiling Domain.scala: (): Int. If possible, please file a bug on https://github.com/scala/bug/issues.
[error] Error while emitting Domain.scala
[error] (): Int (of class scala.reflect.internal.Types$MethodType)
[error] Error while emitting Domain.scala
[error] assertion failed: Bad superClass for trait Tag: class Any
[error] Error while emitting Users.scala
[error] assertion failed: type Type

@strokyl
Copy link

strokyl commented Jan 12, 2023

Ok my CI was also fix by:

Global / concurrentRestrictions += Tags.limit(Tags.Compile, 1)

So I think it's a scalac bug and not a refine bug.

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

Successfully merging a pull request may close this issue.