Skip to content

Commit 75b6143

Browse files
committed
Fix definition of enclosingExtensionMethod
Now also finds enclosing methods outside the current class. Fixes #13075
1 parent 27e221b commit 75b6143

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,11 +1140,10 @@ object SymDenotations {
11401140
else NoSymbol
11411141

11421142
/** The closest enclosing extension method containing this definition,
1143-
* provided the extension method appears in the same class.
1143+
* including methods outside the current class.
11441144
*/
11451145
final def enclosingExtensionMethod(using Context): Symbol =
11461146
if this.is(ExtensionMethod) then symbol
1147-
else if this.isClass then NoSymbol
11481147
else if this.exists then owner.enclosingExtensionMethod
11491148
else NoSymbol
11501149

tests/neg/i13075.scala

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
object Implementing_Tuples:
2+
3+
sealed trait Tup
4+
case class ConsTup[T, H <: Tup](head: T, tail: H) extends Tup
5+
case object EmptyTup extends Tup
6+
7+
val *: = ConsTup // for unapply
8+
type *:[H, T <: Tup] = ConsTup[H, T] // for type matching
9+
type EmptyTup = EmptyTup.type // for type matching
10+
11+
extension [H](head: H)
12+
def *:[T <: Tup](tail: T) = ConsTup(head, tail)
13+
14+
type Fold[T <: Tup, Seed, F[_,_]] = T match
15+
case EmptyTup => Seed
16+
case h *: t => Fold[t, F[Seed, h], F]
17+
18+
extension [T <: Tup](v: T)
19+
def fold[Seed, F[_,_]](seed: Seed)(
20+
fn: [C, Acc] => (C, Acc) => F[C, Acc]
21+
): Fold[T, Seed, F] =
22+
(v match
23+
case EmptyTup => seed
24+
case h *: t => t.fold(fn(h, seed))(fn)
25+
).asInstanceOf[Fold[T, Seed, F]]
26+
27+
extension [T <: Tup](v: T) def reversed: Tup =
28+
v.fold[EmptyTup, [C, Acc] =>> Acc match {
29+
case h *: t => C *: h *: t
30+
}](EmptyTup)(
31+
[C, Acc] => (c: C, acc: Acc) => acc match
32+
case _@(_ *: _) => c *: acc // error
33+
)
34+
35+
@main def testProperFold =
36+
val t = (1 *: '2' *: "foo" *: EmptyTup)
37+
val reversed: (String *: Char *: Int *: EmptyTup) = t.reversed // error
38+
println(reversed)
39+
40+
end Implementing_Tuples

0 commit comments

Comments
 (0)