Skip to content

Commit b20ff6b

Browse files
committed
Move isBackquoted to TreeInfo
1 parent 70316a6 commit b20ff6b

File tree

7 files changed

+14
-11
lines changed

7 files changed

+14
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ object desugar {
310310
* ```
311311
*/
312312
def transformQuotedPatternName(tree: ValOrDefDef)(implicit ctx: Context): ValOrDefDef = {
313-
if (ctx.mode.is(Mode.QuotedPattern) && !tree.isBackquoted && tree.name != nme.ANON_FUN && tree.name.startsWith("$")) {
313+
if (ctx.mode.is(Mode.QuotedPattern) && !isBackquoted(tree) && tree.name != nme.ANON_FUN && tree.name.startsWith("$")) {
314314
val mods = tree.mods.withAddedAnnotation(New(ref(defn.InternalQuoted_patternBindHoleAnnot.typeRef)).withSpan(tree.span))
315315
tree.withMods(mods)
316316
} else tree
@@ -1478,7 +1478,7 @@ object desugar {
14781478
// This is a deliberate departure from scalac, where StringContext is not rooted (See #4732)
14791479
Apply(Select(Apply(scalaDot(nme.StringContext), strs), id), elems)
14801480
case PostfixOp(t, op) =>
1481-
if ((ctx.mode is Mode.Type) && !op.isBackquoted && op.name == tpnme.raw.STAR) {
1481+
if ((ctx.mode is Mode.Type) && !isBackquoted(op) && op.name == tpnme.raw.STAR) {
14821482
val seqType = if (ctx.compilationUnit.isJava) defn.ArrayType else defn.SeqType
14831483
Annotated(
14841484
AppliedTypeTree(ref(seqType), t),

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,12 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
140140
case _ => false
141141
}
142142

143+
/** Is tree a backquoted identifier or definition */
144+
def isBackquoted(tree: Tree): Boolean = tree.hasAttachment(Backquoted)
145+
143146
/** Is tree a variable pattern? */
144147
def isVarPattern(pat: Tree): Boolean = unsplice(pat) match {
145-
case x: Ident => x.name.isVariableName && !x.isBackquoted
148+
case x: Ident => x.name.isVariableName && !isBackquoted(x)
146149
case _ => false
147150
}
148151

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@ object Parsers {
408408
*/
409409
def convertToParam(tree: Tree, expected: String = "formal parameter"): ValDef = tree match {
410410
case id @ Ident(name) =>
411-
makeParameter(name.asTermName, TypeTree(), isBackquoted = id.isBackquoted).withSpan(tree.span)
411+
makeParameter(name.asTermName, TypeTree(), isBackquoted = isBackquoted(id)).withSpan(tree.span)
412412
case Typed(id @ Ident(name), tpt) =>
413-
makeParameter(name.asTermName, tpt, isBackquoted = id.isBackquoted).withSpan(tree.span)
413+
makeParameter(name.asTermName, tpt, isBackquoted = isBackquoted(id)).withSpan(tree.span)
414414
case Typed(Splice(Ident(name)), tpt) =>
415415
makeParameter(("$" + name).toTermName, tpt).withSpan(tree.span)
416416
case _ =>
@@ -2526,7 +2526,7 @@ object Parsers {
25262526
} else EmptyTree
25272527
lhs match {
25282528
case (id @ Ident(name: TermName)) :: Nil =>
2529-
if (id.isBackquoted)
2529+
if (isBackquoted(id))
25302530
finalizeDef(BackquotedValDef(id.name.asTermName, tpt, rhs), mods, start)
25312531
else
25322532
finalizeDef(ValDef(name, tpt, rhs), mods, start)
@@ -2606,7 +2606,7 @@ object Parsers {
26062606
expr()
26072607
}
26082608

2609-
if (ident.isBackquoted) finalizeDef(BackquotedDefDef(ident.name.asTermName, tparams, vparamss, tpt, rhs), mods1, start)
2609+
if (isBackquoted(ident)) finalizeDef(BackquotedDefDef(ident.name.asTermName, tparams, vparamss, tpt, rhs), mods1, start)
26102610
else finalizeDef(DefDef(ident.name.asTermName, tparams, vparamss, tpt, rhs), mods1, start)
26112611
}
26122612
}

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
349349
case _ =>
350350
toText(name)
351351
}
352-
if (tree.isBackquoted && !homogenizedView) "`" ~ toText(name) ~ "`"
352+
if (isBackquoted(tree) && !homogenizedView) "`" ~ toText(name) ~ "`"
353353
else if (name.isTypeName) typeText(txt)
354354
else txt
355355
case tree @ Select(qual, name) =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ object PatternMatcher {
188188
case Typed(_, tpt) if tpt.tpe.isRepeatedParam => true
189189
case Bind(nme.WILDCARD, WildcardPattern()) => true // don't skip when binding an interesting symbol!
190190
case t if isWildcardArg(t) => true
191-
case x: Ident => x.name.isVariableName && !x.isBackquoted
191+
case x: Ident => x.name.isVariableName && !isBackquoted(x)
192192
case Alternative(ps) => ps.forall(unapply)
193193
case EmptyTree => true
194194
case _ => false

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
330330
Typ(c.value.asInstanceOf[Symbol].termRef, false)
331331
else
332332
Typ(ConstantType(c), false)
333-
case pat: Ident if pat.isBackquoted => Typ(pat.tpe, false)
333+
case pat: Ident if isBackquoted(pat) => Typ(pat.tpe, false)
334334
case Ident(nme.WILDCARD) =>
335335
Or(Typ(pat.tpe.stripAnnots, false) :: nullSpace :: Nil)
336336
case Ident(_) | Select(_, _) =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ trait Checking {
755755
case id @ Ident(name: Name) =>
756756
name.toTermName match {
757757
case name: SimpleName
758-
if !id.isBackquoted &&
758+
if !untpd.isBackquoted(id) &&
759759
!name.exists(isOperatorPart) &&
760760
!isInfix(meth) &&
761761
!meth.maybeOwner.is(Scala2x) &&

0 commit comments

Comments
 (0)