Skip to content

Commit 3577cf1

Browse files
committed
Add ErasedFunctionOf
1 parent 6de51f6 commit 3577cf1

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ class Definitions {
11141114
FunctionType(args.length, isContextual).appliedTo(args ::: resultType :: Nil)
11151115
def unapply(ft: Type)(using Context): Option[(List[Type], Type, Boolean)] = {
11161116
ft.dealias match
1117-
case PolyOrErasedFunctionOf(mt: MethodType) =>
1117+
case ErasedFunctionOf(mt) =>
11181118
Some(mt.paramInfos, mt.resType, mt.isContextualMethod)
11191119
case _ =>
11201120
val tsym = ft.dealias.typeSymbol
@@ -1138,6 +1138,18 @@ class Definitions {
11381138
case _ => None
11391139
}
11401140

1141+
object ErasedFunctionOf {
1142+
/** Matches a refined `ErasedFunction` type and extracts the apply info.
1143+
*
1144+
* Pattern: `ErasedFunction { def apply: $mt }`
1145+
*/
1146+
def unapply(ft: Type)(using Context): Option[MethodType] = ft.dealias match
1147+
case RefinedType(parent, nme.apply, mt: MethodType)
1148+
if parent.derivesFrom(defn.ErasedFunctionClass) =>
1149+
Some(mt)
1150+
case _ => None
1151+
}
1152+
11411153
object PartialFunctionOf {
11421154
def apply(arg: Type, result: Type)(using Context): Type =
11431155
PartialFunctionClass.typeRef.appliedTo(arg :: result :: Nil)
@@ -1838,7 +1850,7 @@ class Definitions {
18381850
tp.stripTypeVar.dealias match
18391851
case tp1: TypeParamRef if ctx.typerState.constraint.contains(tp1) =>
18401852
asContextFunctionType(TypeComparer.bounds(tp1).hiBound)
1841-
case tp1 @ PolyOrErasedFunctionOf(mt: MethodType) if mt.isContextualMethod =>
1853+
case tp1 @ ErasedFunctionOf(mt) if mt.isContextualMethod =>
18421854
tp1
18431855
case tp1 =>
18441856
if tp1.typeSymbol.name.isContextFunction && isFunctionNType(tp1) then tp1
@@ -1858,7 +1870,7 @@ class Definitions {
18581870
atPhase(erasurePhase)(unapply(tp))
18591871
else
18601872
asContextFunctionType(tp) match
1861-
case PolyOrErasedFunctionOf(mt: MethodType) =>
1873+
case ErasedFunctionOf(mt) =>
18621874
Some((mt.paramInfos, mt.resType, mt.erasedParams))
18631875
case tp1 if tp1.exists =>
18641876
val args = tp1.functionArgInfos
@@ -1868,7 +1880,7 @@ class Definitions {
18681880

18691881
/* Returns a list of erased booleans marking whether parameters are erased, for a function type. */
18701882
def erasedFunctionParameters(tp: Type)(using Context): List[Boolean] = tp.dealias match {
1871-
case RefinedType(parent, nme.apply, mt: MethodType) => mt.erasedParams
1883+
case ErasedFunctionOf(mt) => mt.erasedParams
18721884
case tp if isFunctionNType(tp) => List.fill(functionArity(tp)) { false }
18731885
case _ => Nil
18741886
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +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 defn.PolyOrErasedFunctionOf(mt: MethodType) => (mt.paramInfos :+ mt.resultType)
512+
case defn.ErasedFunctionOf(mt) => (mt.paramInfos :+ mt.resultType)
513513
case _ => self.dropDependentRefinement.dealias.argInfos
514514

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
13281328
case RefinedType(parent, nme.apply, mt @ MethodTpe(_, formals, restpe))
13291329
if defn.isNonRefinedFunction(parent) && formals.length == defaultArity =>
13301330
(formals, untpd.InLambdaTypeTree(isResult = true, (_, syms) => restpe.substParams(mt, syms.map(_.termRef))))
1331-
case defn.PolyOrErasedFunctionOf(mt @ MethodTpe(_, formals, restpe)) if formals.length == defaultArity =>
1331+
case defn.ErasedFunctionOf(mt @ MethodTpe(_, formals, restpe)) if formals.length == defaultArity =>
13321332
(formals, untpd.InLambdaTypeTree(isResult = true, (_, syms) => restpe.substParams(mt, syms.map(_.termRef))))
13331333
case pt1 @ SAMType(mt @ MethodTpe(_, formals, _)) =>
13341334
val restpe = mt.resultType match

0 commit comments

Comments
 (0)