Skip to content

Commit af86500

Browse files
Remove redundant case override in TreeTypeMap (#17442)
This case is handled in the same way by TreeMap.
2 parents da01fd7 + 50d6303 commit af86500

File tree

7 files changed

+15
-21
lines changed

7 files changed

+15
-21
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@ class TreeTypeMap(
146146
val bind1 = tmap.transformSub(bind)
147147
val expr1 = tmap.transform(expr)
148148
cpy.Labeled(labeled)(bind1, expr1)
149-
case tree @ Hole(_, _, args, content, tpt) =>
150-
val args1 = args.mapConserve(transform)
151-
val content1 = transform(content)
152-
val tpt1 = transform(tpt)
153-
cpy.Hole(tree)(args = args1, content = content1, tpt = tpt1)
154149
case tree1 =>
155150
super.transform(tree1)
156151
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,16 +1033,15 @@ object Trees {
10331033
/** Tree that replaces a level 1 splices in pickled (level 0) quotes.
10341034
* It is only used when picking quotes (will never be in a TASTy file).
10351035
*
1036-
* @param isTermHole If this hole is a term, otherwise it is a type hole.
1036+
* @param isTerm If this hole is a term, otherwise it is a type hole.
10371037
* @param idx The index of the hole in it's enclosing level 0 quote.
10381038
* @param args The arguments of the splice to compute its content
10391039
* @param content Lambda that computes the content of the hole. This tree is empty when in a quote pickle.
10401040
* @param tpt Type of the hole
10411041
*/
1042-
case class Hole[+T <: Untyped](isTermHole: Boolean, idx: Int, args: List[Tree[T]], content: Tree[T], tpt: Tree[T])(implicit @constructorOnly src: SourceFile) extends Tree[T] {
1042+
case class Hole[+T <: Untyped](override val isTerm: Boolean, idx: Int, args: List[Tree[T]], content: Tree[T], tpt: Tree[T])(implicit @constructorOnly src: SourceFile) extends Tree[T] {
10431043
type ThisTree[+T <: Untyped] <: Hole[T]
1044-
override def isTerm: Boolean = isTermHole
1045-
override def isType: Boolean = !isTermHole
1044+
override def isType: Boolean = !isTerm
10461045
}
10471046

10481047
def flatten[T <: Untyped](trees: List[Tree[T]]): List[Tree[T]] = {
@@ -1563,8 +1562,8 @@ object Trees {
15631562
cpy.Quote(tree)(transform(body)(using quoteContext))
15641563
case tree @ Splice(expr) =>
15651564
cpy.Splice(tree)(transform(expr)(using spliceContext))
1566-
case tree @ Hole(_, _, args, content, tpt) =>
1567-
cpy.Hole(tree)(args = transform(args), content = transform(content), tpt = transform(tpt))
1565+
case tree @ Hole(isTerm, idx, args, content, tpt) =>
1566+
cpy.Hole(tree)(isTerm, idx, transform(args), transform(content), transform(tpt))
15681567
case _ =>
15691568
transformMoreCases(tree)
15701569
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
397397
def Throw(expr: Tree)(using Context): Tree =
398398
ref(defn.throwMethod).appliedTo(expr)
399399

400-
def Hole(isTermHole: Boolean, idx: Int, args: List[Tree], content: Tree, tpt: Tree)(using Context): Hole =
401-
ta.assignType(untpd.Hole(isTermHole, idx, args, content, tpt), tpt)
400+
def Hole(isTerm: Boolean, idx: Int, args: List[Tree], content: Tree, tpt: Tree)(using Context): Hole =
401+
ta.assignType(untpd.Hole(isTerm, idx, args, content, tpt), tpt)
402402

403403
// ------ Making references ------------------------------------------------------
404404

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
424424
def Export(expr: Tree, selectors: List[ImportSelector])(implicit src: SourceFile): Export = new Export(expr, selectors)
425425
def PackageDef(pid: RefTree, stats: List[Tree])(implicit src: SourceFile): PackageDef = new PackageDef(pid, stats)
426426
def Annotated(arg: Tree, annot: Tree)(implicit src: SourceFile): Annotated = new Annotated(arg, annot)
427-
def Hole(isTermHole: Boolean, idx: Int, args: List[Tree], content: Tree, tpt: Tree)(implicit src: SourceFile): Hole = new Hole(isTermHole, idx, args, content, tpt)
427+
def Hole(isTerm: Boolean, idx: Int, args: List[Tree], content: Tree, tpt: Tree)(implicit src: SourceFile): Hole = new Hole(isTerm, idx, args, content, tpt)
428428

429429
// ------ Additional creation methods for untyped only -----------------
430430

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
724724
case Splice(expr) =>
725725
val spliceTypeText = (keywordStr("[") ~ toTextGlobal(tree.typeOpt) ~ keywordStr("]")).provided(printDebug && tree.typeOpt.exists)
726726
keywordStr("$") ~ spliceTypeText ~ keywordStr("{") ~ toTextGlobal(expr) ~ keywordStr("}")
727-
case Hole(isTermHole, idx, args, content, tpt) =>
728-
val (prefix, postfix) = if isTermHole then ("{{{", "}}}") else ("[[[", "]]]")
727+
case Hole(isTerm, idx, args, content, tpt) =>
728+
val (prefix, postfix) = if isTerm then ("{{{", "}}}") else ("[[[", "]]]")
729729
val argsText = toTextGlobal(args, ", ")
730730
val contentText = toTextGlobal(content)
731731
val tptText = toTextGlobal(tpt)

compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ object PickledQuotes {
100100
private def spliceTerms(tree: Tree, typeHole: TypeHole, termHole: ExprHole)(using Context): Tree = {
101101
def evaluateHoles = new TreeMap {
102102
override def transform(tree: tpd.Tree)(using Context): tpd.Tree = tree match {
103-
case Hole(isTermHole, idx, args, _, _) =>
103+
case Hole(isTerm, idx, args, _, _) =>
104104
inContext(SpliceScope.contextWithNewSpliceScope(tree.sourcePos)) {
105-
if isTermHole then
105+
if isTerm then
106106
val quotedExpr = termHole match
107107
case ExprHole.V1(evalHole) =>
108108
evalHole.nn.apply(idx, reifyExprHoleV1Args(args), QuotesImpl())

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,15 +658,15 @@ object TreeChecker {
658658
super.typedPackageDef(tree)
659659

660660
override def typedHole(tree: untpd.Hole, pt: Type)(using Context): Tree = {
661-
val tree1 @ Hole(isTermHole, _, args, content, tpt) = super.typedHole(tree, pt): @unchecked
661+
val tree1 @ Hole(isTerm, _, args, content, tpt) = super.typedHole(tree, pt): @unchecked
662662

663663
// Check that we only add the captured type `T` instead of a more complex type like `List[T]`.
664664
// If we have `F[T]` with captured `F` and `T`, we should list `F` and `T` separately in the args.
665665
for arg <- args do
666666
assert(arg.isTerm || arg.tpe.isInstanceOf[TypeRef], "Expected TypeRef in Hole type args but got: " + arg.tpe)
667667

668668
// Check result type of the hole
669-
if isTermHole then assert(tpt.typeOpt <:< pt)
669+
if isTerm then assert(tpt.typeOpt <:< pt)
670670
else assert(tpt.typeOpt =:= pt)
671671

672672
// Check that the types of the args conform to the types of the contents of the hole
@@ -682,7 +682,7 @@ object TreeChecker {
682682
else defn.QuotedTypeClass.typeRef.appliedTo(arg.typeOpt.widenTermRefExpr)
683683
}
684684
val expectedResultType =
685-
if isTermHole then defn.QuotedExprClass.typeRef.appliedTo(tpt.typeOpt)
685+
if isTerm then defn.QuotedExprClass.typeRef.appliedTo(tpt.typeOpt)
686686
else defn.QuotedTypeClass.typeRef.appliedTo(tpt.typeOpt)
687687
val contextualResult =
688688
defn.FunctionOf(List(defn.QuotesClass.typeRef), expectedResultType, isContextual = true)

0 commit comments

Comments
 (0)