File tree 3 files changed +11
-2
lines changed
compiler/src/dotty/tools/dotc
3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -134,7 +134,8 @@ public enum ErrorMessageID {
134
134
TermMemberNeedsNeedsResultTypeForImplicitSearchID ,
135
135
CaseClassCannotExtendEnumID ,
136
136
ValueClassParameterMayNotBeCallByNameID ,
137
- NotAnExtractorID
137
+ NotAnExtractorID ,
138
+ PureExpressionInStatementPositionID
138
139
;
139
140
140
141
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -2131,4 +2131,12 @@ object messages {
2131
2131
|For this reason, you can also define patterns through `unapplySeq` which returns `Option[Seq[T]]`.
2132
2132
|This mechanism is used for instance in pattern `case List(x1, ..., xn)` """ .stripMargin
2133
2133
}
2134
+
2135
+ case class PureExpressionInStatementPosition (stat : untpd.Tree , exprOwner : Symbol )(implicit ctx : Context ) extends Message (PureExpressionInStatementPositionID ) {
2136
+ val kind = " Potential Issue"
2137
+ val msg = " a pure expression does nothing in statement position; you may be omitting necessary parentheses"
2138
+ val explanation =
2139
+ hl """ The pure expression ` $stat` doesn't have any side effect and its result is not assigned elsewhere.
2140
+ |It can be removed without changing the semantics of the program. This may indicate an error. """ .stripMargin
2141
+ }
2134
2142
}
Original file line number Diff line number Diff line change @@ -2026,7 +2026,7 @@ class Typer extends Namer
2026
2026
val stat1 = typed(stat)(ctx.exprContext(stat, exprOwner))
2027
2027
if (! ctx.isAfterTyper && isPureExpr(stat1) &&
2028
2028
! stat1.tpe.isRef(defn.UnitClass ) && ! isSelfOrSuperConstrCall(stat1))
2029
- ctx.warning(em " a pure expression does nothing in statement position " , stat.pos)
2029
+ ctx.warning(PureExpressionInStatementPosition (stat, exprOwner) , stat.pos)
2030
2030
buf += stat1
2031
2031
traverse(rest)
2032
2032
case nil =>
You can’t perform that action at this time.
0 commit comments