Skip to content

Commit 198f8b5

Browse files
sjrdadpi2
authored andcommitted
Pull the special erasure of wildcards up to the ContextFunction extractor.
That is their only source. In general, it makes no sense to erase a wildcard. It only makes sense in that particular place because the compiler later turns those type arguments into actual arguments and result types, where it picks their upper bound.
1 parent a11bedd commit 198f8b5

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

modules/unpickler/src/main/scala/ch/epfl/scala/debugadapter/internal/stacktrace/Scala3Unpickler.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -917,11 +917,12 @@ class Scala3Unpickler(
917917
checkTypeErasure: Boolean = true
918918
): Boolean =
919919
object CurriedContextFunction:
920-
def unapply(tpe: Type): Option[(Seq[TypeOrWildcard], TypeOrWildcard)] =
921-
def rec(tpe: TypeOrWildcard, args: Seq[TypeOrWildcard]): Option[(Seq[TypeOrWildcard], TypeOrWildcard)] =
920+
def unapply(tpe: Type): Option[(Seq[Type], Type)] =
921+
def rec(tpe: TypeOrWildcard, args: Seq[Type]): Option[(Seq[Type], Type)] =
922922
tpe match
923-
case tpe: AppliedType if tpe.tycon.isContextFunction => rec(tpe.args.last, args ++ tpe.args.init)
924-
case res => Option.when(args.nonEmpty)((args, res))
923+
case tpe: AppliedType if tpe.tycon.isContextFunction =>
924+
rec(tpe.args.last, args ++ tpe.args.init.map(_.highIfWildcard))
925+
case res => Option.when(args.nonEmpty)((args, res.highIfWildcard))
925926
if uncurryContextFunction then rec(tpe, Seq.empty) else None
926927

927928
val paramNames = declaredType.allParamNames.map(_.toString)

modules/unpickler/src/main/scala/ch/epfl/scala/debugadapter/internal/stacktrace/extensions.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ extension (tpe: Type)
112112

113113
extension (tpe: NamedType) def nameStr: String = tpe.name.toString
114114

115-
extension (tpe: TypeOrWildcard)
115+
extension (tpe: Type)
116116
def erasedAsReturnType(using Context): ErasedTypeRef = erased(isReturnType = true)
117117
def erasedAsArgType(asJavaVarargs: Boolean = false)(using Context): ErasedTypeRef =
118118
tpe match
@@ -121,10 +121,7 @@ extension (tpe: TypeOrWildcard)
121121
case _ => tpe.erased(isReturnType = false)
122122

123123
private def erased(isReturnType: Boolean)(using Context): ErasedTypeRef =
124-
val tpe1 = tpe match
125-
case tpe: Type => tpe
126-
case _: WildcardTypeArg => ctx.defn.ObjectType
127-
ErasedTypeRef.erase(tpe1, SourceLanguage.Scala3, keepUnit = isReturnType)
124+
ErasedTypeRef.erase(tpe, SourceLanguage.Scala3, keepUnit = isReturnType)
128125

129126
extension (ref: TermRef)
130127
def isScalaPredef: Boolean =

0 commit comments

Comments
 (0)