0.2.0 macro expansion creates unused ZLayer.requires[Any] val, which triggers scalac warnings
See original GitHub issueThanks @kitlangton for back-porting layer memoization, it’s a life-saver!
It did create a new issue: there is now a val layer$macro$1 = ZLayer.requires[Any];
val generated, which will trigger scalac warnings since it’s unused. Here’s a reproducer:
Given this scalac options in build.sbt
:
scalacOptions := Seq(
"-Wunused:_", // Warn unused
"-Wmacros:after", // Warn after macro expansions, a must for Scala 2.13.5+, else there are tons of false positive warnings due to typeclass derivation for most Scala libraries out there
"-Wconf:any:wv"
)
And this app:
import zio.{Has, ZLayer}
import zio.magic._
object ZioMagicUnusedWarnings {
def main(args: Array[String]): Unit = {
val layer = ZLayer.fromMagic[Has[Double]](
ZLayer.requires[Has[Int]].map(v => Has(v.get.toDouble)),
ZLayer.succeed(123)
)
println(layer)
}
}
The macro will expand into:
val layer$macro$1 = ZLayer.requires[Any];
val layer$macro$2 = zio.ZLayer.requires[zio.Has[Int]].map[zio.Has[Double]](((v: zio.Has[Int]) =>
zio.Has.apply[Double](zio.this.Has.HasSyntax[zio.Has[Int]](v).get[Int](
scala.this.<:<.refl[zio.Has[Int]],
(izumi.reflect.Tag.apply[Int](
classOf[scala.Int],
izumi.reflect.macrortti.LightTypeTag.parse[Nothing](
(1454689320: Int),
("\u0004\u0000\u0001\tscala.Int\u0001\u0001": String),
("\u0000\u0001\u0004\u0000\u0001\tscala.Int\u0001\u0001\u0001\u0004\u0000\u0001\fscala.AnyVal\u0001\u0001\u0001\u0000\u0001\u0090\u0002\u0001\u0001\u0001\u0000\u0001\u0090\u0003\u0001\u0001": String),
(1: Int)
)
): izumi.reflect.Tag[Int])
).toDouble)((izumi.reflect.Tag.apply[Double](
classOf[scala.Double],
izumi.reflect.macrortti.LightTypeTag.parse[Nothing](
(1618223923: Int),
("\u0004\u0000\u0001\fscala.Double\u0001\u0001": String),
("\u0000\u0001\u0004\u0000\u0001\fscala.Double\u0001\u0001\u0001\u0004\u0000\u0001\fscala.AnyVal\u0001\u0001\u0001\u0000\u0001\u0090\u0002\u0001\u0001\u0001\u0000\u0001\u0090\u0003\u0001\u0001": String),
(1: Int)
)
): izumi.reflect.Tag[Double])))
);
val layer$macro$3 = zio.ZLayer.succeed[Int](123)((izumi.reflect.Tag.apply[Int](
classOf[scala.Int],
izumi.reflect.macrortti.LightTypeTag.parse[Nothing](
(1454689320: Int),
("\u0004\u0000\u0001\tscala.Int\u0001\u0001": String),
("\u0000\u0001\u0004\u0000\u0001\tscala.Int\u0001\u0001\u0001\u0004\u0000\u0001\fscala.AnyVal\u0001\u0001\u0001\u0000\u0001\u0090\u0002\u0001\u0001\u0001\u0000\u0001\u0090\u0003\u0001\u0001": String),
(1: Int)
)
): izumi.reflect.Tag[Int]));
layer$macro$3.$greater$greater$greater(layer$macro$2)
Looks like Any
should just be ignored when decomposing the Env
type.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (9 by maintainers)
Top Results From Across the Web
2.12.4 regression (?): Spurious unused warnings · Issue #10571
In 2.12.3, private/local values that are used in macro expansions were considered to be used, but in 2.12.4, they trigger unused value warnings....
Read more >Scala Compiler Options
The Scala compiler scalac offers various compiler options, or flags, that change the compiler's default behavior. Some options just generate more compiler ...
Read more >How can I tell scalac to suppress warnings is macro ...
I'm currently using a macro (ZIO's @mockable ) whose generated code is causing a compilation error that is causing my build to fail:...
Read more >How to set Fatal Warnings in Scala 2.13?
-Wextra-implicit Warn when more than one implicit parameter section is defined. -Wmacros:<mode> Enable lint warnings on macro expansions.
Read more >Scala Compiler Options, Fatal Warnings and Linting Guide
In this video we are going to learn all there is to know related to scalac options related to warnings and linting. Where...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
0.2.2 did it! I don’t see any more of those so will close this now.
@kitlangton Oh I just added
"-Ymacro-debug-lite"
toscalacOptions
, scary output for sure 😃)Also hopefully this PR will catch all of those in the future https://github.com/kitlangton/zio-magic/pull/48