Skip to content

Commit 81f5677

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

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
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
}

tests/run-custom-args/erased/quotes-reflection.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ method m2: (i: scala.Int) isGiven=false isImplicit=false erasedArgs=List(true)
44
method m3: (i: scala.Int, j: scala.Int) isGiven=false isImplicit=false erasedArgs=List(false, true)
55
method m4: (i: EC) isGiven=false isImplicit=false erasedArgs=List(true)
66
val l1: scala.ContextFunction1[scala.Int, scala.Int]
7-
val l2: scala.runtime.ErasedFunction with apply: (x$0: scala.Int @scala.annotation.internal.ErasedParam) isImplicit=false erasedParams=List(true)
8-
val l3: scala.runtime.ErasedFunction with apply: (x$0: scala.Int @scala.annotation.internal.ErasedParam) isImplicit=true erasedParams=List(true)
9-
val l4: scala.runtime.ErasedFunction with apply: (x$0: scala.Int, x$1: scala.Int @scala.annotation.internal.ErasedParam) isImplicit=false erasedParams=List(false, true)
10-
val l5: scala.runtime.ErasedFunction with apply: (x$0: EC @scala.annotation.internal.ErasedParam) isImplicit=false erasedParams=List(true)
7+
val l2: scala.runtime.ErasedFunction with apply: (x: scala.Int @scala.annotation.internal.ErasedParam) isImplicit=false erasedParams=List(true)
8+
val l3: scala.runtime.ErasedFunction with apply: (x: scala.Int @scala.annotation.internal.ErasedParam) isImplicit=true erasedParams=List(true)
9+
val l4: scala.runtime.ErasedFunction with apply: (x: scala.Int, y: scala.Int @scala.annotation.internal.ErasedParam) isImplicit=false erasedParams=List(false, true)
10+
val l5: scala.runtime.ErasedFunction with apply: (x: EC @scala.annotation.internal.ErasedParam) isImplicit=false erasedParams=List(true)

0 commit comments

Comments
 (0)