@@ -35,7 +35,7 @@ import util.common.*
35
35
import util .{Property , SimpleIdentityMap , SrcPos }
36
36
import Applications .{tupleComponentTypes , wrapDefs , defaultArgument }
37
37
38
- import collection .mutable
38
+ import collection .mutable , mutable . ListBuffer
39
39
import Implicits .*
40
40
import util .Stats .record
41
41
import config .Printers .{gadts , typr }
@@ -207,7 +207,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
207
207
* a reference for `m` is searched. `null` in all other situations.
208
208
*/
209
209
def findRef (name : Name , pt : Type , required : FlagSet , excluded : FlagSet , pos : SrcPos ,
210
- altImports : mutable. ListBuffer [TermRef ] | Null = null )(using Context ): Type = {
210
+ altImports : ListBuffer [TermRef ] | Null = null )(using Context ): Type = {
211
211
val refctx = ctx
212
212
val noImports = ctx.mode.is(Mode .InPackageClauseName )
213
213
def suppressErrors = excluded.is(ConstructorProxy )
@@ -3435,7 +3435,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3435
3435
else {
3436
3436
val app = typedApply(desugar.binop(l, op, r).withAttachmentsFrom(tree), pt)
3437
3437
if op.name.isRightAssocOperatorName && ! ctx.mode.is(Mode .QuotedExprPattern ) then
3438
- val defs = new mutable. ListBuffer [Tree ]
3438
+ val defs = ListBuffer .empty [Tree ]
3439
3439
def lift (app : Tree ): Tree = (app : @ unchecked) match
3440
3440
case Apply (fn, args) =>
3441
3441
if (app.tpe.isError) app
@@ -3735,7 +3735,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3735
3735
trees mapconserve (typed(_))
3736
3736
3737
3737
def typedStats (stats : List [untpd.Tree ], exprOwner : Symbol )(using Context ): (List [Tree ], Context ) = {
3738
- val buf = new mutable. ListBuffer [Tree ]
3738
+ val buf = ListBuffer .empty [Tree ]
3739
3739
var enumContexts : SimpleIdentityMap [Symbol , Context ] = SimpleIdentityMap .empty
3740
3740
val initialNotNullInfos = ctx.notNullInfos
3741
3741
// A map from `enum` symbols to the contexts enclosing their definitions
@@ -3779,7 +3779,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3779
3779
traverse(xtree :: rest)
3780
3780
case stat :: rest =>
3781
3781
val stat1 = typed(stat)(using ctx.exprContext(stat, exprOwner))
3782
- if ! Linter .warnOnInterestingResultInStatement(stat1) then checkStatementPurity(stat1)(stat, exprOwner)
3782
+ if ! Linter .warnOnInterestingResultInStatement(stat1) then
3783
+ checkStatementPurity(stat1)(stat, exprOwner, isUnitExpr = false )
3783
3784
buf += stat1
3784
3785
traverse(rest)(using stat1.nullableContext)
3785
3786
case nil =>
@@ -3986,7 +3987,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3986
3987
def selectionProto = SelectionProto (tree.name, mbrProto, compat, privateOK = inSelect, tree.nameSpan)
3987
3988
3988
3989
def tryExtension (using Context ): Tree =
3989
- val altImports = new mutable. ListBuffer [TermRef ]()
3990
+ val altImports = ListBuffer .empty [TermRef ]
3990
3991
findRef(tree.name, WildcardType , ExtensionMethod , EmptyFlags , qual.srcPos, altImports) match
3991
3992
case ref : TermRef =>
3992
3993
def tryExtMethod (ref : TermRef )(using Context ) =
@@ -3995,7 +3996,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3995
3996
tryExtMethod(ref)
3996
3997
else
3997
3998
// Try all possible imports and collect successes and failures
3998
- val successes, failures = new mutable. ListBuffer [(Tree , TyperState )]
3999
+ val successes, failures = ListBuffer .empty [(Tree , TyperState )]
3999
4000
for alt <- ref :: altImports.toList do
4000
4001
val nestedCtx = ctx.fresh.setNewTyperState()
4001
4002
val app = tryExtMethod(alt)(using nestedCtx)
@@ -4653,19 +4654,19 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4653
4654
return readapt(tree.cast(captured))
4654
4655
4655
4656
// drop type if prototype is Unit
4656
- if (pt isRef defn.UnitClass ) {
4657
+ if (pt. isRef( defn.UnitClass ) ) {
4657
4658
// local adaptation makes sure every adapted tree conforms to its pt
4658
4659
// so will take the code path that decides on inlining
4659
4660
val tree1 = adapt(tree, WildcardType , locked)
4660
4661
checkStatementPurity(tree1)(tree, ctx.owner, isUnitExpr = true )
4661
4662
4662
- if ctx.settings.Whas .valueDiscard
4663
- && ! ctx.isAfterTyper
4664
- && ! tree. isInstanceOf [ Inlined ]
4665
- && ! isThisTypeResult( tree)
4666
- && ! tree .hasAttachment(AscribedToUnit ) then
4667
- report.warning( ValueDiscarding (tree.tpe), tree.srcPos)
4668
-
4663
+ if ctx.settings.Whas .valueDiscard && ! ctx.isAfterTyper then
4664
+ val warnable = tree match
4665
+ case inlined : Inlined => inlined.expansion
4666
+ case tree => tree
4667
+ if ! isThisTypeResult(warnable) && ! warnable .hasAttachment(AscribedToUnit )
4668
+ then
4669
+ report.warning( ValueDiscarding (warnable.tpe), tree.srcPos)
4669
4670
return tpd.Block (tree1 :: Nil , unitLiteral)
4670
4671
}
4671
4672
@@ -4925,7 +4926,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4925
4926
typedExpr(cmp, defn.BooleanType )
4926
4927
case _ =>
4927
4928
4928
- private def checkStatementPurity (tree : tpd.Tree )(original : untpd.Tree , exprOwner : Symbol , isUnitExpr : Boolean = false )(using Context ): Unit =
4929
+ private def checkStatementPurity (tree : tpd.Tree )(original : untpd.Tree , exprOwner : Symbol , isUnitExpr : Boolean )(using Context ): Unit =
4929
4930
if ! tree.tpe.isErroneous
4930
4931
&& ! ctx.isAfterTyper
4931
4932
&& ! tree.isInstanceOf [Inlined ]
0 commit comments