Skip to content

Commit 0b41954

Browse files
committed
Restrict treee copiers with default arguments to trees with more than 2 elements.
It's not really an abbreviation to do it for trees with fewer elements and it leads to unncessessary syntactic variation.
1 parent 891aeba commit 0b41954

File tree

5 files changed

+46
-46
lines changed

5 files changed

+46
-46
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ object desugar {
504504
*/
505505
def block(tree: Block)(implicit ctx: Context): Block = tree.expr match {
506506
case EmptyTree =>
507-
cpy.Block(tree)(
508-
expr = unitLiteral withPos (if (tree.stats.isEmpty) tree.pos else tree.pos.endPos))
507+
cpy.Block(tree)(tree.stats,
508+
unitLiteral withPos (if (tree.stats.isEmpty) tree.pos else tree.pos.endPos))
509509
case _ =>
510510
tree
511511
}

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

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ object Trees {
433433
case class Select[-T >: Untyped] private[ast] (qualifier: Tree[T], name: Name)
434434
extends RefTree[T] {
435435
type ThisTree[-T >: Untyped] = Select[T]
436-
def withName(name: Name)(implicit ctx: Context): untpd.Select = untpd.cpy.Select(this)(name = name)
436+
def withName(name: Name)(implicit ctx: Context): untpd.Select = untpd.cpy.Select(this)(qualifier, name)
437437
}
438438

439439
class SelectWithSig[-T >: Untyped] private[ast] (qualifier: Tree[T], name: Name, val sig: Signature)
@@ -620,7 +620,7 @@ object Trees {
620620
case class SelectFromTypeTree[-T >: Untyped] private[ast] (qualifier: Tree[T], name: Name)
621621
extends RefTree[T] {
622622
type ThisTree[-T >: Untyped] = SelectFromTypeTree[T]
623-
def withName(name: Name)(implicit ctx: Context): untpd.SelectFromTypeTree = untpd.cpy.SelectFromTypeTree(this)(name = name)
623+
def withName(name: Name)(implicit ctx: Context): untpd.SelectFromTypeTree = untpd.cpy.SelectFromTypeTree(this)(qualifier, name)
624624
}
625625

626626
/** left & right */
@@ -666,7 +666,7 @@ object Trees {
666666
extends NameTree[T] with DefTree[T] with PatternTree[T] {
667667
type ThisTree[-T >: Untyped] = Bind[T]
668668
override def envelope: Position = pos union initialPos
669-
def withName(name: Name)(implicit ctx: Context): untpd.Bind = untpd.cpy.Bind(this)(name = name)
669+
def withName(name: Name)(implicit ctx: Context): untpd.Bind = untpd.cpy.Bind(this)(name, body)
670670
}
671671

672672
/** tree_1 | ... | tree_n */
@@ -1094,24 +1094,24 @@ object Trees {
10941094
}
10951095

10961096
// Copier methods with default arguments; these demand that the original tree
1097-
// is of the same class as the copy
1098-
1099-
def Select(tree: Select)(qualifier: Tree = tree.qualifier, name: Name = tree.name): Select =
1100-
Select(tree: Tree)(qualifier, name)
1101-
def Super(tree: Super)(qual: Tree = tree.qual, mix: TypeName = tree.mix): Super =
1102-
Super(tree: Tree)(qual, mix)
1103-
def Apply(tree: Apply)(fun: Tree = tree.fun, args: List[Tree] = tree.args): Apply =
1104-
Apply(tree: Tree)(fun, args)
1105-
def TypeApply(tree: TypeApply)(fun: Tree = tree.fun, args: List[Tree] = tree.args): TypeApply =
1106-
TypeApply(tree: Tree)(fun, args)
1107-
def Typed(tree: Typed)(expr: Tree = tree.expr, tpt: Tree = tree.tpt): Typed =
1108-
Typed(tree: Tree)(expr, tpt)
1109-
def NamedArg(tree: NamedArg)(name: Name = tree.name, arg: Tree = tree.arg): NamedArg =
1110-
NamedArg(tree: Tree)(name, arg)
1111-
def Assign(tree: Assign)(lhs: Tree = tree.lhs, rhs: Tree = tree.rhs): Assign =
1112-
Assign(tree: Tree)(lhs, rhs)
1113-
def Block(tree: Block)(stats: List[Tree] = tree.stats, expr: Tree = tree.expr): Block =
1114-
Block(tree: Tree)(stats, expr)
1097+
// is of the same class as the copy. We only include trees with more than 2 elements here.
1098+
1099+
//def Select(tree: Select)(qualifier: Tree = tree.qualifier, name: Name = tree.name): Select =
1100+
// Select(tree: Tree)(qualifier, name)
1101+
//def Super(tree: Super)(qual: Tree = tree.qual, mix: TypeName = tree.mix): Super =
1102+
// Super(tree: Tree)(qual, mix)
1103+
//def Apply(tree: Apply)(fun: Tree = tree.fun, args: List[Tree] = tree.args): Apply =
1104+
// Apply(tree: Tree)(fun, args)
1105+
//def TypeApply(tree: TypeApply)(fun: Tree = tree.fun, args: List[Tree] = tree.args): TypeApply =
1106+
// TypeApply(tree: Tree)(fun, args)
1107+
//def Typed(tree: Typed)(expr: Tree = tree.expr, tpt: Tree = tree.tpt): Typed =
1108+
// Typed(tree: Tree)(expr, tpt)
1109+
//def NamedArg(tree: NamedArg)(name: Name = tree.name, arg: Tree = tree.arg): NamedArg =
1110+
// NamedArg(tree: Tree)(name, arg)
1111+
//def Assign(tree: Assign)(lhs: Tree = tree.lhs, rhs: Tree = tree.rhs): Assign =
1112+
// Assign(tree: Tree)(lhs, rhs)
1113+
//def Block(tree: Block)(stats: List[Tree] = tree.stats, expr: Tree = tree.expr): Block =
1114+
// Block(tree: Tree)(stats, expr)
11151115
def If(tree: If)(cond: Tree = tree.cond, thenp: Tree = tree.thenp, elsep: Tree = tree.elsep): If =
11161116
If(tree: Tree)(cond, thenp, elsep)
11171117
def Closure(tree: Closure)(env: List[Tree] = tree.env, meth: Tree = tree.meth, tpt: Tree = tree.tpt): Closure =
@@ -1120,20 +1120,20 @@ object Trees {
11201120
Match(tree: Tree)(selector, cases)
11211121
def CaseDef(tree: CaseDef)(pat: Tree = tree.pat, guard: Tree = tree.guard, body: Tree = tree.body): CaseDef =
11221122
CaseDef(tree: Tree)(pat, guard, body)
1123-
def Return(tree: Return)(expr: Tree = tree.expr, from: Tree = tree.from): Return =
1124-
Return(tree: Tree)(expr, from)
1123+
//def Return(tree: Return)(expr: Tree = tree.expr, from: Tree = tree.from): Return =
1124+
// Return(tree: Tree)(expr, from)
11251125
def Try(tree: Try)(expr: Tree = tree.expr, handler: Tree = tree.handler, finalizer: Tree = tree.finalizer): Try =
11261126
Try(tree: Tree)(expr, handler, finalizer)
1127-
def SelectFromTypeTree(tree: SelectFromTypeTree)(qualifier: Tree = tree.qualifier, name: Name = tree.name):
1128-
SelectFromTypeTree = SelectFromTypeTree(tree: Tree)(qualifier, name)
1129-
def RefinedTypeTree(tree: RefinedTypeTree)(tpt: Tree = tree.tpt, refinements: List[Tree] = tree.refinements):
1130-
RefinedTypeTree = RefinedTypeTree(tree: Tree)(tpt, refinements)
1131-
def AppliedTypeTree(tree: AppliedTypeTree)(tpt: Tree = tree.tpt, args: List[Tree] = tree.args): AppliedTypeTree =
1132-
AppliedTypeTree(tree: Tree)(tpt, args)
1133-
def TypeBoundsTree(tree: TypeBoundsTree)(lo: Tree = tree.lo, hi: Tree = tree.hi): TypeBoundsTree =
1134-
TypeBoundsTree(tree: Tree)(lo, hi)
1135-
def Bind(tree: Bind)(name: Name = tree.name, body: Tree = tree.body): Bind =
1136-
Bind(tree: Tree)(name, body)
1127+
//def SelectFromTypeTree(tree: SelectFromTypeTree)(qualifier: Tree = tree.qualifier, name: Name = tree.name):
1128+
// SelectFromTypeTree = SelectFromTypeTree(tree: Tree)(qualifier, name)
1129+
//def RefinedTypeTree(tree: RefinedTypeTree)(tpt: Tree = tree.tpt, refinements: List[Tree] = tree.refinements):
1130+
// RefinedTypeTree = RefinedTypeTree(tree: Tree)(tpt, refinements)
1131+
//def AppliedTypeTree(tree: AppliedTypeTree)(tpt: Tree = tree.tpt, args: List[Tree] = tree.args): AppliedTypeTree =
1132+
// AppliedTypeTree(tree: Tree)(tpt, args)
1133+
//def TypeBoundsTree(tree: TypeBoundsTree)(lo: Tree = tree.lo, hi: Tree = tree.hi): TypeBoundsTree =
1134+
// TypeBoundsTree(tree: Tree)(lo, hi)
1135+
//def Bind(tree: Bind)(name: Name = tree.name, body: Tree = tree.body): Bind =
1136+
// Bind(tree: Tree)(name, body)
11371137
def UnApply(tree: UnApply)(fun: Tree = tree.fun, implicits: List[Tree] = tree.implicits, patterns: List[Tree] = tree.patterns): UnApply =
11381138
UnApply(tree: Tree)(fun, implicits, patterns)
11391139
def ValDef(tree: ValDef)(mods: Modifiers = tree.mods, name: TermName = tree.name, tpt: Tree = tree.tpt, rhs: Tree = tree.rhs): ValDef =
@@ -1144,12 +1144,12 @@ object Trees {
11441144
TypeDef(tree: Tree)(mods, name, rhs, tparams)
11451145
def Template(tree: Template)(constr: DefDef = tree.constr, parents: List[Tree] = tree.parents, self: ValDef = tree.self, body: List[Tree] = tree.body): Template =
11461146
Template(tree: Tree)(constr, parents, self, body)
1147-
def Import(tree: Import)(expr: Tree = tree.expr, selectors: List[untpd.Tree] = tree.selectors): Import =
1148-
Import(tree: Tree)(expr, selectors)
1149-
def PackageDef(tree: PackageDef)(pid: RefTree = tree.pid, stats: List[Tree] = tree.stats): PackageDef =
1150-
PackageDef(tree: Tree)(pid, stats)
1151-
def Annotated(tree: Annotated)(annot: Tree = tree.annot, arg: Tree = tree.arg): Annotated =
1152-
Annotated(tree: Tree)(annot, arg)
1147+
//def Import(tree: Import)(expr: Tree = tree.expr, selectors: List[untpd.Tree] = tree.selectors): Import =
1148+
// Import(tree: Tree)(expr, selectors)
1149+
//def PackageDef(tree: PackageDef)(pid: RefTree = tree.pid, stats: List[Tree] = tree.stats): PackageDef =
1150+
// PackageDef(tree: Tree)(pid, stats)
1151+
//def Annotated(tree: Annotated)(annot: Tree = tree.annot, arg: Tree = tree.arg): Annotated =
1152+
// Annotated(tree: Tree)(annot, arg)
11531153
}
11541154

11551155
abstract class TreeMap(val cpy: TreeCopier = inst.cpy) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Nullarify extends MiniPhaseTransform with InfoTransformer {
7272
val MethodType(_, formals) = methType(funType, tree.fun)
7373

7474
val args1 = tree.args.zipWithConserve(formals)(transformArg)
75-
cpy.Apply(tree)(args = args1) withType nullarify(tree.tpe)
75+
cpy.Apply(tree)(tree.fun, args1) withType nullarify(tree.tpe)
7676
}
7777

7878
/** Insert () or .apply() if the term refers to something that was converted to a

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class UncurryTreeTransform extends MiniPhaseTransform with InfoTransformer {
2323
showType
2424
ctx.atNextPhase(showType(_))
2525
showType
26-
cpy.Apply(tree)(args = args ++ tree.args)
26+
cpy.Apply(tree)(tree.fun, args ++ tree.args)
2727
case _ => tree
2828
}}
2929

src/dotty/tools/dotc/typer/ReTyper.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ class ReTyper extends Typer {
3232
override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = {
3333
assert(tree.hasType)
3434
val qual1 = typed(tree.qualifier, AnySelectionProto)
35-
untpd.cpy.Select(tree)(qualifier = qual1).withType(tree.typeOpt)
35+
untpd.cpy.Select(tree)(qual1, tree.name).withType(tree.typeOpt)
3636
}
3737

3838
override def typedSelectFromTypeTree(tree: untpd.SelectFromTypeTree, pt: Type)(implicit ctx: Context): SelectFromTypeTree = {
3939
assert(tree.hasType)
4040
val qual1 = typed(tree.qualifier, AnySelectionProto)
41-
untpd.cpy.SelectFromTypeTree(tree)(qualifier = qual1).withType(tree.typeOpt)
41+
untpd.cpy.SelectFromTypeTree(tree)(qual1, tree.name).withType(tree.typeOpt)
4242
}
4343

4444
override def typedLiteral(tree: untpd.Literal)(implicit ctc: Context): Literal =
@@ -50,7 +50,7 @@ class ReTyper extends Typer {
5050
override def typedBind(tree: untpd.Bind, pt: Type)(implicit ctx: Context): Bind = {
5151
assert(tree.hasType)
5252
val body1 = typed(tree.body, pt)
53-
untpd.cpy.Bind(tree)(body = body1).withType(tree.typeOpt)
53+
untpd.cpy.Bind(tree)(tree.name, body1).withType(tree.typeOpt)
5454
}
5555

5656
override def localDummy(cls: ClassSymbol, impl: untpd.Template)(implicit ctx: Context) = impl.symbol

0 commit comments

Comments
 (0)