Skip to content

Commit 9591d96

Browse files
committed
make tpd.appliedToArgss also work for type arguments
1 parent dcf6124 commit 9591d96

18 files changed

+36
-33
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
181181

182182
def rewire(stat: Tree) = thisMap.transform(stat).changeOwner(claszSymbol.primaryConstructor, clInitSymbol)
183183

184-
val callConstructor = New(claszSymbol.typeRef).select(claszSymbol.primaryConstructor).appliedToArgs(Nil)
184+
val callConstructor = New(claszSymbol.typeRef).select(claszSymbol.primaryConstructor).appliedToTermArgs(Nil)
185185
val assignModuleField = Assign(ref(moduleField), callConstructor)
186186
val remainingConstrStatsSubst = remainingConstrStats.map(rewire)
187187
val clinit = clinits match {

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
894894
* will return a term or type tree respectively.
895895
*/
896896
def unapply(tree: tpd.Tree)(using Context): Option[tpd.Tree] = tree match {
897-
case tree: GenericApply[Type] if tree.symbol.isQuote => Some(tree.args.head)
897+
case tree: GenericApply if tree.symbol.isQuote => Some(tree.args.head)
898898
case _ => None
899899
}
900900
}

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,7 @@ object Trees {
970970
type Super = Trees.Super[T]
971971
type Apply = Trees.Apply[T]
972972
type TypeApply = Trees.TypeApply[T]
973+
type GenericApply = Trees.GenericApply[T]
973974
type Literal = Trees.Literal[T]
974975
type New = Trees.New[T]
975976
type Typed = Trees.Typed[T]

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
4242
Super(qual, if (mixName.isEmpty) untpd.EmptyTypeIdent else untpd.Ident(mixName), mixinClass)
4343

4444
def Apply(fn: Tree, args: List[Tree])(using Context): Apply = {
45-
assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply[_]] || fn.isInstanceOf[Inlined] || fn.isInstanceOf[tasty.TreePickler.Hole])
45+
assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply] || fn.isInstanceOf[Inlined] || fn.isInstanceOf[tasty.TreePickler.Hole])
4646
ta.assignType(untpd.Apply(fn, args), fn, args)
4747
}
4848

4949
def TypeApply(fn: Tree, args: List[Tree])(using Context): TypeApply = {
50-
assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply[_]])
50+
assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply])
5151
ta.assignType(untpd.TypeApply(fn, args), fn, args)
5252
}
5353

@@ -196,7 +196,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
196196
ta.assignType(untpd.Alternative(trees), trees)
197197

198198
def UnApply(fun: Tree, implicits: List[Tree], patterns: List[Tree], proto: Type)(using Context): UnApply = {
199-
assert(fun.isInstanceOf[RefTree] || fun.isInstanceOf[GenericApply[_]])
199+
assert(fun.isInstanceOf[RefTree] || fun.isInstanceOf[GenericApply])
200200
ta.assignType(untpd.UnApply(fun, implicits, patterns), proto)
201201
}
202202

@@ -463,10 +463,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
463463

464464
if (!ctx.erasedTypes) {
465465
assert(!TypeErasure.isGeneric(elemTpe), elemTpe) //needs to be done during typer. See Applications.convertNewGenericArray
466-
newArr.appliedToTypeTrees(TypeTree(returnTpe) :: Nil).appliedToArgs(clsOf(elemTpe) :: clsOf(returnTpe) :: dims :: Nil).withSpan(span)
466+
newArr.appliedToTypeTrees(TypeTree(returnTpe) :: Nil).appliedToTermArgs(clsOf(elemTpe) :: clsOf(returnTpe) :: dims :: Nil).withSpan(span)
467467
}
468468
else // after erasure
469-
newArr.appliedToArgs(clsOf(elemTpe) :: clsOf(returnTpe) :: dims :: Nil).withSpan(span)
469+
newArr.appliedToTermArgs(clsOf(elemTpe) :: clsOf(returnTpe) :: dims :: Nil).withSpan(span)
470470
}
471471

