Skip to content

Commit cf5999c

Browse files
committed
Remove appliedIfMethod use ensureApplied instead
1 parent 765960f commit cf5999c

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
4444
def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply =
4545
ta.assignType(untpd.Apply(fn, args), fn, args)
4646

47-
def ensureApplied(fn: Tree)(implicit ctx: Context): Tree =
48-
if (fn.tpe.widen.isParameterless) fn else Apply(fn, Nil)
49-
5047
def TypeApply(fn: Tree, args: List[Tree])(implicit ctx: Context): TypeApply =
5148
ta.assignType(untpd.TypeApply(fn, args), fn, args)
5249

@@ -566,13 +563,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
566563

567564
def appliedToNone(implicit ctx: Context): Apply = appliedToArgs(Nil)
568565

569-
def appliedIfMethod(implicit ctx: Context): Tree = {
570-
tree.tpe.widen match {
571-
case fntpe: MethodType => appliedToArgs(Nil)
572-
case _ => tree
573-
}
574-
}
575-
576566
def appliedToType(targ: Type)(implicit ctx: Context): Tree =
577567
appliedToTypes(targ :: Nil)
578568

@@ -582,6 +572,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
582572
def appliedToTypeTrees(targs: List[Tree])(implicit ctx: Context): Tree =
583573
if (targs.isEmpty) tree else TypeApply(tree, targs)
584574

575+
def ensureApplied(implicit ctx: Context): Tree =
576+
if (tree.tpe.widen.isParameterless) tree else tree.appliedToNone
577+
585578
def isInstance(tp: Type)(implicit ctx: Context): Tree =
586579
tree.select(defn.Any_isInstanceOf).appliedToType(tp)
587580

@@ -638,7 +631,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
638631
val mname = ("to" + numericCls.name).toTermName
639632
val conversion = tree.tpe member mname
640633
if (conversion.symbol.exists)
641-
ensureApplied(tree.select(conversion.symbol.termRef))
634+
tree.select(conversion.symbol.termRef).ensureApplied
642635
else if (tree.tpe.widen isRef numericCls)
643636
tree
644637
else {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import typer.ErrorReporting._
2020
import ast.Trees._
2121
import Applications._
2222
import TypeApplications._
23-
import TypeUtils._
23+
import SymUtils._, core.NameOps._
2424

2525
import dotty.tools.dotc.util.Positions.Position
2626
import dotty.tools.dotc.core.Decorators._
@@ -112,7 +112,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
112112
def tupleSel(binder: Symbol)(i: Int): Tree = ref(binder).select(nme.productAccessorName(i))
113113
def index(tgt: Tree)(i: Int): Tree = {
114114
if (i > 0) tgt.select(defn.Seq_apply).appliedTo(Literal(Constant(i)))
115-
else tgt.select(defn.Seq_head).appliedIfMethod
115+
else tgt.select(defn.Seq_head).ensureApplied
116116
}
117117

118118
// Right now this blindly calls drop on the result of the unapplySeq
@@ -237,7 +237,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
237237
val matchFail = newSynthCaseLabel(ctx.freshName("matchFail"), MethodType(Nil, restpe))
238238
val catchAllDefBody = DefDef(matchFail, catchAllDef)
239239

240-
val nextCases = (caseSyms.tail ::: List(matchFail)).map(ref(_).appliedIfMethod)
240+
val nextCases = (caseSyms.tail ::: List(matchFail)).map(ref(_).ensureApplied)
241241
val caseDefs = (cases zip caseSyms zip nextCases).foldRight[Tree](catchAllDefBody) {
242242
// dotty deviation
243243
//case (((mkCase, sym), nextCase), acc) =>
@@ -248,7 +248,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
248248

249249
val caseBody = DefDef(sym, _ => Block(List(acc), body))
250250

251-
Block(List(caseBody),ref(sym).appliedIfMethod)
251+
Block(List(caseBody),ref(sym).ensureApplied)
252252
}}
253253

254254

@@ -278,7 +278,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
278278
val isDefined = extractorMemberType(prev.tpe, nme.isDefined)
279279

280280
if ((isDefined isRef defn.BooleanClass) && getTp.exists) {
281-
val prevValue = ref(prevSym).select("get".toTermName).appliedIfMethod
281+
val prevValue = ref(prevSym).select("get".toTermName).ensureApplied
282282
Block(
283283
List(ValDef(prevSym, prev)),
284284
// must be isEmpty and get as we don't control the target of the call (prev is an extractor call)
@@ -1800,7 +1800,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
18001800
if ((extractorMemberType(resultType, nme.isDefined) isRef defn.BooleanClass) && resultOfGet.exists)
18011801
getUnapplySelectors(resultOfGet, args)
18021802
else if (defn.isProductSubType(resultType)) productSelectorTypes(resultType)
1803-
else if (resultType =:= defn.BooleanType) Nil
1803+
else if (resultType isRef defn.BooleanClass) Nil
18041804
else {
18051805
ctx.error(i"invalid return type in Unapply node: $resultType")
18061806
Nil

0 commit comments

Comments
 (0)