Skip to content

Commit f97a640

Browse files
committed
Lift arguments to defs instead of vals in coverage
possible fix for lampepfl#16940
1 parent ce1ca44 commit f97a640

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ object LiftCoverage extends LiftImpure {
194194
val liftedArgs = liftArgs(defs, tree.fun.tpe, tree.args)(using liftingArgsContext)
195195
tpd.cpy.Apply(tree)(liftedFun, liftedArgs)
196196
}
197+
198+
override def liftedFlags: FlagSet = Method
199+
200+
override def liftedDef(sym: TermSymbol, rhs: tpd.Tree)(using Context): tpd.DefDef = tpd.DefDef(sym, rhs)
197201
}
198202

199203
object LiftErased extends LiftComplex:

tests/run/i16940.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// scalac: -coverage-out:coverage
2+
3+
import concurrent.ExecutionContext.Implicits.global
4+
import scala.concurrent.*
5+
import scala.concurrent.duration.*
6+
7+
var test = 0
8+
9+
def brokenSynchronizedBlock(option: Boolean): Future[Unit] = Future {
10+
if (option) {
11+
Thread.sleep(500)
12+
}
13+
synchronized {
14+
val tmp = test
15+
Thread.sleep(1000)
16+
test = tmp + 1
17+
}
18+
}
19+
20+
object Test extends App {
21+
Await.result(
22+
Future.sequence(Seq(brokenSynchronizedBlock(false), brokenSynchronizedBlock(true)))
23+
.map { result =>
24+
println(test)
25+
assert(test == 2)
26+
},
27+
3.seconds
28+
)
29+
}

0 commit comments

Comments
 (0)