Skip to content

Commit 9363584

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 a20027f commit 9363584

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
@@ -1171,19 +1171,18 @@ class Definitions {
11711171
}
11721172
}
11731173

1174-
object RefinedFunctionOf {
1174+
object RefinedFunctionOf:
1175+
11751176
/** Matches a refined `PolyFunction`/`FunctionN[...]`/`ContextFunctionN[...]`.
11761177
* Extracts the method type type and apply info.
11771178
*/
1178-
def unapply(tpe: RefinedType)(using Context): Option[MethodOrPoly] = {
1179+
def unapply(tpe: RefinedType)(using Context): Option[MethodOrPoly] =
11791180
tpe.refinedInfo match
11801181
case mt: MethodOrPoly
1181-
if tpe.refinedName == nme.apply
1182-
&& (tpe.parent.derivesFrom(defn.PolyFunctionClass) || isFunctionNType(tpe.parent)) =>
1183-
Some(mt)
1182+
if tpe.refinedName == nme.apply && isFunctionType(tpe.parent) => Some(mt)
11841183
case _ => None
1185-
}
1186-
}
1184+
1185+
end RefinedFunctionOf
11871186

11881187
object PolyFunctionOf {
11891188

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

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

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

0 commit comments

Comments
 (0)