Skip to content

Commit 90292c0

Browse files
committed
Add a root ErasedFunction class type
Helps with checking that types are `derivesFrom(ErasedFunctionClass)`. Also make sure that we use `isErasedFunctionType` in most places in place of `isErasedFunctionClass` (which is just a synthetic class check).
1 parent 664783b commit 90292c0

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
910910
val qualType = tree.qualifier.tpe
911911
hasRefinement(qualType) &&
912912
!qualType.derivesFrom(defn.PolyFunctionClass) &&
913-
!defn.isErasedFunctionClass(qualType.typeSymbol)
913+
!defn.isErasedFunctionType(qualType)
914914
}
915915
def loop(tree: Tree): Boolean = tree match
916916
case TypeApply(fun, _) =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extends tpd.TreeTraverser:
3535
* arguments `argTypes` and result `resType`.
3636
*/
3737
private def depFun(tycon: Type, argTypes: List[Type], resType: Type)(using Context): Type =
38-
assert(!defn.isErasedFunctionClass(tycon.classSymbol)) // TODO @natsukagami not sure how to know
38+
assert(!defn.isErasedFunctionType(tycon)) // TODO @natsukagami not sure how to know
3939
// erased parameter info here.
4040
MethodType.companion(
4141
isContextual = defn.isContextFunctionClass(tycon.classSymbol),

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ class Definitions {
147147
isImplicit = false,
148148
isErased = List())
149149
decls.enter(newMethod(cls, nme.apply, methodType(argParamRefs, resParamRef), Deferred))
150+
val parent = if name.isErasedFunction then List(ErasedFunctionType) else Nil
150151
denot.info =
151-
ClassInfo(ScalaPackageClass.thisType, cls, ObjectType :: Nil, decls)
152+
ClassInfo(ScalaPackageClass.thisType, cls, ObjectType :: parent, decls)
152153
}
153154
}
154155
if impure then
@@ -1445,6 +1446,9 @@ class Definitions {
14451446
lazy val PolyFunctionClass = requiredClass("scala.PolyFunction")
14461447
def PolyFunctionType = PolyFunctionClass.typeRef
14471448

1449+
lazy val ErasedFunctionClass = requiredClass("scala.ErasedFunction")
1450+
def ErasedFunctionType = ErasedFunctionClass.typeRef
1451+
14481452
/** If `cls` is a class in the scala package, its name, otherwise EmptyTypeName */
14491453
def scalaClassName(cls: Symbol)(using Context): TypeName = cls.denot match
14501454
case clsd: ClassDenotation if clsd.owner eq ScalaPackageClass =>
@@ -1804,8 +1808,7 @@ class Definitions {
18041808
else None
18051809

18061810
def isErasedFunctionType(tp: Type)(using Context): Boolean =
1807-
// false // TODO @natsukagami fix this
1808-
tp.dealias.typeSymbol.name.isErasedFunction && isFunctionType(tp)
1811+
tp.derivesFrom(defn.ErasedFunctionClass)
18091812

18101813
/** A whitelist of Scala-2 classes that are known to be pure */
18111814
def isAssuredNoInits(sym: Symbol): Boolean =
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package scala
2+
3+
/** Marker trait for erased function types.
4+
*
5+
* This trait will be refined with an `apply` method with erased parameters:
6+
* ErasedFunction { def apply[T_1, ..., T_M]([erased] x_1: P_1, ..., [erased] x_N: P_N): R }
7+
* This type will be erased to FunctionM, where M is the number of non-erased parameters.
8+
*/
9+
trait ErasedFunction

0 commit comments

Comments
 (0)