Skip to content

Commit 02f329c

Browse files
committed
Make withMods produce Untyped trees
withMods should never be used to produce a typed tree, because typed member defs get their modifiers from their symbols.
1 parent f7a4d81 commit 02f329c

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,13 @@ object Trees {
444444
private[ast] def rawMods: Modifiers[T] =
445445
if (myMods == null) genericEmptyModifiers else myMods
446446

447-
def withMods(mods: Modifiers[T @uncheckedVariance]): ThisTree[T] = { // TODO move to untpd.modsDeco?
448-
val tree = if (myMods == null || (myMods == mods)) this else clone.asInstanceOf[MemberDef[T]]
447+
def withMods(mods: Modifiers[Untyped]): ThisTree[Untyped] = {
448+
val tree = if (myMods == null || (myMods == mods)) this else clone.asInstanceOf[MemberDef[Untyped]]
449449
tree.setMods(mods)
450-
tree.asInstanceOf[ThisTree[T]]
450+
tree.asInstanceOf[ThisTree[Untyped]]
451451
}
452452

453-
def withFlags(flags: FlagSet): ThisTree[T] = withMods(Modifiers(flags))
453+
def withFlags(flags: FlagSet): ThisTree[Untyped] = withMods(Modifiers(flags))
454454

455455
protected def setMods(mods: Modifiers[T @uncheckedVariance]) = myMods = mods
456456

@@ -1253,13 +1253,10 @@ object Trees {
12531253
val tpt1 = transform(tpt)
12541254
val rhs1 = transform(rhs)
12551255
cpy.ValDef(tree)(name, transform(tpt1), transform(rhs1))
1256-
.withMods(tree.rawMods)
12571256
case tree @ DefDef(name, tparams, vparamss, tpt, rhs) =>
12581257
cpy.DefDef(tree)(name, transformSub(tparams), vparamss mapConserve (transformSub(_)), transform(tpt), transform(rhs))
1259-
.withMods(tree.rawMods)
12601258
case tree @ TypeDef(name, rhs) =>
12611259
cpy.TypeDef(tree)(name, transform(rhs), tree.tparams)
1262-
.withMods(tree.rawMods)
12631260
case Template(constr, parents, self, body) =>
12641261
cpy.Template(tree)(transformSub(constr), transform(parents), transformSub(self), transformStats(body))
12651262
case Import(expr, selectors) =>

0 commit comments

Comments
 (0)