fthomas / refined

Refinement types for Scala
MIT License
1.71k stars 157 forks source link

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

Open tpolecat opened 7 years ago

tpolecat commented 7 years ago

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 commented 7 years ago

Oh dear! I haven't seen this one yet. Stack traces I've seen so far are https://github.com/fthomas/refined/issues/3 and https://github.com/scalacenter/scalafix/issues/47.

fthomas commented 7 years ago

@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 commented 7 years ago

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

tpolecat commented 7 years ago

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 commented 7 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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

NeQuissimus commented 6 years ago

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

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

fthomas commented 6 years ago

@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 commented 5 years ago

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 commented 4 years ago

I'm seeing this in the Scala community build at https://github.com/scala/community-build/issues/1039

fthomas commented 4 years ago

I've just read this comment by @retronym in https://github.com/scala/bug/issues/9218#issuecomment-565285839:

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Seeing this on 2.12.11, refined 0.9.12

jeffmay commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@kubukoz Can you deterministically reproduce this with bloop?

kubukoz commented 4 years ago

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

kubukoz commented 4 years ago

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 commented 4 years ago

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 https://github.com/fthomas/refined/blob/4fa9cbc7bc308d820f82e69d0f0ead7502d95f8d/modules/core/shared/src/main/scala/eu/timepit/refined/macros/RefineMacro.scala#L40-L89

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

jonathan-neufeld-asurion commented 3 years ago

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 commented 3 years ago

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

fthomas commented 3 years ago

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

ThijsBroersen commented 2 years ago

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

fthomas commented 2 years ago

It seems that disabling parallel compilation might help, see https://github.com/scala/bug/issues/10682#issuecomment-1005130476 and https://github.com/gemini-hlsw/lucuma-core/pull/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 commented 1 year ago

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:

[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: [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 commented 1 year ago

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.