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

Lints should respect -Wmacros #12072

Closed
neko-kai opened this issue Jul 6, 2020 · 7 comments · Fixed by scala/scala#10781
Closed

Lints should respect -Wmacros #12072

neko-kai opened this issue Jul 6, 2020 · 7 comments · Fixed by scala/scala#10781

Comments

@neko-kai
Copy link

neko-kai commented Jul 6, 2020

reproduction steps

using Scala 2.13.3:

Scastie showing the warning: https://scastie.scala-lang.org/r3Fnc5YcSzeA91CKs06EtQ

// libraryDependencies += "com.github.alexarchambault" %% "scalacheck-shapeless_1.14" % "1.2.5"

import org.scalacheck.Arbitrary

final case class X(s: String)
object X {
  implicit val arb: Arbitrary[X] = org.scalacheck.derive.MkArbitrary[X].arbitrary
}

problem

Getting a warning:

Block result was adapted via implicit conversion (method apply) taking a by-name parameter

But the warning applies to the code generated by shapeless.Lazy macro, not user-written code. This makes it mandatory to disable the -Xlint:byname-implicit due to the massive amount of false positives whenever implicit derivation is used.

@som-snytt som-snytt changed the title Spurious "Block result was adapted via implicit conversion" warning whenever shapeless.Lazy is used for implicit derivation Lints should respect -Wmacros Jul 7, 2020
@som-snytt
Copy link

-Wunused consults -Wmacros, and it looks like -Xlint:missing-interpolator attempts to avoid reporting on macro expansion. Maybe typer could just tell reporter not to report warnings.

@SethTisue
Copy link
Member

fyi @milessabin

@milessabin
Copy link

I'd seen this and assumed the linter rule was trigger happy and disabled it.

There's nothing I can do here because the structure is essential to the encoding of Lazy. It's a shame this wasn't picked up in the community build.

@diesalbla
Copy link

The error message was introduced by scala/scala#8590

@SethTisue
Copy link
Member

volunteer to attempt to improve the situation?

@lrytz
Copy link
Member

lrytz commented Dec 4, 2020

Maybe we can find a secret handshake to sidestep the warning? It would also be good not to warn if the method call is written by the user, not synthesized by the compiler:

scala> implicit def f(x: => Int): Int = x
warning: 1 feature warning; for details, enable `:setting -feature` or `:replay -feature`
def f(x: => Int): Int

scala> { println("hi"); f(1) }
                         ^
       warning: Block result was adapted via implicit conversion (method f) taking a by-name parameter
hi
val res0: Int = 1

Alternatively, the shapeless macro could add a : @nowarn("cat=lint-byname-implicit") ascription.

scala> { println("hi"); f(1) } : @annotation.nowarn("cat=lint-byname-implicit")
hi

@alexklibisz
Copy link

If anyone else is trying to figure out how to suppress just this one type of lint warning:

-Xlint:-byname-implicit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants