Skip to content

Commit ef19bca

Browse files
committed
Make isFunctionType no longer recognize ErasedFunction refinements
1 parent a592bfb commit ef19bca

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ class CheckCaptures extends Recheck, SymTransformer:
754754
val (parent1, leaked) = adaptFun(parent, args.init, args.last, expected, covariant, insertBox,
755755
(aargs1, ares1) => actual.derivedAppliedType(tycon, aargs1 :+ ares1))
756756
(parent1, leaked ++ cs)
757-
case actual @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionType(actual) =>
757+
case actual @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionOrPolyType(actual) =>
758758
// TODO Find a way to combine handling of generic and dependent function types (here and elsewhere)
759759
val (parent1, leaked) = adaptFun(parent, rinfo.paramInfos, rinfo.resType, expected, covariant, insertBox,
760760
(aargs1, ares1) =>
@@ -973,7 +973,7 @@ class CheckCaptures extends Recheck, SymTransformer:
973973
case CapturingType(parent, refs) =>
974974
healCaptureSet(refs)
975975
traverse(parent)
976-
case tp @ RefinedType(parent, rname, rinfo: MethodType) if defn.isFunctionType(tp) =>
976+
case tp @ RefinedType(parent, rname, rinfo: MethodType) if defn.isFunctionOrPolyType(tp) =>
977977
traverse(rinfo)
978978
case tp: TermLambda =>
979979
val saved = allowed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extends tpd.TreeTraverser:
5454
val boxedRes = recur(res)
5555
if boxedRes eq res then tp
5656
else tp1.derivedAppliedType(tycon, args.init :+ boxedRes)
57-
case tp1 @ RefinedType(_, _, rinfo) if defn.isFunctionType(tp1) =>
57+
case tp1 @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionOrPolyType(tp1) =>
5858
val boxedRinfo = recur(rinfo)
5959
if boxedRinfo eq rinfo then tp
6060
else boxedRinfo.toFunctionType(isJava = false, alwaysDependent = true)
@@ -231,7 +231,7 @@ extends tpd.TreeTraverser:
231231
tp.derivedAppliedType(tycon1, args1 :+ res1)
232232
else
233233
tp.derivedAppliedType(tycon1, args.mapConserve(arg => this(arg)))
234-
case tp @ RefinedType(core, rname, rinfo) if defn.isFunctionType(tp) =>
234+
case tp @ RefinedType(core, rname, rinfo: MethodType) if defn.isFunctionOrPolyType(tp) =>
235235
val rinfo1 = apply(rinfo)
236236
if rinfo1 ne rinfo then rinfo1.toFunctionType(isJava = false, alwaysDependent = true)
237237
else tp
@@ -327,7 +327,7 @@ extends tpd.TreeTraverser:
327327
args.last, CaptureSet.empty, currentCs ++ outerCs)
328328
tp.derivedAppliedType(tycon1, args1 :+ resType1)
329329
tp1.capturing(outerCs)
330-
case tp @ RefinedType(parent, nme.apply, rinfo: MethodType) if defn.isFunctionType(tp) =>
330+
case tp @ RefinedType(parent, nme.apply, rinfo: MethodType) if defn.isFunctionOrPolyType(tp) =>
331331
propagateDepFunctionResult(mapOver(tp), currentCs ++ outerCs)
332332
.capturing(outerCs)
333333
case _ =>

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1671,10 +1671,14 @@ class Definitions {
16711671

16721672
/** Is `tp` a representation of a (possibly dependent) function type or an alias of such? */
16731673
def isFunctionType(tp: Type)(using Context): Boolean =
1674-
isNonRefinedFunction(tp.dropDependentRefinement) || isErasedFunctionType(tp)
1674+
isNonRefinedFunction(tp.dropDependentRefinement)
1675+
1676+
/** Is `tp` a specialized, refined function type? Either an `ErasedFunction` or a `PolyFunction`. */
1677+
def isRefinedFunctionType(tp: Type)(using Context): Boolean =
1678+
(tp.typeSymbol eq defn.PolyFunctionClass) || isErasedFunctionType(tp)
16751679

16761680
def isFunctionOrPolyType(tp: Type)(using Context): Boolean =
1677-
isFunctionType(tp) || (tp.typeSymbol eq defn.PolyFunctionClass)
1681+
isFunctionType(tp) || isRefinedFunctionType(tp)
16781682

16791683
private def withSpecMethods(cls: ClassSymbol, bases: List[Name], paramTypes: Set[TypeRef]) =
16801684
for base <- bases; tp <- paramTypes do

0 commit comments

Comments
 (0)