Skip to content

Commit 52236dc

Browse files
Final fixes for -Wvalue-discard (#16637)
2 parents 667d904 + dc99b55 commit 52236dc

File tree

1 file changed

+8
-90
lines changed

1 file changed

+8
-90
lines changed

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

Lines changed: 8 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -327,102 +327,20 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
327327
case _ => p(tree)
328328
}
329329

330-
/** Applications in Scala can have one of the following shapes:
331-
*
332-
* 1) naked core: Ident(_) or Select(_, _) or basically anything else
333-
* 2) naked core with targs: TypeApply(core, targs) or AppliedTypeTree(core, targs)
334-
* 3) apply or several applies wrapping a core: Apply(core, _), or Apply(Apply(core, _), _), etc
335-
*
336-
* This class provides different ways to decompose applications and simplifies their analysis.
337-
*
338-
* ***Examples***
339-
* (TypeApply in the examples can be replaced with AppliedTypeTree)
340-
*
341-
* Ident(foo):
342-
* * callee = Ident(foo)
343-
* * core = Ident(foo)
344-
* * targs = Nil
345-
* * argss = Nil
346-
*
347-
* TypeApply(foo, List(targ1, targ2...))
348-
* * callee = TypeApply(foo, List(targ1, targ2...))
349-
* * core = foo
350-
* * targs = List(targ1, targ2...)
351-
* * argss = Nil
352-
*
353-
* Apply(foo, List(arg1, arg2...))
354-
* * callee = foo
355-
* * core = foo
356-
* * targs = Nil
357-
* * argss = List(List(arg1, arg2...))
358-
*
359-
* Apply(Apply(foo, List(arg21, arg22, ...)), List(arg11, arg12...))
360-
* * callee = foo
361-
* * core = foo
362-
* * targs = Nil
363-
* * argss = List(List(arg21, arg22, ...), List(arg11, arg12, ...))
364-
*
365-
* Apply(Apply(TypeApply(foo, List(targs1, targs2, ...)), List(arg21, arg22, ...)), List(arg11, arg12...))
366-
* * callee = TypeApply(foo, List(targs1, targs2, ...))
367-
* * core = foo
368-
* * targs = Nil
369-
* * argss = List(List(arg21, arg22, ...), List(arg11, arg12, ...))
370-
*/
371-
final class Applied(val tree: Tree) {
372-
/** The tree stripped of the possibly nested applications.
373-
* The original tree if it's not an application.
374-
*/
375-
def callee: Tree = stripApply(tree)
376-
377-
/** The `callee` unwrapped from type applications.
378-
* The original `callee` if it's not a type application.
379-
*/
380-
def core: Tree = callee match {
381-
case TypeApply(fn, _) => fn
382-
case AppliedTypeTree(fn, _) => fn
383-
case tree => tree
384-
}
385-
386-
/** The type arguments of the `callee`.
387-
* `Nil` if the `callee` is not a type application.
388-
*/
389-
def targs: List[Tree] = callee match {
390-
case TypeApply(_, args) => args
391-
case AppliedTypeTree(_, args) => args
392-
case _ => Nil
393-
}
394-
395-
/** (Possibly multiple lists of) value arguments of an application.
396-
* `Nil` if the `callee` is not an application.
397-
*/
398-
def argss: List[List[Tree]] = termArgss(tree)
399-
}
400-
401-
/** Destructures applications into important subparts described in `Applied` class,
402-
* namely into: core, targs and argss (in the specified order).
403-
*
404-
* Trees which are not applications are also accepted. Their callee and core will
405-
* be equal to the input, while targs and argss will be Nil.
406-
*
407-
* The provided extractors don't expose all the API of the `Applied` class.
408-
* For advanced use, call `dissectApplied` explicitly and use its methods instead of pattern matching.
409-
*/
410-
object Applied {
411-
def apply(tree: Tree): Applied = new Applied(tree)
412-
413-
def unapply(applied: Applied): Some[(Tree, List[Tree], List[List[Tree]])] =
414-
Some((applied.core, applied.targs, applied.argss))
415-
416-
def unapply(tree: Tree): Some[(Tree, List[Tree], List[List[Tree]])] =
417-
unapply(new Applied(tree))
330+
def appliedCore(tree: Tree): Tree = tree match {
331+
case Apply(fn, _) => appliedCore(fn)
332+
case TypeApply(fn, _) => appliedCore(fn)
333+
case AppliedTypeTree(fn, _) => appliedCore(fn)
334+
case tree => tree
418335
}
419336

420337
/** Is tree an application with result `this.type`?
421338
* Accept `b.addOne(x)` and also `xs(i) += x`
422339
* where the op is an assignment operator.
423340
*/
424-
def isThisTypeResult(tree: Tree)(using Context): Boolean = tree match {
425-
case Applied(fun @ Select(receiver, op), _, argss) =>
341+
def isThisTypeResult(tree: Tree)(using Context): Boolean = appliedCore(tree) match {
342+
case fun @ Select(receiver, op) =>
343+
val argss = termArgss(tree)
426344
tree.tpe match {
427345
case ThisType(tref) =>
428346
tref.symbol == receiver.symbol

0 commit comments

Comments
 (0)