Skip to content

Commit 6533594

Browse files
committed
Avoid forming intersections for dependent function types
Avoid forming an intersection when selecting the apply method of a dependent function type.
1 parent 31f837e commit 6533594

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,19 +1173,18 @@ class Definitions {
11731173
}
11741174
}
11751175

1176-
object RefinedFunctionOf {
1176+
object RefinedFunctionOf:
1177+
11771178
/** Matches a refined `PolyFunction`/`FunctionN[...]`/`ContextFunctionN[...]`.
11781179
* Extracts the method type type and apply info.
11791180
*/
1180-
def unapply(tpe: RefinedType)(using Context): Option[MethodOrPoly] = {
1181+
def unapply(tpe: RefinedType)(using Context): Option[MethodOrPoly] =
11811182
tpe.refinedInfo match
11821183
case mt: MethodOrPoly
1183-
if tpe.refinedName == nme.apply
1184-
&& (tpe.parent.derivesFrom(defn.PolyFunctionClass) || isFunctionNType(tpe.parent)) =>
1185-
Some(mt)
1184+
if tpe.refinedName == nme.apply && isFunctionType(tpe.parent) => Some(mt)
11861185
case _ => None
1187-
}
1188-
}
1186+
1187+
end RefinedFunctionOf
11891188

11901189
object PolyFunctionOf {
11911190

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,9 @@ object Types extends TypeUtils {
843843
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
844844
joint match
845845
case joint: SingleDenotation
846-
if isRefinedMethod && rinfo <:< joint.info =>
846+
if isRefinedMethod
847+
&& (rinfo <:< joint.info
848+
|| name == nme.apply && defn.isFunctionType(tp.parent)) =>
847849
// use `rinfo` to keep the right parameter names for named args. See i8516.scala.
848850
joint.derivedSingleDenotation(joint.symbol, rinfo, pre, isRefinedMethod)
849851
case _ =>
@@ -6477,7 +6479,7 @@ object Types extends TypeUtils {
64776479
protected def needsRangeIfInvariant(refs: CaptureSet): Boolean = true
64786480

64796481
override def mapCapturingType(tp: Type, parent: Type, refs: CaptureSet, v: Int): Type =
6480-
if v == 0 && needsRangeIfInvariant(refs) then
6482+
if v == 0 && needsRangeIfInvariant(refs) /* && false*/ then
64816483
range(mapCapturingType(tp, parent, refs, -1), mapCapturingType(tp, parent, refs, 1))
64826484
else
64836485
super.mapCapturingType(tp, parent, refs, v)

0 commit comments

Comments
 (0)