Skip to content

Commit

Permalink
TreeOps: statements don't start on a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 20, 2024
1 parent b3e0e45 commit 14a940f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ object TreeOps {
val ret = Map.newBuilder[Int, Tree]
ret.sizeHint(tree.tokens.length)

def addFT(ft: FormatToken, tree: Tree): Unit = ret += ft.meta.idx -> tree
def addTok(token: Token, tree: Tree) = addFT(ftoks.after(token), tree)
def addTree(t: Tree, o: Tree) = ftoks.getHeadOpt(t).foreach(addFT(_, o))
def addFT(stmt: Tree)(ft: FormatToken): Unit = {
val isComment = ft.left.is[Token.Comment]
val nft = if (isComment) ftoks.nextAfterNonComment(ft) else ft
ret += nft.meta.idx -> stmt
}
def addTok(stmt: Tree)(token: Token) = addFT(stmt)(ftoks.after(token))
def addTree(t: Tree, stmt: Tree) = ftoks.getHeadOpt(t).foreach(addFT(stmt))
def addOne(t: Tree) = addTree(t, t)
def addAll(trees: Seq[Tree]) = trees.foreach(addOne)

Expand All @@ -142,10 +146,8 @@ object TreeOps {
case Some(x) => addTree(x, tree)
case _ =>
// No non-annotation modifier exists, fallback to keyword like `object`
tree.tokens.find(isMatch) match {
case Some(x) => addTok(x, tree)
case None => throw Error.CantFindDefnToken(what, tree)
}
tree.tokens.find(isMatch)
.fold(throw Error.CantFindDefnToken(what, tree))(addTok(tree))
}
}
def addDefn[T](mods: Seq[Mod], tree: Tree)(implicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,23 +267,21 @@ object a {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
base.info.parents.tail
- .forall {
- p => // - every mixin parent is unrelated to (not a subclass of) low and high, i.e.,
- val psym =
- p.typeSymbol // we're not mixing in high or low, both are coming from the superclass
- !psym.isNonBottomSubClass(lowClass) && !psym.isNonBottomSubClass(
- highClass
- )
+ .forall { p => // - every mixin parent is unrelated to (not a subclass of) low and high, i.e.,
+ val psym =
+ p.typeSymbol // we're not mixing in high or low, both are coming from the superclass
+ !psym.isNonBottomSubClass(lowClass) && !psym.isNonBottomSubClass(
+ highClass
+ )
}
object a {
lowClass.isJavaDefined && highClass.isJavaDefined && { // skip if both are java-defined, and
lowClass
.isNonBottomSubClass(highClass) || { // - low <:< high, which means they are overrides in Java and javac is doing the check; or
base.info.parents.tail.forall {
p => // - every mixin parent is unrelated to (not a subclass of) low and high, i.e.,
val psym =
p.typeSymbol // we're not mixing in high or low, both are coming from the superclass
!psym.isNonBottomSubClass(lowClass) && !psym.isNonBottomSubClass(
highClass
)
}
}
}
}
<<< #4133 lambda body without a comment
rewrite.redundantBraces.maxLines = 100
===
Expand Down

0 comments on commit 14a940f

Please sign in to comment.