diff --git a/compiler/src/dotty/tools/backend/jvm/GenericSignatures.scala b/compiler/src/dotty/tools/backend/jvm/GenericSignatures.scala index adf5f72864a3..1a954519bada 100644 --- a/compiler/src/dotty/tools/backend/jvm/GenericSignatures.scala +++ b/compiler/src/dotty/tools/backend/jvm/GenericSignatures.scala @@ -439,7 +439,7 @@ object GenericSignatures { jsig(info, toplevel = true) for annot <- sym0.annotations do annot match - case ThrownException(e) => + case ThrownException(e) if sym0.is(Method) => // ThrowsSignature is only valid in MethodSignature builder.append('^') jsig(e, toplevel = true) case _ => () diff --git a/tests/run/throws-annot.scala b/tests/run/throws-annot.scala index 444251c7f83b..587c2947c9b3 100644 --- a/tests/run/throws-annot.scala +++ b/tests/run/throws-annot.scala @@ -68,6 +68,15 @@ object TL { def readNoEx(): Int = 0 } +// @throws on class/object/field must be ignored/compiler shouldn't crash. +@throws(classOf[IOException]) +class ThrowsOnClass + +@throws(classOf[IOException]) +object ThrowsOnObject: + @throws(classOf[IOException]) + val field: Int = 0 + object Test { def main(args: Array[String]): Unit = { TestThrows.run(classOf[TestThrows.Foo])