Skip to content

Commit 0365d9f

Browse files
Backport "Improve defn.PolyFunctionOf extractor" to LTS (#20663)
Backports #18442 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 2e9c90f + 3dbb053 commit 0365d9f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ class CheckCaptures extends Recheck, SymTransformer:
732732

733733
try
734734
val eres = expected.dealias.stripCapturing match
735-
case RefinedType(_, _, rinfo: PolyType) => rinfo.resType
735+
case defn.PolyFunctionOf(rinfo: PolyType) => rinfo.resType
736736
case expected: PolyType => expected.resType
737737
case _ => WildcardType
738738

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,11 +1151,12 @@ class Definitions {
11511151
*
11521152
* Pattern: `PolyFunction { def apply: $pt }`
11531153
*/
1154-
def unapply(ft: Type)(using Context): Option[PolyType] = ft.dealias match
1155-
case RefinedType(parent, nme.apply, pt: PolyType)
1156-
if parent.derivesFrom(defn.PolyFunctionClass) =>
1157-
Some(pt)
1158-
case _ => None
1154+
def unapply(tpe: RefinedType)(using Context): Option[MethodOrPoly] =
1155+
tpe.refinedInfo match
1156+
case mt: MethodOrPoly
1157+
if tpe.refinedName == nme.apply && tpe.parent.derivesFrom(defn.PolyFunctionClass) =>
1158+
Some(mt)
1159+
case _ => None
11591160
}
11601161

11611162
object ErasedFunctionOf {

0 commit comments

Comments
 (0)