Skip to content

Commit fc82020

Browse files
committed
Fix problem when erasing erased context functions
1 parent 02a5955 commit fc82020

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,9 @@ object Erasure {
892892
case closureDef(meth) =>
893893
val contextParams = meth.termParamss.head
894894
for param <- contextParams do
895-
param.symbol.copySymDenotation(owner = sym).installAfter(erasurePhase)
896-
vparams ++= contextParams
895+
if !param.symbol.is(Flags.Erased) then
896+
param.symbol.copySymDenotation(owner = sym).installAfter(erasurePhase)
897+
vparams = vparams :+ param
897898
if crCount == 1 then meth.rhs.changeOwnerAfter(meth.symbol, sym, erasurePhase)
898899
else skipContextClosures(meth.rhs, crCount - 1)
899900

library/src/scala/annotation/internal/ContextResultCount.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scala.annotation
22
package internal
33

4-
/** An annotation that's aitomatically added for methods
4+
/** An annotation that's automatically added for methods
55
* that have one or more nested context closures as their right hand side.
66
* The parameter `n` is an Int Literal that tells how many nested closures
77
* there are.

tests/pos/CanThrow.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package canThrowStrawman
2+
import language.experimental.erasedTerms
3+
4+
class CanThrow[E <: Throwable]
5+
6+
infix type throws1[R, E <: Throwable] = (erased CanThrow[E]) ?=> R
7+
8+
class Fail extends Exception
9+
10+
def foo(x: Boolean): Int throws1 Fail =
11+
if x then 1 else throw Fail()

0 commit comments

Comments
 (0)