Skip to content

Commit 80bebc9

Browse files
committed
Fix: wrap extensions in toplevel package objects
1 parent b2bc105 commit 80bebc9

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ object desugar {
12681268
}
12691269

12701270
private def isTopLevelDef(stat: Tree)(using Context): Boolean = stat match
1271-
case _: ValDef | _: PatDef | _: DefDef | _: Export => true
1271+
case _: ValDef | _: PatDef | _: DefDef | _: Export | _: ExtMethods => true
12721272
case stat: ModuleDef =>
12731273
stat.mods.isOneOf(GivenOrImplicit)
12741274
case stat: TypeDef =>

tests/pos/i6565.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ class Err
33
type Lifted[A] = Err | A
44

55
def point[O](o: O): Lifted[O] = o
6-
def [O, U](o: Lifted[O]).map(f: O => U): Lifted[U] = ???
7-
def [O, U](o: Lifted[O]).flatMap(f: O => Lifted[U]): Lifted[U] = ???
6+
extension [O, U](o: Lifted[O]) def map(f: O => U): Lifted[U] = ???
7+
extension [O, U](o: Lifted[O]) def flatMap(f: O => Lifted[U]): Lifted[U] = ???
88

99
val error: Err = Err()
1010

tests/pos/i7041.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import scala.util.control.NonLocalReturns._
22

3-
inline def [T, E <: Throwable](op: => T) rescue (fallback: PartialFunction[E, T]) =
4-
try op
5-
catch {
6-
case ex: ReturnThrowable[_] => throw ex
7-
case ex: E =>
8-
if (fallback.isDefinedAt(ex)) fallback(ex) else throw ex
9-
}
3+
extension [T, E <: Throwable](op: => T)
4+
inline def rescue (fallback: PartialFunction[E, T]) =
5+
try op
6+
catch {
7+
case ex: ReturnThrowable[_] => throw ex
8+
case ex: E =>
9+
if (fallback.isDefinedAt(ex)) fallback(ex) else throw ex
10+
}
1011

1112
def test: Unit = {
1213
9 / 0 rescue { case _: ArithmeticException => 10 }

tests/pos/i7458.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
type Tr[+V1, +O1 <: V1]
2-
def [V2, O2 <: V2](tr: Tr[V2, O2]) sl: Tr[V2, O2] = ???
2+
extension [V2, O2 <: V2](tr: Tr[V2, O2]) def sl: Tr[V2, O2] = ???
33
def as[V3, O3 <: V3](tr: Tr[V3, O3]) : Tr[V3, O3] = tr.sl

0 commit comments

Comments
 (0)