Skip to content

Commit 63fa75a

Browse files
committed
More consistent use of is{Refined,Poly,Erased}isFunctionType
1 parent d7167b0 commit 63fa75a

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,9 +1714,13 @@ class Definitions {
17141714

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

1719-
/** Is `tp` a specialized, refined function type? Either an `ErasedFunction`. */
1719+
/** Is `tp` a specialized, refined `PolyFunction` type? */
1720+
def isPolyFunctionType(tp: Type)(using Context): Boolean =
1721+
tp.derivesFrom(defn.PolyFunctionClass)
1722+
1723+
/** Is `tp` a specialized, refined `ErasedFunction` type? */
17201724
def isErasedFunctionType(tp: Type)(using Context): Boolean =
17211725
tp.derivesFrom(defn.ErasedFunctionClass)
17221726

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,7 @@ class TypeApplications(val self: Type) extends AnyVal {
509509
* Handles `ErasedFunction`s and poly functions gracefully.
510510
*/
511511
final def functionArgInfos(using Context): List[Type] = self.dealias match
512-
case RefinedType(parent, nme.apply, mt: MethodType) if defn.isErasedFunctionType(parent) => (mt.paramInfos :+ mt.resultType)
513-
case RefinedType(parent, nme.apply, mt: MethodType) if parent.typeSymbol eq defn.PolyFunctionClass => (mt.paramInfos :+ mt.resultType)
512+
case RefinedType(parent, nme.apply, mt: MethodType) if defn.isRefinedFunctionType(parent) => (mt.paramInfos :+ mt.resultType)
514513
case _ => self.dropDependentRefinement.dealias.argInfos
515514

516515
/** Argument types where existential types in arguments are disallowed */

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ import TypeErasure._
592592
*/
593593
class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConstructor: Boolean, isSymbol: Boolean, inSigName: Boolean) {
594594

595-
/** The erasure |T| of a type T.
595+
/** The erasure |T| of a type T.
596596
*
597597
* If computing the erasure of T requires erasing a WildcardType or an
598598
* uninstantiated type variable, then an exception signaling an internal
@@ -659,7 +659,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
659659
else SuperType(eThis, eSuper)
660660
case ExprType(rt) =>
661661
defn.FunctionType(0)
662-
case RefinedType(parent, nme.apply, refinedInfo) if parent.typeSymbol eq defn.PolyFunctionClass =>
662+
case RefinedType(parent, nme.apply, refinedInfo) if defn.isPolyFunctionType(parent) =>
663663
erasePolyFunctionApply(refinedInfo)
664664
case RefinedType(parent, nme.apply, refinedInfo: MethodType) if defn.isErasedFunctionType(parent) =>
665665
eraseErasedFunctionApply(refinedInfo)
@@ -943,13 +943,11 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
943943
sigName(defn.FunctionOf(Nil, rt))
944944
case tp: TypeVar if !tp.isInstantiated =>
945945
tpnme.Uninstantiated
946-
case tp @ RefinedType(parent, nme.apply, _) if parent.typeSymbol eq defn.PolyFunctionClass =>
946+
case tp @ RefinedType(parent, nme.apply, _) if defn.isRefinedFunctionType(parent) =>
947947
// we need this case rather than falling through to the default
948948
// because RefinedTypes <: TypeProxy and it would be caught by
949949
// the case immediately below
950950
sigName(this(tp))
951-
case tp @ RefinedType(parent, nme.apply, refinedInfo) if defn.isErasedFunctionType(parent) =>
952-
sigName(this(tp))
953951
case tp: TypeProxy =>
954952
sigName(tp.underlying)
955953
case tp: WildcardType =>

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,12 @@ object TreeChecker {
446446
assert(tree.isTerm || !ctx.isAfterTyper, tree.show + " at " + ctx.phase)
447447
val tpe = tree.typeOpt
448448

449-
// Polymorphic apply methods stay structural until Erasure
450-
val isPolyFunctionApply = (tree.name eq nme.apply) && tree.qualifier.typeOpt.derivesFrom(defn.PolyFunctionClass)
451-
// Erased functions stay structural until Erasure
452-
val isErasedFunctionApply = (tree.name eq nme.apply) && tree.qualifier.typeOpt.derivesFrom(defn.ErasedFunctionClass)
449+
// PolyFunction and ErasedFunction apply methods stay structural until Erasure
450+
val isRefinedFunctionApply = (tree.name eq nme.apply) && defn.isRefinedFunctionType(tree.qualifier.typeOpt)
453451
// Outer selects are pickled specially so don't require a symbol
454452
val isOuterSelect = tree.name.is(OuterSelectName)
455453
val isPrimitiveArrayOp = ctx.erasedTypes && nme.isPrimitiveName(tree.name)
456-
if !(tree.isType || isPolyFunctionApply || isErasedFunctionApply || isOuterSelect || isPrimitiveArrayOp) then
454+
if !(tree.isType || isRefinedFunctionApply || isOuterSelect || isPrimitiveArrayOp) then
457455
val denot = tree.denot
458456
assert(denot.exists, i"Selection $tree with type $tpe does not have a denotation")
459457
assert(denot.symbol.exists, i"Denotation $denot of selection $tree with type $tpe does not have a symbol, qualifier type = ${tree.qualifier.typeOpt}")

0 commit comments

Comments
 (0)