Skip to content

Commit 939d06f

Browse files
committed
Improve defn.PolyFunctionOf extractor
* Only match `RefinedType` representing the `PolyFunction`. This will allow us to use `derivedRefinedType` on the function type. * Only match the refinement if it is a `MethodOrPoly`. `ExprType` is not a valid `PolyFunction` refinement. * Remove `dealias` in `PolyFunctionOf` extractor. There was only one case where this was necessary and it added unnecessary overhead. [Cherry-picked 60b2d02][modified]
1 parent ffedd75 commit 939d06f

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)