Skip to content

Don't lift the argument of a synchronized block in scoverage #16941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ class InstrumentCoverage extends MacroTransform with IdentityDenotTransformer:
* they shouldn't be lifted.
*/
val sym = fun.symbol
sym.exists && (isShortCircuitedOp(sym) || StringInterpolatorOpt.isCompilerIntrinsic(sym))
sym.exists && (isShortCircuitedOp(sym) || StringInterpolatorOpt.isCompilerIntrinsic(sym) || sym == defn.Object_synchronized)
end

val fun = tree.fun
Expand Down
30 changes: 30 additions & 0 deletions tests/run/i16940.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// scalac: -coverage-out:coverage
// scalajs: --skip

import concurrent.ExecutionContext.Implicits.global
import scala.concurrent.*
import scala.concurrent.duration.*

var test = 0

def brokenSynchronizedBlock(option: Boolean): Future[Unit] = Future {
if (option) {
Thread.sleep(500)
}
synchronized {
val tmp = test
Thread.sleep(1000)
test = tmp + 1
}
}

object Test extends App {
Await.result(
Future.sequence(Seq(brokenSynchronizedBlock(false), brokenSynchronizedBlock(true)))
.map { result =>
println(test)
assert(test == 2)
},
3.seconds
)
}