Skip to content

@nowarn on early initializer does not work inside class with annotation macro #12498

Open
@pweisenburger

Description

@pweisenburger

Reproduction steps

Using Scala 2.13.7 with -Ymacro-annotations, define a macro annotation that just leaves the annotated class unchanged:

package test

import scala.annotation.StaticAnnotation
import scala.language.experimental.macros
import scala.reflect.macros.blackbox

class Test extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro TestImpl.test
}

object TestImpl {
  def test(c: blackbox.Context)(annottees: c.Tree*): c.Tree = annottees.head
}

Apply the annotation as in the following:

@test.Test class C {
  new { val v = 1 } with AnyRef: @scala.annotation.nowarn("msg=early initializers")
}

Problem

The compiler generates the following warnings:

early initializers are deprecated; they will be replaced by trait parameters in 3.0, see the migration guide on avoiding var/val in traits.
  new { val v = 1 } with AnyRef: @scala.annotation.nowarn("msg=early initializers")
      ^
@nowarn annotation does not suppress any warnings
  new { val v = 1 } with AnyRef: @scala.annotation.nowarn("msg=early initializers")
                                  ^

I would expected that the annotation actually suppresses the first warning (making also the second warning void). Hence, I would expect compilation without warnings. In particular, there is no warning when leaving out the macro annotation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions