scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Compiler incorrectly warns about pure volatile reads #9053

Open scabug opened 9 years ago

scabug commented 9 years ago

Scala 2.11 warns about pure expressions in statement position. This warning is incorrect for volatile reads. A volatile read has the side-effect of inserting a memory read barrier (which must not be optimized away by the JIT even when the actual read is unnecessary and can be removed).

[warn] /Users/szeiger/code/slick/src/main/scala/scala/slick/backend/DatabaseComponent.scala:190: a pure expression does nothing in statement position; you may be omitting necessary parentheses
[warn]             ctx.sync
[warn]                 ^
scabug commented 9 years ago

Imported From: https://issues.scala-lang.org/browse/SI-9053?orig=1 Reporter: @szeiger Affected Versions: 2.11.2, 2.11.4

scabug commented 9 years ago

@szeiger said: Checking the bytecode, the volatile reads are still generated (as they should be). It's just the warning that is wrong.

scabug commented 9 years ago

@retronym said: WIP: https://github.com/retronym/scala/compare/scala:2.11.x...retronym:ticket/9053?expand=1

scabug commented 9 years ago

@retronym said: Workaround if you want to silence to warning:

  def volatileRead() = ctx.sync
  volatileRead()