Skip to content

Commit

Permalink
Cherry-pick typeMappingTable fix from #3455
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejSpanel committed Mar 22, 2024
1 parent 2774c3e commit 4a8d185
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,16 @@ private[surface] class CompileTimeSurfaceFactory[Q <: Quotes](using quotes: Q):
}

private def typeMappingTable(t: TypeRepr, method: Symbol): Map[String, TypeRepr] =
val classTypeParams: List[TypeRepr] = t match
val classTypeParams = t.typeSymbol.typeMembers.filter(_.isTypeParam)
val classTypeArgs: List[TypeRepr] = t match
case a: AppliedType => a.args
case _ => List.empty[TypeRepr]

// Build a table for resolving type parameters, e.g., class MyClass[A, B] -> Map("A" -> TypeRepr, "B" -> TypeRepr)
method.paramSymss match
// tpeArgs for case fields, methodArgs for method arguments
case tpeArgs :: tail if t.typeSymbol.typeMembers.nonEmpty =>
val typeArgTable = tpeArgs
.map(_.tree).zipWithIndex.collect {
case (td: TypeDef, i: Int) if i < classTypeParams.size =>
td.name -> classTypeParams(i)
}.toMap[String, TypeRepr]
// pri ntln(s"type args: ${typeArgTable}")
typeArgTable
case _ =>
Map.empty
(classTypeParams zip classTypeArgs)
.map { (paramType, argType) =>
paramType.name -> argType
}.toMap[String, TypeRepr]

// Get a constructor with its generic types are resolved
private def getResolvedConstructorOf(t: TypeRepr): Option[Term] =
Expand Down

0 comments on commit 4a8d185

Please sign in to comment.