Skip to content

Commit fab6d3c

Browse files
Fix #11318: properly detect enclosing extension methods from a polyfunction.
1 parent 07d8ff8 commit fab6d3c

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,9 @@ object SymDenotations {
11301130
if (cls.effectiveName == name || !cls.exists) cls else cls.owner.enclosingClassNamed(name)
11311131
}
11321132

1133+
final def isPolyFunction(using Context): Boolean =
1134+
this.asInstanceOf[ClassDenotation].parentSyms.contains(defn.PolyFunctionClass)
1135+
11331136
/** The closest enclosing method containing this definition.
11341137
* A local dummy owner is mapped to the primary constructor of the class.
11351138
*/
@@ -1144,7 +1147,7 @@ object SymDenotations {
11441147
*/
11451148
final def enclosingExtensionMethod(using Context): Symbol =
11461149
if this.is(ExtensionMethod) then symbol
1147-
else if this.isClass then NoSymbol
1150+
else if this.isClass && !this.isPolyFunction then NoSymbol
11481151
else if this.exists then owner.enclosingExtensionMethod
11491152
else NoSymbol
11501153

tests/pos/i11318a.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extension(a: Int)
2+
def b: Int = ???
3+
def h: Unit =
4+
[A] => (r: Int) => b

tests/pos/i11318b.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
type FunctionK[A[_], B[_]] = [Z] => A[Z] => B[Z]
2+
type ~>:[A[_], B[_]] = FunctionK[A, B]
3+
4+
trait RepresentableK[F[_[_], _]]:
5+
type RepresentationK[_]
6+
7+
def tabulateK[A[_], C](f: RepresentationK ~>: A): F[A, C]
8+
9+
extension[A[_], C](fa: F[A, C])
10+
def indexK: RepresentationK ~>: A
11+
12+
def mapK[B[_]] (f: A ~>: B): F[B, C] =
13+
tabulateK([Z] => (r: RepresentationK[Z]) => f(indexK(r)))

0 commit comments

Comments
 (0)