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 {
135
135
CaseClassCannotExtendEnumID ,
136
136
ValueClassParameterMayNotBeCallByNameID ,
137
137
NotAnExtractorID ,
138
- MemberWithSameNameAsStaticID
138
+ MemberWithSameNameAsStaticID ,
139
+ PureExpressionInStatementPositionID
139
140
;
140
141
141
142
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -2139,4 +2139,14 @@ object messages {
2139
2139
override def kind : String = " Syntax"
2140
2140
override def explanation : String = " "
2141
2141
}
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
+ }
2142
2152
}
Original file line number Diff line number Diff line change @@ -2013,7 +2013,7 @@ class Typer extends Namer
2013
2013
val stat1 = typed(stat)(ctx.exprContext(stat, exprOwner))
2014
2014
if (! ctx.isAfterTyper && isPureExpr(stat1) &&
2015
2015
! 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)
2017
2017
buf += stat1
2018
2018
traverse(rest)
2019
2019
case nil =>
You can’t perform that action at this time.
0 commit comments