Skip to content

Commit d1cb9de

Browse files
committed
Address review comments
- Move $throws to scala.runtime - Add comment
1 parent af9b940 commit d1cb9de

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,13 +1261,15 @@ object desugar {
12611261
makeOp(left, right, Span(left.span.start, op.span.end, op.span.start))
12621262
}
12631263

1264-
/** Translate throws type `A throws E1 | ... | En`
1264+
/** Translate throws type `A throws E1 | ... | En` to
1265+
* $throws[... $throws[A, E1] ... , En].
12651266
*/
12661267
def throws(tpt: Tree, op: Ident, excepts: Tree)(using Context): AppliedTypeTree = excepts match
12671268
case InfixOp(l, bar @ Ident(tpnme.raw.BAR), r) =>
12681269
throws(throws(tpt, op, l), bar, r)
12691270
case e =>
1270-
AppliedTypeTree(cpy.Ident(op)(tpnme.THROWS), tpt :: excepts :: Nil)
1271+
AppliedTypeTree(
1272+
TypeTree(defn.throwsAlias.typeRef).withSpan(op.span), tpt :: excepts :: Nil)
12711273

12721274
/** Translate tuple expressions of arity <= 22
12731275
*

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ class Definitions {
834834
CanEqualClass.companionModule.requiredMethod(methodName)
835835

836836
@tu lazy val CanThrowClass: ClassSymbol = requiredClass("scala.CanThrow")
837+
@tu lazy val throwsAlias: Symbol = ScalaRuntimePackageVal.requiredType(tpnme.THROWS)
837838

838839
@tu lazy val TypeBoxClass: ClassSymbol = requiredClass("scala.runtime.TypeBox")
839840
@tu lazy val TypeBox_CAP: TypeSymbol = TypeBoxClass.requiredType(tpnme.CAP)

library/src-bootstrapped/scala/CanThrow.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,7 @@ import annotation.{implicitNotFound, experimental}
1010
@implicitNotFound("The capability to throw exception ${E} is missing.\nThe capability can be provided by one of the following:\n - A using clause `(using CanThrow[${E}])`\n - A `throws` clause in a result type such as `X throws ${E}`\n - an enclosing `try` that catches ${E}")
1111
erased class CanThrow[-E <: Exception]
1212

13-
/** A helper type to allow syntax like
14-
*
15-
* def f(): T throws Ex1 | Ex2
16-
*
17-
* Used in desugar.throws.
18-
*/
19-
@experimental
20-
infix type $throws[R, +E <: Exception] = CanThrow[E] ?=> R
21-
2213
@experimental
2314
object unsafeExceptions:
2415
given canThrowAny: CanThrow[Exception] = ???
16+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package scala.runtime
2+
import annotation.experimental
3+
4+
/** A helper type to allow syntax like
5+
*
6+
* def f(): T throws Ex1 | Ex2
7+
*
8+
* Used in desugar.throws.
9+
*/
10+
@experimental
11+
infix type $throws[R, +E <: Exception] = CanThrow[E] ?=> R

0 commit comments

Comments
 (0)