@@ -159,23 +159,39 @@ class LiftComplex extends Lifter {
159159}
160160object LiftComplex extends LiftComplex
161161
162- /** Lift complex + lift the prefixes */
163- object LiftCoverage extends LiftComplex {
162+ /** Lift impure + lift the prefixes */
163+ object LiftCoverage extends LiftImpure {
164164
165- private val LiftEverything = new Property .Key [Boolean ]
165+ // Property indicating whether we're currently lifting the arguments of an application
166+ private val LiftingArgs = new Property .Key [Boolean ]
166167
167- private inline def liftEverything (using Context ): Boolean =
168- ctx.property(LiftEverything ).contains(true )
168+ private inline def liftingArgs (using Context ): Boolean =
169+ ctx.property(LiftingArgs ).contains(true )
169170
170- private def liftEverythingContext (using Context ): Context =
171- ctx.fresh.setProperty(LiftEverything , true )
171+ private def liftingArgsContext (using Context ): Context =
172+ ctx.fresh.setProperty(LiftingArgs , true )
173+
174+ /** Variant of `noLift` for the arguments of applications.
175+ * To produce the right coverage information (especially in case of exceptions), we must lift:
176+ * - all the applications, except the erased ones
177+ * - all the impure arguments
178+ *
179+ * There's no need to lift the other arguments.
180+ */
181+ private def noLiftArg (arg : tpd.Tree )(using Context ): Boolean =
182+ arg match
183+ case a : tpd.Apply => a.symbol.is(Erased ) // don't lift erased applications, but lift all others
184+ case tpd.Block (stats, expr) => stats.forall(noLiftArg) && noLiftArg(expr)
185+ case tpd.Inlined (_, bindings, expr) => noLiftArg(expr)
186+ case tpd.Typed (expr, _) => noLiftArg(expr)
187+ case _ => super .noLift(arg)
172188
173189 override def noLift (expr : tpd.Tree )(using Context ) =
174- ! liftEverything && super .noLift(expr)
190+ if liftingArgs then noLiftArg(expr) else super .noLift(expr)
175191
176192 def liftForCoverage (defs : mutable.ListBuffer [tpd.Tree ], tree : tpd.Apply )(using Context ) = {
177193 val liftedFun = liftApp(defs, tree.fun)
178- val liftedArgs = liftArgs(defs, tree.fun.tpe, tree.args)(using liftEverythingContext )
194+ val liftedArgs = liftArgs(defs, tree.fun.tpe, tree.args)(using liftingArgsContext )
179195 tpd.cpy.Apply (tree)(liftedFun, liftedArgs)
180196 }
181197}
0 commit comments