Skip to content

Commit d5217e6

Browse files
nicolasstuckiKordyjan
authored andcommitted
Rename isFunctionOrPoly to isFunctionType
This method checks if the type is any kind of function type: `FunctionN`, `ContextFunctionN`, `PolyFunction`, and `ErasedFunction`. [Cherry-picked d7167b0]
1 parent f967482 commit d5217e6

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class CheckCaptures extends Recheck, SymTransformer:
187187
capt.println(i"solving $t")
188188
refs.solve()
189189
traverse(parent)
190-
case t @ RefinedType(_, nme.apply, rinfo) if defn.isFunctionOrPolyType(t) =>
190+
case t @ RefinedType(_, nme.apply, rinfo) if defn.isFunctionType(t) =>
191191
traverse(rinfo)
192192
case tp: TypeVar =>
193193
case tp: TypeRef =>
@@ -769,7 +769,7 @@ class CheckCaptures extends Recheck, SymTransformer:
769769
case actual @ AppliedType(tycon, args) if defn.isNonRefinedFunction(actual) =>
770770
adaptFun(actual, args.init, args.last, expected, covariant, insertBox,
771771
(aargs1, ares1) => actual.derivedAppliedType(tycon, aargs1 :+ ares1))
772-
case actual @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionOrPolyType(actual) =>
772+
case actual @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionType(actual) =>
773773
// TODO Find a way to combine handling of generic and dependent function types (here and elsewhere)
774774
adaptFun(actual, rinfo.paramInfos, rinfo.resType, expected, covariant, insertBox,
775775
(aargs1, ares1) =>
@@ -779,7 +779,7 @@ class CheckCaptures extends Recheck, SymTransformer:
779779
adaptFun(actual, actual.paramInfos, actual.resType, expected, covariant, insertBox,
780780
(aargs1, ares1) =>
781781
actual.derivedLambdaType(paramInfos = aargs1, resType = ares1))
782-
case actual @ RefinedType(p, nme, rinfo: PolyType) if defn.isFunctionOrPolyType(actual) =>
782+
case actual @ RefinedType(p, nme, rinfo: PolyType) if defn.isFunctionType(actual) =>
783783
adaptTypeFun(actual, rinfo.resType, expected, covariant, insertBox,
784784
ares1 =>
785785
val rinfo1 = rinfo.derivedLambdaType(rinfo.paramNames, rinfo.paramInfos, ares1)
@@ -996,7 +996,7 @@ class CheckCaptures extends Recheck, SymTransformer:
996996
case CapturingType(parent, refs) =>
997997
healCaptureSet(refs)
998998
traverse(parent)
999-
case tp @ RefinedType(parent, rname, rinfo: MethodType) if defn.isFunctionOrPolyType(tp) =>
999+
case tp @ RefinedType(parent, rname, rinfo: MethodType) if defn.isFunctionType(tp) =>
10001000
traverse(rinfo)
10011001
case tp: TermLambda =>
10021002
val saved = allowed

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

Lines changed: 3 additions & 3 deletions
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: MethodType) if defn.isFunctionOrPolyType(tp1) =>
57+
case tp1 @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionType(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: MethodType) if defn.isFunctionOrPolyType(tp) =>
234+
case tp @ RefinedType(core, rname, rinfo: MethodType) if defn.isFunctionType(tp) =>
235235
val rinfo1 = apply(rinfo)
236236
if rinfo1 ne rinfo then rinfo1.toFunctionType(isJava = false, alwaysDependent = true)
237237
else tp
@@ -329,7 +329,7 @@ extends tpd.TreeTraverser:
329329
args.last, CaptureSet.empty, currentCs ++ outerCs)
330330
tp.derivedAppliedType(tycon1, args1 :+ resType1)
331331
tp1.capturing(outerCs)
332-
case tp @ RefinedType(parent, nme.apply, rinfo: MethodType) if defn.isFunctionOrPolyType(tp) =>
332+
case tp @ RefinedType(parent, nme.apply, rinfo: MethodType) if defn.isFunctionType(tp) =>
333333
propagateDepFunctionResult(mapOver(tp), currentCs ++ outerCs)
334334
.capturing(outerCs)
335335
case _ =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ class Definitions {
17171717
* - ErasedFunction
17181718
* - PolyFunction
17191719
*/
1720-
def isFunctionOrPolyType(tp: Type)(using Context): Boolean =
1720+
def isFunctionType(tp: Type)(using Context): Boolean =
17211721
isFunctionNType(tp) || isRefinedFunctionType(tp)
17221722

17231723
private def withSpecMethods(cls: ClassSymbol, bases: List[Name], paramTypes: Set[TypeRef]) =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4056,7 +4056,7 @@ object Types {
40564056
tp.derivedAppliedType(tycon, addInto(args.head) :: Nil)
40574057
case tp @ AppliedType(tycon, args) if defn.isFunctionNType(tp) =>
40584058
wrapConvertible(tp.derivedAppliedType(tycon, args.init :+ addInto(args.last)))
4059-
case tp @ RefinedType(parent, rname, rinfo) if defn.isFunctionOrPolyType(tp) =>
4059+
case tp @ RefinedType(parent, rname, rinfo) if defn.isFunctionType(tp) =>
40604060
wrapConvertible(tp.derivedRefinedType(parent, rname, addInto(rinfo)))
40614061
case tp: MethodOrPoly =>
40624062
tp.derivedLambdaType(resType = addInto(tp.resType))

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
266266
if !printDebug && appliedText(tp.asInstanceOf[HKLambda].resType).isEmpty =>
267267
// don't eta contract if the application would be printed specially
268268
toText(tycon)
269-
case tp: RefinedType if defn.isFunctionOrPolyType(tp) && !printDebug =>
269+
case tp: RefinedType if defn.isFunctionType(tp) && !printDebug =>
270270
toTextMethodAsFunction(tp.refinedInfo,
271271
isPure = Feature.pureFunsEnabled && !tp.typeSymbol.name.isImpureFunction)
272272
case tp: TypeRef =>
@@ -763,7 +763,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
763763
override protected def toTextCapturing(tp: Type, refsText: Text, boxText: Text): Text = tp match
764764
case tp: AppliedType if defn.isFunctionSymbol(tp.typeSymbol) && !printDebug =>
765765
boxText ~ toTextFunction(tp, refsText)
766-
case tp: RefinedType if defn.isFunctionOrPolyType(tp) && !printDebug =>
766+
case tp: RefinedType if defn.isFunctionType(tp) && !printDebug =>
767767
boxText ~ toTextMethodAsFunction(tp.refinedInfo, isPure = !tp.typeSymbol.name.isImpureFunction, refsText)
768768
case _ =>
769769
super.toTextCapturing(tp, refsText, boxText)

0 commit comments

Comments
 (0)