scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Annotation arg induces unrelated warning #12834

Open som-snytt opened 11 months ago

som-snytt commented 11 months ago

Reproduction steps

Scala version: 2.13.11

import scala.annotation.nowarn

class C {
  def f =
    try ???
    catch { case _: NullPointerException => }: @nowarn
  def g =
    try ???
    catch { case _: NullPointerException => }: @nowarn("cat=w-flag-value-discard")
}

Problem

catchem.scala:10: warning: This catches all Throwables. If this is really intended, use `case _ : Throwable` to clear this warning.
    catch { case _: NullPointerException => }: @nowarn("cat=w-flag-value-discard")
                                                ^
1 warning

Warns at g but not at f. The correct code adds parens (try ??? catch { ... }): @nowarn.