diff --git a/modules/internal/src/main/scala/higherkindness/mu/rpc/internal/serviceImpl.scala b/modules/internal/src/main/scala/higherkindness/mu/rpc/internal/serviceImpl.scala index a138bcfe5..8996988c3 100644 --- a/modules/internal/src/main/scala/higherkindness/mu/rpc/internal/serviceImpl.scala +++ b/modules/internal/src/main/scala/higherkindness/mu/rpc/internal/serviceImpl.scala @@ -285,6 +285,34 @@ object serviceImpl { ..$nonRpcDefs }""".supressWarts("DefaultArguments") + /* + * When you write an anonymous parameter in an anonymous function that + * ignores the parameter, e.g. `List(1, 2, 3).map(_ => "hello")` the + * -Wunused:params scalac flag does not warn you about it. That's + * because the compiler attaches a `NoWarnAttachment` to the tree for + * the parameter. + * + * But if you write the same thing in a quasiquote inside a macro, the + * attachment does not get added, so you get false-positive compiler + * warnings at the macro use site like: "parameter value x$2 in anonymous + * function is never used". + * + * (The parameter needs a name, even though the function doesn't + * reference it, so `_` gets turned into a fresh name e.g. `x$2`. The + * same thing happens even if you're not in a macro.) + * + * I'd say this is a bug in Scala. We work around it by manually adding + * the attachment. + */ + private def anonymousParam: ValDef = { + val tree: ValDef = q"{(_) => 1}".vparams.head + c.universe.internal.updateAttachment( + tree, + c.universe.asInstanceOf[scala.reflect.internal.StdAttachments].NoWarnAttachment + ) + tree + } + val client: DefDef = q""" def client[$F_]( @@ -296,7 +324,7 @@ object serviceImpl { _root_.cats.effect.Resource.make { new _root_.higherkindness.mu.rpc.channel.ManagedChannelInterpreter[$F](channelFor, channelConfigList).build }(channel => CE.void(CE.delay(channel.shutdown()))).flatMap(ch => - _root_.cats.effect.Resource.make[F, $serviceName[$F]](CE.delay(new $Client[$F](ch, options)))(_ => CE.unit)) + _root_.cats.effect.Resource.make[F, $serviceName[$F]](CE.delay(new $Client[$F](ch, options)))($anonymousParam=> CE.unit)) """.supressWarts("DefaultArguments") val clientFromChannel: DefDef = @@ -306,7 +334,7 @@ object serviceImpl { options: _root_.io.grpc.CallOptions = _root_.io.grpc.CallOptions.DEFAULT )(implicit ..$classImplicits): _root_.cats.effect.Resource[$F, $serviceName[$F]] = _root_.cats.effect.Resource.make(channel)(channel => CE.void(CE.delay(channel.shutdown()))).flatMap(ch => - _root_.cats.effect.Resource.make[$F, $serviceName[$F]](CE.delay(new $Client[$F](ch, options)))(_ => CE.unit)) + _root_.cats.effect.Resource.make[$F, $serviceName[$F]](CE.delay(new $Client[$F](ch, options)))($anonymousParam => CE.unit)) """.supressWarts("DefaultArguments") val unsafeClient: DefDef =