Skip to content

Commit c03d69f

Browse files
committed
Rename isFunctionType to isFunctionNType
This way we are explicit on the fact that this methods does not cover `PolyFunction` and `ErasedFunction`.
1 parent d0403b6 commit c03d69f

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
@@ -1709,21 +1709,25 @@ class Definitions {
17091709
* - scala.FunctionN
17101710
* - scala.ContextFunctionN
17111711
*/
1712-
def isFunctionType(tp: Type)(using Context): Boolean =
1712+
def isFunctionNType(tp: Type)(using Context): Boolean =
17131713
isNonRefinedFunction(tp.dropDependentRefinement)
17141714

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

1719+
/** Is `tp` a specialized, refined function type? Either an `ErasedFunction`. */
1720+
def isErasedFunctionType(tp: Type)(using Context): Boolean =
1721+
tp.derivesFrom(defn.ErasedFunctionClass)
1722+
17191723
/** Returns whether `tp` is an instance or a refined instance of:
17201724
* - scala.FunctionN
17211725
* - scala.ContextFunctionN
17221726
* - ErasedFunction
17231727
* - PolyFunction
17241728
*/
17251729
def isFunctionOrPolyType(tp: Type)(using Context): Boolean =
1726-
isFunctionType(tp) || isRefinedFunctionType(tp)
1730+
isFunctionNType(tp) || isRefinedFunctionType(tp)
17271731

17281732
private def withSpecMethods(cls: ClassSymbol, bases: List[Name], paramTypes: Set[TypeRef]) =
17291733
if !ctx.settings.Yscala2Stdlib.value then
@@ -1830,7 +1834,7 @@ class Definitions {
18301834
case tp1 @ RefinedType(parent, nme.apply, mt: MethodType) if isErasedFunctionType(parent) && mt.isContextualMethod =>
18311835
tp1
18321836
case tp1 =>
1833-
if tp1.typeSymbol.name.isContextFunction && isFunctionType(tp1) then tp1
1837+
if tp1.typeSymbol.name.isContextFunction && isFunctionNType(tp1) then tp1
18341838
else NoType
18351839

18361840
/** Is `tp` an context function type? */
@@ -1858,13 +1862,10 @@ class Definitions {
18581862
/* Returns a list of erased booleans marking whether parameters are erased, for a function type. */
18591863
def erasedFunctionParameters(tp: Type)(using Context): List[Boolean] = tp.dealias match {
18601864
case RefinedType(parent, nme.apply, mt: MethodType) => mt.erasedParams
1861-
case tp if isFunctionType(tp) => List.fill(functionArity(tp)) { false }
1865+
case tp if isFunctionNType(tp) => List.fill(functionArity(tp)) { false }
18621866
case _ => Nil
18631867
}
18641868

1865-
def isErasedFunctionType(tp: Type)(using Context): Boolean =
1866-
tp.derivesFrom(defn.ErasedFunctionClass)
1867-
18681869
/** A whitelist of Scala-2 classes that are known to be pure */
18691870
def isAssuredNoInits(sym: Symbol): Boolean =
18701871
(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
@@ -665,7 +665,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
665665
case _ =>
666666
isSubType(info1, info2)
667667

668-
if defn.isFunctionType(tp2) then
668+
if defn.isFunctionNType(tp2) then
669669
tp1w.widenDealias match
670670
case tp1: RefinedType =>
671671
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
@@ -708,7 +708,7 @@ object Types {
708708
}
709709
findMember(name, pre, required, excluded)
710710
}
711-
711+
712712
/** The implicit members with given name. If there are none and the denotation
713713
* contains private members, also look for shadowed non-private implicits.
714714
*/
@@ -4071,7 +4071,7 @@ object Types {
40714071
def addInto(tp: Type): Type = tp match
40724072
case tp @ AppliedType(tycon, args) if tycon.typeSymbol == defn.RepeatedParamClass =>
40734073
tp.derivedAppliedType(tycon, addInto(args.head) :: Nil)
4074-
case tp @ AppliedType(tycon, args) if defn.isFunctionType(tp) =>
4074+
case tp @ AppliedType(tycon, args) if defn.isFunctionNType(tp) =>
40754075
wrapConvertible(tp.derivedAppliedType(tycon, args.init :+ addInto(args.last)))
40764076
case tp @ RefinedType(parent, rname, rinfo) if defn.isFunctionOrPolyType(tp) =>
40774077
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
@@ -220,7 +220,7 @@ object Implicits:
220220
case pt: ViewProto =>
221221
viewCandidateKind(ref.widen, pt.argType, pt.resType)
222222
case _: ValueTypeOrProto =>
223-
if (defn.isFunctionType(pt)) Candidate.Value
223+
if (defn.isFunctionNType(pt)) Candidate.Value
224224
else valueTypeCandidateKind(ref.widen)
225225
case _ =>
226226
Candidate.Value
@@ -973,7 +973,7 @@ trait Implicits:
973973
/** A string indicating the formal parameter corresponding to a missing argument */
974974
def implicitParamString(paramName: TermName, methodStr: String, tree: Tree)(using Context): String =
975975
tree match {
976-
case Select(qual, nme.apply) if defn.isFunctionType(qual.tpe.widen) =>
976+
case Select(qual, nme.apply) if defn.isFunctionNType(qual.tpe.widen) =>
977977
val qt = qual.tpe.widen
978978
val qt1 = qt.dealiasKeepAnnots
979979
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
@@ -1685,7 +1685,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16851685
case mt: MethodType =>
16861686
pt.findFunctionType match {
16871687
case pt @ SAMType(sam)
1688-
if !defn.isFunctionType(pt) && mt <:< sam =>
1688+
if !defn.isFunctionNType(pt) && mt <:< sam =>
16891689
// SAMs of the form C[?] where C is a class cannot be conversion targets.
16901690
// The resulting class `class $anon extends C[?] {...}` would be illegal,
16911691
// since type arguments to `C`'s super constructor cannot be constructed.
@@ -2935,7 +2935,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
29352935

29362936
def typedAsFunction(tree: untpd.PostfixOp, pt: Type)(using Context): Tree = {
29372937
val untpd.PostfixOp(qual, Ident(nme.WILDCARD)) = tree: @unchecked
2938-
val pt1 = if (defn.isFunctionType(pt)) pt else AnyFunctionProto
2938+
val pt1 = if (defn.isFunctionNType(pt)) pt else AnyFunctionProto
29392939
val nestedCtx = ctx.fresh.setNewTyperState()
29402940
val res = typed(qual, pt1)(using nestedCtx)
29412941
res match {
@@ -3957,7 +3957,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39573957
sym.isConstructor
39583958
|| sym.matchNullaryLoosely
39593959
|| Feature.warnOnMigration(msg, tree.srcPos, version = `3.0`)
3960-
&& {
3960+
&& {
39613961
msg.actions
39623962
.headOption
39633963
.foreach(Rewrites.applyAction)
@@ -3990,7 +3990,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39903990
// Ignore `.apply` in `m.apply(...)`; it will later be simplified in typedSelect to `m(...)`
39913991
adapt1(tree, pt1, locked)
39923992
else
3993-
if (!defn.isFunctionType(pt))
3993+
if (!defn.isFunctionNType(pt))
39943994
pt match {
39953995
case SAMType(_) if !pt.classSymbol.hasAnnotation(defn.FunctionalInterfaceAnnot) =>
39963996
report.warning(em"${tree.symbol} is eta-expanded even though $pt does not have the @FunctionalInterface annotation.", tree.srcPos)
@@ -4108,7 +4108,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
41084108

41094109
def adaptNoArgs(wtp: Type): Tree = {
41104110
val ptNorm = underlyingApplied(pt)
4111-
def functionExpected = defn.isFunctionType(ptNorm)
4111+
def functionExpected = defn.isFunctionNType(ptNorm)
41124112
def needsEta = pt.revealIgnored match
41134113
case _: SingletonType | _: FunOrPolyProto => false
41144114
case _ => true
@@ -4198,7 +4198,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
41984198
// convert function literal to SAM closure
41994199
tree match {
42004200
case closure(Nil, id @ Ident(nme.ANON_FUN), _)
4201-
if defn.isFunctionType(wtp) && !defn.isFunctionType(pt) =>
4201+
if defn.isFunctionNType(wtp) && !defn.isFunctionNType(pt) =>
42024202
pt match {
42034203
case SAMType(sam)
42044204
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
@@ -1784,7 +1784,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
17841784
def baseType(cls: Symbol): TypeRepr = self.baseType(cls)
17851785
def derivesFrom(cls: Symbol): Boolean = self.derivesFrom(cls)
17861786
def isFunctionType: Boolean =
1787-
dotc.core.Symbols.defn.isFunctionType(self)
1787+
dotc.core.Symbols.defn.isFunctionNType(self)
17881788
def isContextFunctionType: Boolean =
17891789
dotc.core.Symbols.defn.isContextFunctionType(self)
17901790
def isErasedFunctionType: Boolean =

0 commit comments

Comments
 (0)