472472
/** The wrapped array method name for an array of type elemtp */
@@ -500,7 +500,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
500500
New(tycon)
501501
.select(TermRef(tycon, constr))
502502
.appliedToTypes(targs)
503-
.appliedToArgs(args)
503+
.appliedToTermArgs(args)
504504
}
505505

506506
/** An object def
@@ -898,14 +898,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
898898

899899
/** A unary apply node with given argument: `tree(arg)` */
900900
def appliedTo(arg: Tree)(using Context): Apply =
901-
appliedToArgs(arg :: Nil)
901+
appliedToTermArgs(arg :: Nil)
902902

903903
/** An apply node with given arguments: `tree(arg, args0, ..., argsN)` */
904904
def appliedTo(arg: Tree, args: Tree*)(using Context): Apply =
905-
appliedToArgs(arg :: args.toList)
905+
appliedToTermArgs(arg :: args.toList)
906906

907907
/** An apply node with given argument list `tree(args(0), ..., args(args.length - 1))` */
908-
def appliedToArgs(args: List[Tree])(using Context): Apply =
908+
def appliedToTermArgs(args: List[Tree])(using Context): Apply =
909909
Apply(tree, args)
910910

911911
/** An applied node that accepts only varargs as arguments */
@@ -916,10 +916,13 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
916916
* `tree (argss(0)) ... (argss(argss.length -1))`
917917
*/
918918
def appliedToArgss(argss: List[List[Tree]])(using Context): Tree =
919-
argss.foldLeft(tree: Tree)(Apply(_, _))
919+
argss.foldLeft(tree: Tree) { (t, args) => args match
920+
case arg :: args1 if arg.isType => TypeApply(tree, args)
921+
case _ => Apply(t, args)
922+
}
920923

921924
/** The current tree applied to (): `tree()` */
922-
def appliedToNone(using Context): Apply = appliedToArgs(Nil)
925+
def appliedToNone(using Context): Apply = Apply(tree, Nil)
923926

924927
/** The current tree applied to given type argument: `tree[targ]` */
925928
def appliedToType(targ: Type)(using Context): Tree =
@@ -1224,7 +1227,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
12241227
letBindUnless(TreeInfo.Idempotent, tree)(within)
12251228

12261229
def runtimeCall(name: TermName, args: List[Tree])(using Context): Tree =
1227-
Ident(defn.ScalaRuntimeModule.requiredMethod(name).termRef).appliedToArgs(args)
1230+
Ident(defn.ScalaRuntimeModule.requiredMethod(name).termRef).appliedToTermArgs(args)
12281231

12291232
/** An extractor that pulls out type arguments */
12301233
object MaybePoly {

compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
230230
ref(sym.termRef)
231231
.appliedToTypeTrees(trefs)
232232
.appliedToArgss(init)
233-
.appliedToArgs(last :+ wrapArray(vararg, elemtp))
233+
.appliedToTermArgs(last :+ wrapArray(vararg, elemtp))
234234
})
235235
Thicket(tree, forwarderDef)
236236
else

