Skip to content

Commit ced86e4

Browse files
committed
Add thrown exceptions to generic java signature
1 parent 63754e7 commit ced86e4

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
@@ -1035,11 +1035,23 @@ object Erasure {
10351035
else None
10361036
}
10371037

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

1054+
10431055
class UnknownSig extends Exception
10441056

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

0 commit comments

Comments
 (0)