File tree Expand file tree Collapse file tree 3 files changed +13
-2
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,8 @@ public enum ErrorMessageID {
135135 CaseClassCannotExtendEnumID ,
136136 ValueClassParameterMayNotBeCallByNameID ,
137137 NotAnExtractorID ,
138- MemberWithSameNameAsStaticID
138+ MemberWithSameNameAsStaticID ,
139+ PureExpressionInStatementPositionID
139140 ;
140141
141142 public int errorNumber () {
Original file line number Diff line number Diff line change @@ -2139,4 +2139,14 @@ object messages {
21392139 override def kind : String = " Syntax"
21402140 override def explanation : String = " "
21412141 }
2142+
2143+ case class PureExpressionInStatementPosition (stat : untpd.Tree , exprOwner : Symbol )(implicit ctx : Context )
2144+ extends Message (PureExpressionInStatementPositionID ) {
2145+
2146+ val kind = " Potential Issue"
2147+ val msg = " a pure expression does nothing in statement position; you may be omitting necessary parentheses"
2148+ val explanation =
2149+ hl """ The pure expression ` $stat` doesn't have any side effect and its result is not assigned elsewhere.
2150+ |It can be removed without changing the semantics of the program. This may indicate an error. """ .stripMargin
2151+ }
21422152}
Original file line number Diff line number Diff line change @@ -2013,7 +2013,7 @@ class Typer extends Namer
20132013 val stat1 = typed(stat)(ctx.exprContext(stat, exprOwner))
20142014 if (! ctx.isAfterTyper && isPureExpr(stat1) &&
20152015 ! stat1.tpe.isRef(defn.UnitClass ) && ! isSelfOrSuperConstrCall(stat1))
2016- ctx.warning(em " a pure expression does nothing in statement position " , stat.pos)
2016+ ctx.warning(PureExpressionInStatementPosition (stat, exprOwner) , stat.pos)
20172017 buf += stat1
20182018 traverse(rest)
20192019 case nil =>
You can’t perform that action at this time.
0 commit comments