Skip to content

Commit 7930004

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

File tree

2 files changed

+34
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)