Skip to content

Commit f967482

Browse files
committed
Rename isFunctionType to isFunctionNType
This way we are explicit on the fact that this methods does not cover `PolyFunction` and `ErasedFunction`. [Cherry-picked c03d69f][modified]
1 parent 5aadde8 commit f967482

File tree

11 files changed

+27
-26
lines changed

11 files changed

+27
-26
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ class CheckCaptures extends Recheck, SymTransformer:
638638
case expected @ CapturingType(eparent, refs) =>
639639
CapturingType(recur(eparent), refs, boxed = expected.isBoxed)
640640
case expected @ defn.FunctionOf(args, resultType, isContextual)
641-
if defn.isNonRefinedFunction(expected) && defn.isFunctionType(actual) && !defn.isNonRefinedFunction(actual) =>
641+
if defn.isNonRefinedFunction(expected) && defn.isFunctionNType(actual) && !defn.isNonRefinedFunction(actual) =>
642642
val expected1 = toDepFun(args, resultType, isContextual)
643643
expected1
644644
case _ =>
@@ -707,7 +707,7 @@ class CheckCaptures extends Recheck, SymTransformer:
707707
val (eargs, eres) = expected.dealias.stripCapturing match
708708
case defn.FunctionOf(eargs, eres, _) => (eargs, eres)
709709
case expected: MethodType => (expected.paramInfos, expected.resType)
710-
case expected @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionType(expected) => (rinfo.paramInfos, rinfo.resType)
710+
case expected @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionNType(expected) => (rinfo.paramInfos, rinfo.resType)
711711
case _ => (aargs.map(_ => WildcardType), WildcardType)
712712
val aargs1 = aargs.zipWithConserve(eargs) { (aarg, earg) => adapt(aarg, earg, !covariant) }
713713
val ares1 = adapt(ares, eres, covariant)

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,21 +1700,25 @@ class Definitions {
17001700
* - scala.FunctionN
17011701
* - scala.ContextFunctionN
17021702
*/
1703-
def isFunctionType(tp: Type)(using Context): Boolean =
1703+
def isFunctionNType(tp: Type)(using Context): Boolean =
17041704
isNonRefinedFunction(tp.dropDependentRefinement)
17051705

17061706
/** Is `tp` a specialized, refined function type? Either an `ErasedFunction` or a `PolyFunction`. */
17071707
def isRefinedFunctionType(tp: Type)(using Context): Boolean =
17081708
tp.derivesFrom(defn.PolyFunctionClass) || isErasedFunctionType(tp)
17091709

1710+
/** Is `tp` a specialized, refined function type? Either an `ErasedFunction`. */
1711+
def isErasedFunctionType(tp: Type)(using Context): Boolean =
1712+
tp.derivesFrom(defn.ErasedFunctionClass)
1713+
17101714
/** Returns whether `tp` is an instance or a refined instance of:
17111715
* - scala.FunctionN
17121716
* - scala.ContextFunctionN
17131717
* - ErasedFunction
17141718
* - PolyFunction
17151719
*/
17161720
def isFunctionOrPolyType(tp: Type)(using Context): Boolean =
1717-
isFunctionType(tp) || isRefinedFunctionType(tp)
1721+
isFunctionNType(tp) || isRefinedFunctionType(tp)
17181722

17191723
private def withSpecMethods(cls: ClassSymbol, bases: List[Name], paramTypes: Set[TypeRef]) =
17201724
for base <- bases; tp <- paramTypes do
@@ -1818,7 +1822,7 @@ class Definitions {
18181822
case tp1 @ RefinedType(parent, nme.apply, mt: MethodType) if isErasedFunctionType(parent) && mt.isContextualMethod =>
18191823
tp1
18201824
case tp1 =>
1821-
if tp1.typeSymbol.name.isContextFunction && isFunctionType(tp1) then tp1
1825+
if tp1.typeSymbol.name.isContextFunction && isFunctionNType(tp1) then tp1
18221826
else NoType
18231827

18241828
/** Is `tp` an context function type? */
@@ -1846,13 +1850,10 @@ class Definitions {
18461850
/* Returns a list of erased booleans marking whether parameters are erased, for a function type. */
18471851
def erasedFunctionParameters(tp: Type)(using Context): List[Boolean] = tp.dealias match {
18481852
case RefinedType(parent, nme.apply, mt: MethodType) => mt.erasedParams
1849-
case tp if isFunctionType(tp) => List.fill(functionArity(tp)) { false }
1853+
case tp if isFunctionNType(tp) => List.fill(functionArity(tp)) { false }
18501854
case _ => Nil
18511855
}
18521856

1853-
def isErasedFunctionType(tp: Type)(using Context): Boolean =
1854-
tp.derivesFrom(defn.ErasedFunctionClass)
1855-
18561857
/** A whitelist of Scala-2 classes that are known to be pure */
18571858
def isAssuredNoInits(sym: Symbol): Boolean =
18581859
(sym `eq` SomeClass) || isTupleClass(sym)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
658658
case _ =>
659659
isSubType(info1, info2)
660660

661-
if defn.isFunctionType(tp2) then
661+
if defn.isFunctionNType(tp2) then
662662
tp1w.widenDealias match
663663
case tp1: RefinedType =>
664664
return isSubInfo(tp1.refinedInfo, tp2.refinedInfo)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,7 @@ object Types {
27602760
final def withPrefix(prefix: Type)(using Context): Type = {
27612761
def reload(): NamedType = {
27622762
val sym =
2763-
if lastSymbol.nn.isValidInCurrentRun then lastSymbol.nn
2763+
if lastSymbol.nn.isValidInCurrentRun then lastSymbol.nn
27642764
else computeSymbol
27652765
val allowPrivate = !sym.exists || sym.is(Private)
27662766
var d = memberDenot(prefix, name, allowPrivate)
@@ -4054,7 +4054,7 @@ object Types {
40544054
def addInto(tp: Type): Type = tp match
40554055
case tp @ AppliedType(tycon, args) if tycon.typeSymbol == defn.RepeatedParamClass =>
40564056
tp.derivedAppliedType(tycon, addInto(args.head) :: Nil)
4057-
case tp @ AppliedType(tycon, args) if defn.isFunctionType(tp) =>
4057+
case tp @ AppliedType(tycon, args) if defn.isFunctionNType(tp) =>
40584058
wrapConvertible(tp.derivedAppliedType(tycon, args.init :+ addInto(args.last)))
40594059
case tp @ RefinedType(parent, rname, rinfo) if defn.isFunctionOrPolyType(tp) =>
40604060
wrapConvertible(tp.derivedRefinedType(parent, rname, addInto(rinfo)))

compiler/src/dotty/tools/dotc/transform/BetaReduce.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ object BetaReduce:
9090
recur(expr, argss)
9191
case _ => None
9292
tree match
93-
case Apply(Select(fn, nme.apply), args) if defn.isFunctionType(fn.tpe) =>
93+
case Apply(Select(fn, nme.apply), args) if defn.isFunctionNType(fn.tpe) =>
9494
recur(fn, List(args)) match
9595
case Some(reduced) =>
9696
seq(bindingsBuf.result(), reduced).withSpan(tree.span)

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ trait Applications extends Compatibility {
695695
val argtpe1 = argtpe.widen
696696

697697
def SAMargOK =
698-
defn.isFunctionType(argtpe1) && formal.match
698+
defn.isFunctionNType(argtpe1) && formal.match
699699
case SAMType(sam) => argtpe <:< sam.toFunctionType(isJava = formal.classSymbol.is(JavaDefined))
700700
case _ => false
701701

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ object Implicits:
222222
case pt: ViewProto =>
223223
viewCandidateKind(ref.widen, pt.argType, pt.resType)
224224
case _: ValueTypeOrProto =>
225-
if (defn.isFunctionType(pt)) Candidate.Value
225+
if (defn.isFunctionNType(pt)) Candidate.Value
226226
else valueTypeCandidateKind(ref.widen)
227227
case _ =>
228228
Candidate.Value
@@ -968,7 +968,7 @@ trait Implicits:
968968
/** A string indicating the formal parameter corresponding to a missing argument */
969969
def implicitParamString(paramName: TermName, methodStr: String, tree: Tree)(using Context): String =
970970
tree match {
971-
case Select(qual, nme.apply) if defn.isFunctionType(qual.tpe.widen) =>
971+
case Select(qual, nme.apply) if defn.isFunctionNType(qual.tpe.widen) =>
972972
val qt = qual.tpe.widen
973973
val qt1 = qt.dealiasKeepAnnots
974974
def addendum = if (qt1 eq qt) "" else (i"\nWhere $qt is an alias of: $qt1")

compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
106106
defn.isContextFunctionType(baseFun))
107107
val arity: Int =
108108
if defn.isErasedFunctionType(fun) then -1 // TODO support?
109-
else if defn.isFunctionType(fun) then
109+
else if defn.isFunctionNType(fun) then
110110
// TupledFunction[(...) => R, ?]
111111
fun.functionArgInfos match
112112
case funArgs :+ funRet
113113
if functionTypeEqual(fun, defn.tupleType(funArgs) :: Nil, funRet, tupled) =>
114114
// TupledFunction[(...funArgs...) => funRet, ?]
115115
funArgs.size
116116
case _ => -1
117-
else if defn.isFunctionType(tupled) then
117+
else if defn.isFunctionNType(tupled) then
118118
// TupledFunction[?, (...) => R]
119119
tupled.functionArgInfos match
120120
case tupledArgs :: funRet :: Nil =>

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16371637
case mt: MethodType =>
16381638
pt.findFunctionType match {
16391639
case pt @ SAMType(sam)
1640-
if !defn.isFunctionType(pt) && mt <:< sam =>
1640+
if !defn.isFunctionNType(pt) && mt <:< sam =>
16411641
// SAMs of the form C[?] where C is a class cannot be conversion targets.
16421642
// The resulting class `class $anon extends C[?] {...}` would be illegal,
16431643
// since type arguments to `C`'s super constructor cannot be constructed.
@@ -2871,7 +2871,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
28712871

28722872
def typedAsFunction(tree: untpd.PostfixOp, pt: Type)(using Context): Tree = {
28732873
val untpd.PostfixOp(qual, Ident(nme.WILDCARD)) = tree: @unchecked
2874-
val pt1 = if (defn.isFunctionType(pt)) pt else AnyFunctionProto
2874+
val pt1 = if (defn.isFunctionNType(pt)) pt else AnyFunctionProto
28752875
val nestedCtx = ctx.fresh.setNewTyperState()
28762876
val res = typed(qual, pt1)(using nestedCtx)
28772877
res match {
@@ -3886,7 +3886,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38863886
sym.isConstructor
38873887
|| sym.matchNullaryLoosely
38883888
|| Feature.warnOnMigration(msg, tree.srcPos, version = `3.0`)
3889-
&& {
3889+
&& {
38903890
msg.actions
38913891
.headOption
38923892
.foreach(Rewrites.applyAction)
@@ -3919,7 +3919,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39193919
// Ignore `.apply` in `m.apply(...)`; it will later be simplified in typedSelect to `m(...)`
39203920
adapt1(tree, pt1, locked)
39213921
else
3922-
if (!defn.isFunctionType(pt))
3922+
if (!defn.isFunctionNType(pt))
39233923
pt match {
39243924
case SAMType(_) if !pt.classSymbol.hasAnnotation(defn.FunctionalInterfaceAnnot) =>
39253925
report.warning(em"${tree.symbol} is eta-expanded even though $pt does not have the @FunctionalInterface annotation.", tree.srcPos)
@@ -4034,7 +4034,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
40344034

40354035
def adaptNoArgs(wtp: Type): Tree = {
40364036
val ptNorm = underlyingApplied(pt)
4037-
def functionExpected = defn.isFunctionType(ptNorm)
4037+
def functionExpected = defn.isFunctionNType(ptNorm)
40384038
def needsEta = pt.revealIgnored match
40394039
case _: SingletonType | _: FunOrPolyProto => false
40404040
case _ => true
@@ -4124,7 +4124,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
41244124
// convert function literal to SAM closure
41254125
tree match {
41264126
case closure(Nil, id @ Ident(nme.ANON_FUN), _)
4127-
if defn.isFunctionType(wtp) && !defn.isFunctionType(pt) =>
4127+
if defn.isFunctionNType(wtp) && !defn.isFunctionNType(pt) =>
41284128
pt match {
41294129
case SAMType(sam)
41304130
if wtp <:< sam.toFunctionType(isJava = pt.classSymbol.is(JavaDefined)) =>

compiler/src/dotty/tools/dotc/util/Signatures.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ object Signatures {
302302
* @param tree tree to validate
303303
*/
304304
private def isValid(tree: tpd.Tree)(using Context): Boolean =
305-
ctx.definitions.isTupleNType(tree.tpe) || ctx.definitions.isFunctionType(tree.tpe)
305+
ctx.definitions.isTupleNType(tree.tpe) || ctx.definitions.isFunctionNType(tree.tpe)
306306

307307
/**
308308
* Get unapply method result type omiting unknown types and another method calls.

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
17751775
def baseType(cls: Symbol): TypeRepr = self.baseType(cls)
17761776
def derivesFrom(cls: Symbol): Boolean = self.derivesFrom(cls)
17771777
def isFunctionType: Boolean =
1778-
dotc.core.Symbols.defn.isFunctionType(self)
1778+
dotc.core.Symbols.defn.isFunctionNType(self)
17791779
def isContextFunctionType: Boolean =
17801780
dotc.core.Symbols.defn.isContextFunctionType(self)
17811781
def isErasedFunctionType: Boolean =

0 commit comments

Comments
 (0)