Skip to content

Commit

Permalink
Fix scala#11318: properly detect enclosing extension methods from a p…
Browse files Browse the repository at this point in the history
…olyfunction.
  • Loading branch information
anatoliykmetyuk committed Mar 24, 2021
1 parent 07d8ff8 commit fab6d3c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,9 @@ object SymDenotations {
if (cls.effectiveName == name || !cls.exists) cls else cls.owner.enclosingClassNamed(name)
}

final def isPolyFunction(using Context): Boolean =
this.asInstanceOf[ClassDenotation].parentSyms.contains(defn.PolyFunctionClass)

/** The closest enclosing method containing this definition.
* A local dummy owner is mapped to the primary constructor of the class.
*/
Expand All @@ -1144,7 +1147,7 @@ object SymDenotations {
*/
final def enclosingExtensionMethod(using Context): Symbol =
if this.is(ExtensionMethod) then symbol
else if this.isClass then NoSymbol
else if this.isClass && !this.isPolyFunction then NoSymbol
else if this.exists then owner.enclosingExtensionMethod
else NoSymbol

Expand Down
4 changes: 4 additions & 0 deletions tests/pos/i11318a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extension(a: Int)
def b: Int = ???
def h: Unit =
[A] => (r: Int) => b
13 changes: 13 additions & 0 deletions tests/pos/i11318b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type FunctionK[A[_], B[_]] = [Z] => A[Z] => B[Z]
type ~>:[A[_], B[_]] = FunctionK[A, B]

trait RepresentableK[F[_[_], _]]:
type RepresentationK[_]

def tabulateK[A[_], C](f: RepresentationK ~>: A): F[A, C]

extension[A[_], C](fa: F[A, C])
def indexK: RepresentationK ~>: A

def mapK[B[_]] (f: A ~>: B): F[B, C] =
tabulateK([Z] => (r: RepresentationK[Z]) => f(indexK(r)))

0 comments on commit fab6d3c

Please sign in to comment.