compiler/src/dotty/tools/dotc/transform/FullParameterization.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ trait FullParameterization {
233233
originalDef.vparamss.foldLeft(fun)((acc, vparams) => {
234234
val meth = acc.tpe.asInstanceOf[MethodType]
235235
val paramTypes = meth.instantiateParamInfos(vparams.map(_.tpe))
236-
acc.appliedToArgs(
236+
acc.appliedToTermArgs(
237237
vparams.lazyZip(paramTypes).map((vparam, paramType) => {
238238
assert(vparam.tpe <:< paramType.widen) // type should still conform to widened type
239239
ref(vparam.symbol).ensureConforms(paramType)

compiler/src/dotty/tools/dotc/transform/FunctionXXLForwarders.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class FunctionXXLForwarders extends MiniPhase with IdentityDenotTransformer {
3434
var idx = -1
3535
val argss = receiver.tpe.widenDealias.paramInfoss.map(_.map { param =>
3636
idx += 1
37-
argsApply.appliedToArgs(List(Literal(Constant(idx)))).cast(param)
37+
argsApply.appliedToTermArgs(List(Literal(Constant(idx)))).cast(param)
3838
})
3939
ref(receiver.symbol).appliedToArgss(argss).cast(defn.ObjectType)
4040
}

compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class InterceptedMethods extends MiniPhase {
7373
}
7474

7575
if tree.fun.symbol == defn.Any_!= then
76-
qual.select(defn.Any_==).appliedToArgs(tree.args).select(defn.Boolean_!).withSpan(tree.span)
76+
qual.select(defn.Any_==).appliedToTermArgs(tree.args).select(defn.Boolean_!).withSpan(tree.span)
7777
else
7878
tree
7979
}

compiler/src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
216216
case _ =>
217217
val Apply(sel @ Select(New(_), nme.CONSTRUCTOR), args) = tree
218218
val (callArgs, initArgs) = if (tree.symbol.owner.is(Trait)) (Nil, args) else (args, Nil)
219-
(superRef(tree.symbol, tree.span).appliedToArgs(callArgs), Nil, initArgs)
219+
(superRef(tree.symbol, tree.span).appliedToTermArgs(callArgs), Nil, initArgs)
220220
}
221221

222222
val superCallsAndArgs: Map[Symbol, (Tree, List[Tree], List[Tree])] = (

compiler/src/dotty/tools/dotc/transform/MixinOps.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
7474
isCurrent(meth)
7575
}
7676

77-
7877
final val PrivateOrAccessor: FlagSet = Private | Accessor
7978
final val PrivateOrAccessorOrDeferred: FlagSet = Private | Accessor | Deferred
8079

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ object PatternMatcher {
390390
case mt: MethodType =>
391391
assert(mt.isImplicitMethod)
392392
val (args, rest) = implicits.splitAt(mt.paramNames.size)
393-
applyImplicits(acc.appliedToArgs(args), rest, mt.resultType)
393+
applyImplicits(acc.appliedToTermArgs(args), rest, mt.resultType)
394394
case _ =>
395395
assert(implicits.isEmpty)
396396
acc

compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class PickleQuotes extends MacroTransform {
166166
val literalValue =
167167
if lit.const.tag == Constants.NullTag || lit.const.tag == Constants.UnitTag then Nil
168168
else List(body)
169-
val constant = reflect.select(s"${typeName}Constant".toTermName).select(nme.apply).appliedToArgs(literalValue)
169+
val constant = reflect.select(s"${typeName}Constant".toTermName).select(nme.apply).appliedToTermArgs(literalValue)
170170
val literal = reflect.select("Literal".toTermName).select(nme.apply).appliedTo(constant)
171171
reflect.select("TreeMethods".toTermName).select("asExpr".toTermName).appliedTo(literal).asInstance(exprType)
172172
}

compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class SpecializeFunctions extends MiniPhase {
5959

6060
// create a forwarding to the specialized apply
6161
val args = ddef.vparamss.head.map(vparam => ref(vparam.symbol))
62-
val rhs = This(cls).select(specializedApply).appliedToArgs(args)
62+
val rhs = This(cls).select(specializedApply).appliedToTermArgs(args)
6363
val ddef1 = cpy.DefDef(ddef)(rhs = rhs)
6464
Thicket(ddef1, specializedDecl)
6565
}
@@ -92,7 +92,7 @@ class SpecializeFunctions extends MiniPhase {
9292
}
9393
}
9494

95-
newSel.appliedToArgs(args)
95+
newSel.appliedToTermArgs(args)
9696

9797
case _ => tree
9898
}

compiler/src/dotty/tools/dotc/transform/SyntheticMembers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
117117
coord = clazz.coord).enteredAfter(thisPhase).asTerm
118118

119119
def forwardToRuntime(vrefs: List[Tree]): Tree =
120-
ref(defn.runtimeMethodRef("_" + sym.name.toString)).appliedToArgs(This(clazz) :: vrefs)
120+
ref(defn.runtimeMethodRef("_" + sym.name.toString)).appliedToTermArgs(This(clazz) :: vrefs)
121121

122122
def ownName: Tree =
123123
Literal(Constant(clazz.name.stripModuleClassSuffix.toString))

compiler/src/dotty/tools/dotc/transform/TupleOptimizations.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
4949
else {
5050
// val it = Iterator.single(head) ++ tail.asInstanceOf[Product].productIterator
5151
// TupleN+1(it.next(), ..., it.next())
52-
val fullIterator = ref(defn.RuntimeTuple_consIterator).appliedToArgs(head :: tail :: Nil)
52+
val fullIterator = ref(defn.RuntimeTuple_consIterator).appliedToTermArgs(head :: tail :: Nil)
5353
evalOnce(fullIterator) { it =>
5454
knownTupleFromIterator(tpes.length, it).asInstance(tree.tpe)
5555
}
@@ -127,7 +127,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
127127
else {
128128
// val it = self.asInstanceOf[Product].productIterator ++ that.asInstanceOf[Product].productIterator
129129
// TupleN+M(it.next(), ..., it.next())
130-
val fullIterator = ref(defn.RuntimeTuple_concatIterator).appliedToArgs(tree.args)
130+
val fullIterator = ref(defn.RuntimeTuple_concatIterator).appliedToTermArgs(tree.args)
131131
evalOnce(fullIterator) { it =>
132132
knownTupleFromIterator(n + m, it).asInstance(tree.tpe)
133133
}
@@ -192,7 +192,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
192192
val size = elements.size
193193
assert(0 < size && size <= MaxTupleArity)
194194
val tupleModule = defn.TupleType(size).classSymbol.companionModule
195-
ref(tupleModule).select(nme.apply).appliedToTypes(tpes).appliedToArgs(elements)
195+
ref(tupleModule).select(nme.apply).appliedToTypes(tpes).appliedToTermArgs(elements)
196196
}
197197

198198
private def knownTupleFromIterator(size: Int, it: Tree)(using Context): Tree =

compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ class StringInterpolatorOpt extends MiniPhase {
152152
val stringToString = defn.StringContextModule_processEscapes.info.asInstanceOf[MethodType]
153153

154154
val process = tpd.Lambda(stringToString, args =>
155-
if (isRaw) args.head else ref(defn.StringContextModule_processEscapes).appliedToArgs(args))
155+
if (isRaw) args.head else ref(defn.StringContextModule_processEscapes).appliedToTermArgs(args))
156156

157157
evalOnce(pre) { sc =>
158158
val parts = sc.select(defn.StringContext_parts)
159159

160160
ref(defn.StringContextModule_standardInterpolator)
161-
.appliedToArgs(List(process, args, parts))
161+
.appliedToTermArgs(List(process, args, parts))
162162
}
163163
}
164164
else

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ trait Applications extends Compatibility {
434434
/** Splice new method reference into existing application */
435435
def spliceMeth(meth: Tree, app: Tree): Tree = app match {
436436
case Apply(fn, args) =>
437-
spliceMeth(meth, fn).appliedToArgs(args)
437+
spliceMeth(meth, fn).appliedToTermArgs(args)
438438
case TypeApply(fn, targs) =>
439439
// Note: It is important that the type arguments `targs` are passed in new trees
440440
// instead of being spliced in literally. Otherwise, a type argument to a default
@@ -1095,7 +1095,7 @@ trait Applications extends Compatibility {
10951095
def newGenericArrayCall =
10961096
ref(defn.DottyArraysModule)
10971097
.select(defn.newGenericArrayMethod).withSpan(tree.span)
1098-
.appliedToTypeTrees(targs).appliedToArgs(args)
1098+
.appliedToTypeTrees(targs).appliedToTermArgs(args)
10991099

11001100
if (TypeErasure.isGeneric(targ.tpe))
11011101
newGenericArrayCall

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
381381
}
382382
val closureTpe = Types.MethodType(mtpe.paramNames, mtpe.paramInfos, closureResType)
383383
val closureMethod = dotc.core.Symbols.newSymbol(owner, nme.ANON_FUN, Synthetic | Method, closureTpe)
384-
tpd.Closure(closureMethod, tss => new tpd.TreeOps(self).appliedToArgs(tss.head).etaExpand(closureMethod))
384+
tpd.Closure(closureMethod, tss => new tpd.TreeOps(self).appliedToTermArgs(tss.head).etaExpand(closureMethod))
385385
case _ => self
386386
}
387387

0 commit comments

Comments
 (0)