Skip to content

Commit f68d5aa

Browse files
committed
Add thrown exceptions to generic java signature
1 parent 356ed5a commit f68d5aa

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,11 +1034,23 @@ object Erasure {
10341034
else None
10351035
}
10361036

1037-
// TODO: Port from scalac
1038-
private object ThrownException {
1039-
def unapply(ann: Annotation): Option[Type] = None
1037+
/** Extracts the type of the thrown exception from an AnnotationInfo.
1038+
*
1039+
* Supports both “old-style” `@throws(classOf[Exception])`
1040+
* as well as “new-style” `@throws[Exception]("cause")` annotations.
1041+
*/
1042+
object ThrownException {
1043+
def unapply(ann: Annotation)(implicit ctx: Context): Option[Type] = {
1044+
ann.tree match {
1045+
case Apply(TypeApply(fun, List(tpe)), _) if tpe.isType && fun.symbol.owner == defn.ThrowsAnnot && fun.symbol.isConstructor =>
1046+
Some(tpe.typeOpt)
1047+
case _ =>
1048+
None
1049+
}
1050+
}
10401051
}
10411052

1053+
10421054
class UnknownSig extends Exception
10431055

10441056
private def needsJavaSig(tp: Type, throwsArgs: List[Type])(implicit ctx: Context): Boolean = !ctx.settings.YnoGenericSig.value && {

0 commit comments

Comments
 (0)