Skip to content

Commit fc75422

Browse files
committed
Get eta-expanded types for HAOS pattern arguments from eta-expanded arguments
1 parent ff89398 commit fc75422

File tree

1 file changed

+11
-30
lines changed

1 file changed

+11
-30
lines changed

compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ object QuoteMatcher {
253253
val captureEnv = env.filter((k, v) => !capturedSymbols.contains(v))
254254
withEnv(captureEnv) {
255255
scrutinee match
256-
case ClosedPatternTerm(scrutinee) => matchedOpen(scrutinee, pattern.tpe, capturedIds, env)
256+
case ClosedPatternTerm(scrutinee) => matchedOpen(scrutinee, pattern.tpe, capturedIds, args.map(_.tpe), env)
257257
case _ => notMatched
258258
}
259259

@@ -473,35 +473,15 @@ object QuoteMatcher {
473473
*
474474
* @param tree Scrutinee sub-tree that matched
475475
* @param patternTpe Type of the pattern hole (from the pattern)
476-
* @param args HOAS arguments (from the pattern)
476+
* @param argIds Identifiers of HOAS arguments (from the pattern)
477+
* @param argTypes Eta-expanded types of HOAS arguments (from the pattern)
477478
* @param env Mapping between scrutinee and pattern variables
478479
*/
479-
case OpenTree(tree: Tree, patternTpe: Type, args: List[Tree], env: Env)
480+
case OpenTree(tree: Tree, patternTpe: Type, argIds: List[Tree], argTypes: List[Type], env: Env)
480481

481482
/** The Definitions object */
482483
def defn(using Context): Definitions = ctx.definitions
483484

484-
/*
485-
* PR-17567 Remaining TODOs
486-
* * [x] Implicit / Contextual parameters
487-
* * [x] Nested Method Types
488-
* * [x] Refinment Types
489-
* * [ ] Erased Types
490-
*/
491-
def adaptTypes(tpe: Type)(using Context): Type =
492-
tpe match {
493-
case tpe: MethodType if tpe.isResultDependent =>
494-
RefinedType(
495-
defn.FunctionOf(tpe.paramInfos, adaptTypes(tpe.nonDependentResultApprox), tpe.isImplicitMethod),
496-
nme.apply,
497-
tpe
498-
)
499-
500-
case tp: MethodType =>
501-
defn.FunctionOf(tp.paramInfos, adaptTypes(tp.resultType), tp.isImplicitMethod)
502-
case tp => tp
503-
}
504-
505485
/** Return the expression that was extracted from a hole.
506486
*
507487
* If it was a closed expression it returns that expression. Otherwise,
@@ -513,16 +493,17 @@ object QuoteMatcher {
513493
def toExpr(mapTypeHoles: TypeMap, spliceScope: Scope)(using Context): Expr[Any] = this match
514494
case MatchResult.ClosedTree(tree) =>
515495
new ExprImpl(tree, spliceScope)
516-
case MatchResult.OpenTree(tree, patternTpe, args, env) =>
517-
val names: List[TermName] = args.map {
496+
case MatchResult.OpenTree(tree, patternTpe, argIds, argTypes, env) =>
497+
val names: List[TermName] = argIds.map {
498+
// TODO 17105: Do we need this case?
518499
case Block(List(DefDef(nme.ANON_FUN, _, _, Apply(Ident(name), _))), _) => name.asTermName
519500
case arg => arg.symbol.name.asTermName
520501
}
521-
val paramTypes = args.map(x => adaptTypes(mapTypeHoles(x.tpe.widenTermRefExpr)))
502+
val paramTypes = argTypes.map(mapTypeHoles)
522503
val methTpe = MethodType(names)(_ => paramTypes, _ => mapTypeHoles(patternTpe))
523504
val meth = newAnonFun(ctx.owner, methTpe)
524505
def bodyFn(lambdaArgss: List[List[Tree]]): Tree = {
525-
val argsMap = args.view.map(_.symbol).zip(lambdaArgss.head).toMap
506+
val argsMap = argIds.view.map(_.symbol).zip(lambdaArgss.head).toMap
526507
val body = new TreeMap {
527508
override def transform(tree: Tree)(using Context): Tree =
528509
tree match
@@ -560,8 +541,8 @@ object QuoteMatcher {
560541
private inline def matched(tree: Tree)(using Context): MatchingExprs =
561542
Seq(MatchResult.ClosedTree(tree))
562543

563-
private def matchedOpen(tree: Tree, patternTpe: Type, args: List[Tree], env: Env)(using Context): MatchingExprs =
564-
Seq(MatchResult.OpenTree(tree, patternTpe, args, env))
544+
private def matchedOpen(tree: Tree, patternTpe: Type, argIds: List[Tree], argTypes: List[Type], env: Env)(using Context): MatchingExprs =
545+
Seq(MatchResult.OpenTree(tree, patternTpe, argIds, argTypes, env))
565546

566547
extension (self: MatchingExprs)
567548
/** Concatenates the contents of two successful matchings */

0 commit comments

Comments
 (0)