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

Error when running on circe #47

Closed
olafurpg opened this issue Jan 28, 2017 · 6 comments
Closed

Error when running on circe #47

olafurpg opened this issue Jan 28, 2017 · 6 comments

Comments

@olafurpg
Copy link
Contributor

olafurpg commented Jan 28, 2017

When using the scalafix compiler plugin and compiling circe

[error] /home/geirsson/scalafix/target/it/circe/tests/shared/src/test/scala/io/circe/refined/RefinedSuite.scala:32: exception during macro expansion:
[error] java.lang.AssertionError: assertion failed: shapeless package shapeless <none>
[error]         at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:193)
[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.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:374)
[error]         at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415)
[error]         at scala.reflect.internal.Importers$StandardImporter$$anonfun$recreateTree$18.apply(Importers.scala:370)
[error]         at scala.reflect.internal.Importers$StandardImporter$$anonfun$recreateTree$18.apply(Importers.scala:370)
[error]         at scala.collection.immutable.List.map(List.scala:273)
[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.tools.reflect.ToolBoxFactory$ToolBoxImpl$$anonfun$compile$2.apply(ToolBoxFactory.scala:426)
[error]         at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$$anonfun$compile$2.apply(ToolBoxFactory.scala:422)
[error]         at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$withCompilerApi$.liftedTree2$1(ToolBoxFactory.scala:355)
[error]         at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$withCompilerApi$.apply(ToolBoxFactory.scala:355)
[error]         at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.compile(ToolBoxFactory.scala:422)
[error]         at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.eval(ToolBoxFactory.scala:444)
[error]         at scala.reflect.macros.contexts.Evals$class.eval(Evals.scala:20)
[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:22)
[error]     val n = refineMV[Greater[W.`2`.T]](5)
@olafurpg
Copy link
Contributor Author

Any idea if my hijack import info hackery caused this error @xeno-by?

@olafurpg
Copy link
Contributor Author

@fthomas any idea if this might be caused a bug in the refined macro? I was compiling circe with the scalafix compiler plugin, the compiler plugin does some evil things in scalac's global to access import info https://github.com/scalacenter/scalafix/blob/master/scalafix-nsc/src/main/scala/scalafix/nsc/HijackImportInfos.scala#L13

@olafurpg
Copy link
Contributor Author

Investigating this further, I suspect this error is caused by runnig c.eval multiple times, see here https://github.com/fthomas/refined/blob/c734e3e80b094da515047daa748ad4fdb68cf7ff/modules/core/shared/src/main/scala/eu/timepit/refined/macros/MacroUtils.scala#L20

My hack in scalafix is to hijack the allImportInfos allUsedImportSelectors maps in g.analyzer: Contexts with a custom HashMap whose -= does nothing. I don't know how that could trigger this error.

For context, here is where the assertion fails in scala/scala https://github.com/scala/scala/blob/b9d4089d19ead36d07c2d6cdda283c9b678d515e/src/reflect/scala/reflect/internal/Importers.scala#L196

@xeno-by
Copy link
Contributor

xeno-by commented Jan 28, 2017

@olafurpg I'm not sure how hijacking these maps could lead to a crash in importers. To the best of my knowledge, importers never touch this part of the compiler. What if you don't do the hijacking? Does it still crash?

@olafurpg
Copy link
Contributor Author

olafurpg commented Jan 28, 2017 via email

@olafurpg
Copy link
Contributor Author

The scalafix compiler plugin no longer exists.

bjaglin added a commit to liancheng/scalafix that referenced this issue May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants