Skip to content

Commit 2e6b343

Browse files
committed
make appliedToNone fail for exprType, use appliedIfMethod instead
see discussion in dotty-staging@0c551f0
1 parent 42ad90f commit 2e6b343

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
497497
Try(tree: Tree)(expr, handler, finalizer)
498498
}
499499

500-
implicit class TreeOps[ThisTree <: tpd.Tree](val tree: ThisTree)/* extends AnyVal*/ {
500+
implicit class TreeOps[ThisTree <: tpd.Tree](val tree: ThisTree) extends AnyVal {
501501

502502
def isValue(implicit ctx: Context): Boolean =
503503
tree.isTerm && tree.tpe.widen.isValueType
@@ -565,8 +565,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
565565
def appliedToArgss(argss: List[List[Tree]])(implicit ctx: Context): Tree =
566566
((tree: Tree) /: argss)(Apply(_, _))
567567

568-
def appliedToNone(implicit ctx: Context): Tree = {
569-
tree.tpe.widen match {
568+
def appliedToNone(implicit ctx: Context): Tree = appliedToArgs(Nil)
569+
570+
def appliedIfMethod(implicit ctx: Context): Tree = {
571+
tree.tpe.widen match {
570572
case fntpe: MethodType => appliedToArgs(Nil)
571573
case _ => tree
572574
}

src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ class Definitions {
342342
def NothingType: Type = NothingClass.typeRef
343343
def NullType: Type = NullClass.typeRef
344344
def SeqType: Type = SeqClass.typeRef
345-
def ObjectArrayType = ArrayType(ObjectType)
346345

347346
def UnitType: Type = UnitClass.typeRef
348347
def BooleanType: Type = BooleanClass.typeRef

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
105105
def tupleSel(binder: Symbol)(i: Int): Tree = ref(binder).select(nme.productAccessorName(i)) // make tree that accesses the i'th component of the tuple referenced by binder
106106
def index(tgt: Tree)(i: Int): Tree = {
107107
if (i > 0) tgt.select(defn.Seq_apply).appliedTo(Literal(Constant(i)))
108-
else tgt.select(defn.Seq_head).appliedToNone
108+
else tgt.select(defn.Seq_head).appliedIfMethod
109109
}
110110

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

235-
val nextCases = (caseSyms.tail ::: List(matchFail)).map(ref(_).appliedToNone)
235+
val nextCases = (caseSyms.tail ::: List(matchFail)).map(ref(_).appliedIfMethod)
236236
val caseDefs = (cases zip caseSyms zip nextCases).foldRight[Tree](catchAllDefBody) {
237237
// dotty deviation
238238
//case (((mkCase, sym), nextCase), acc) =>
@@ -243,7 +243,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
243243

244244
val caseBody = DefDef(sym, _ => Block(List(acc), body))
245245

246-
Block(List(caseBody),ref(sym).appliedToNone)
246+
Block(List(caseBody),ref(sym).appliedIfMethod)
247247
}}
248248

249249

@@ -273,7 +273,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
273273
val isDefined = extractorMemberType(prev.tpe, nme.isDefined)
274274

275275
if ((isDefined isRef defn.BooleanClass) && getTp.exists) {
276-
val prevValue = ref(prevSym).select("get".toTermName).appliedToNone
276+
val prevValue = ref(prevSym).select("get".toTermName).appliedIfMethod
277277
Block(
278278
List(ValDef(prevSym, prev)),
279279
// must be isEmpty and get as we don't control the target of the call (prev is an extractor call)

0 commit comments

Comments
 (0)