tek / splain

better implicit errors for scala
MIT License
370 stars 29 forks source link

Run after macro expansion #4

Closed sellout closed 3 years ago

sellout commented 7 years ago

With Splain I’m getting an error saying that an implicit I reference doesn’t exist. My guess is that this is because the implicit in question is generated by Simulacrum’s @typeclass macro, and Splain is running before it generates the implicit.

tek commented 7 years ago

can you provide a test case? I'm not having any problems with simulacrum.

sellout commented 7 years ago
import simulacrum.typeclass

@typeclass trait Foo[A] {
  def foo(a: A): A
}

package object implicits extends Foo.ToFooOps

This errors with “not found: value Foo”. If I add a dummy companion object, it errors with “type ToFooOps is not a member of object Foo”. If I disable splain, it compiles cleanly. (My original code has a bunch of stuff in explicitly-created companion, so I didn’t see that first error before.)

tek commented 7 years ago

that's pretty peculiar…first of all, the error occurs even if the implicits feature is deactivated. also, the plugin doesn't really run at a specific time, it just overwrites some of the default phases. I don't have the slightest idea how this could be caused, but I'll try and dig around.

tek commented 7 years ago

so, I just noticed that your case failed when I tried because I was using a toolbox to compile the code, which, of course, doesn't include macro paradise just because it is an sbt dependency. Testing in a regular environment resulted in successful compilation, so the problem must be more specific to your setup. Would you upload a minimal project that fails?

sellout commented 7 years ago

Oh, I have a theory … still narrowing it down, but this wouldn’t surprise me:

scalaOrganization := "org.typelevel"
sellout commented 7 years ago

Nope.

sellout commented 7 years ago

Ok, I have a very minimal project at https://github.com/sellout/matryoshka/tree/test-splain that still fails. It’s being built with sbt 0.13.13 and ~/.sbt has been removed.

Commenting out the Splain plugin makes it compile (with a feature warning that can be eliminated by adding scalacOptions += "-language:implicitConversions").

tek commented 7 years ago

this is really weird, but it works for me if I change the paradise version spec to 2.1.+. Even though that doesn't change the actual version.

sellout commented 7 years ago

Hrmm, I still have no luck with

addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.+" cross CrossVersion.full)
tek commented 7 years ago

the only thing that comes to mind is that the change triggered some reordering of the plugins, but it seems to work pretty consistently here. very strange

jrgonzalezg commented 7 years ago

A similar issue also happened to me using https://github.com/frees-io/freestyle that depends on https://github.com/scalamacros/paradise . After reading the comments about reordering here i got my project working by adding the splain compiler plugin before the paradise one so that may also help on similar cases.

tek commented 7 years ago

huh, interesting!

jrgonzalezg commented 7 years ago

But today i added coursier (https://github.com/coursier/coursier) and build fails again and the reordering does not help in this case, so the workaround seems to be very fragile...

nafg commented 5 years ago

Somehow 0.3.4 is breaking monocle @Lenses, while 0.3.3 is fine. At least on this project. I'm pretty sure it didn't cause issues elsewhere.

Is splain modifying any trees?

tek commented 5 years ago

I wish I could give you an answer :smile: it seems to be completely random

julianmichael commented 5 years ago

I've had this issue a couple times now, with implicits from simulacrum (@typeclass), circe-generic (@JsonCodec), and monocle (@Lenses) all missing when I include splain in the build process. Weirdly it seems to depend on something the build tool is doing, because the same exact build works fine on mill 0.2.3 but not 0.3.5. I don't have the bandwidth to dig into it in more detail (nor do I expect anything), but just thought I would drop in the extra data point for anyone else finding this.

nafg commented 5 years ago

Is splain modifying trees?

btw 0.4.0 seems much worse, it breaks monocle much more

tek commented 5 years ago

nope, no modifications.

tek commented 5 years ago

hello dear reporters, please take a look at the new PR for integration into scalac: https://github.com/scala/scala/pull/7785

tek commented 3 years ago

fixed by https://github.com/scala/scala/pull/7785