Skip to content

Commit 1eedc1c

Browse files
committed
Fix toFunctionType to handle erased function types
1 parent 8a202e5 commit 1eedc1c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,7 @@ class Definitions {
14751475
def PolyFunctionType = PolyFunctionClass.typeRef
14761476

14771477
lazy val ErasedFunctionClass = requiredClass("scala.runtime.ErasedFunction")
1478+
def ErasedFunctionType = ErasedFunctionClass.typeRef
14781479

14791480
/** If `cls` is a class in the scala package, its name, otherwise EmptyTypeName */
14801481
def scalaClassName(cls: Symbol)(using Context): TypeName = cls.denot match

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ object Types {
18751875
* @param alwaysDependent if true, always create a dependent function type.
18761876
*/
18771877
def toFunctionType(isJava: Boolean, dropLast: Int = 0, alwaysDependent: Boolean = false)(using Context): Type = this match {
1878-
case mt: MethodType if !mt.isParamDependent =>
1878+
case mt: MethodType if !mt.isParamDependent && !mt.hasErasedParams =>
18791879
val formals1 = if (dropLast == 0) mt.paramInfos else mt.paramInfos dropRight dropLast
18801880
val isContextual = mt.isContextualMethod && !ctx.erasedTypes
18811881
val result1 = mt.nonDependentResultApprox match {
@@ -1888,6 +1888,9 @@ object Types {
18881888
if alwaysDependent || mt.isResultDependent then
18891889
RefinedType(funType, nme.apply, mt)
18901890
else funType
1891+
case mt: MethodType if !mt.isParamDependent =>
1892+
assert(mt.hasErasedParams)
1893+
RefinedType(defn.ErasedFunctionType, nme.apply, mt)
18911894
case poly @ PolyType(_, mt: MethodType) if !mt.isParamDependent =>
18921895
RefinedType(defn.PolyFunctionType, nme.apply, poly)
18931896
}

0 commit comments

Comments
 (0)