Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: scala/scala3
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e73a7bc7007260dada130832d2774a64d5ea0de5
Choose a base ref
..
head repository: scala/scala3
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 02fd9ded5c582a528408ffdd6dd9926f4bcb6ed6
Choose a head ref
Showing with 7 additions and 9 deletions.
  1. +7 −9 compiler/src/dotty/tools/dotc/transform/InstrumentCoverage.scala
16 changes: 7 additions & 9 deletions compiler/src/dotty/tools/dotc/transform/InstrumentCoverage.scala
Original file line number Diff line number Diff line change
@@ -70,11 +70,12 @@ class InstrumentCoverage extends MacroTransform with IdentityDenotTransformer:
* ```
* where DIR is the _outputPath_ defined by the coverage settings.
*/
private def invokeCall(id: Int, span: Span)(using Context): GenericApply =
private def invokeCall(id: Int, span: Span)(using Context): Apply =
ref(defn.InvokedMethodRef).withSpan(span)
.appliedToArgs(
Literal(Constant(id)) :: Literal(ConstOutputPath) :: Nil
).withSpan(span)
.asInstanceOf[Apply]

/**
* Records information about a new coverable statement. Generates a unique id for it.
@@ -119,7 +120,7 @@ class InstrumentCoverage extends MacroTransform with IdentityDenotTransformer:
private def createInvokeCall(tree: Tree, pos: SourcePosition, branch: Boolean = false)(using Context): Apply =
val statementId = recordStatement(tree, pos, branch)
val span = pos.span.toSynthetic
invokeCall(statementId, span).asInstanceOf[Apply]
invokeCall(statementId, span)

/**
* Tries to instrument an `Apply`.
@@ -364,9 +365,10 @@ class InstrumentCoverage extends MacroTransform with IdentityDenotTransformer:
// args are types, instrument the fun with transformParent
cpy.TypeApply(tree)(transformParent(tree.fun), tree.args)
case other =>
transform(other)
// should always be a TypeTree, nothing to instrument
other

parents.map(transformParent)
parents.mapConserve(transformParent)

/** Instruments the body of a DefDef. Handles corner cases.
* Given a DefDef f like this:
@@ -508,7 +510,7 @@ object InstrumentCoverage:
* @param invokeCall call to Invoker.invoked(dir, id), or an empty tree.
* @param expr the instrumented expression, executed just after the invokeCall
*/
case class InstrumentedParts(pre: List[Tree], invokeCall: Apply | Thicket, expr: Tree):
case class InstrumentedParts(pre: List[Tree], invokeCall: Apply | EmptyTree.type, expr: Tree):
require(pre.isEmpty || (pre.nonEmpty && !invokeCall.isEmpty), "if pre isn't empty then invokeCall shouldn't be empty")

/** Turns this into an actual Tree. */
@@ -517,10 +519,6 @@ object InstrumentCoverage:
else if pre.isEmpty then Block(invokeCall :: Nil, expr)
else Block(pre :+ invokeCall, expr)

/** Applies a function on the instrumented expression. */
def map(f: Tree => Tree): InstrumentedParts =
InstrumentedParts(pre, invokeCall, f(expr))

object InstrumentedParts:
def notCovered(expr: Tree) = InstrumentedParts(Nil, EmptyTree, expr)
def singleExpr(invokeCall: Apply, expr: Tree) = InstrumentedParts(Nil, invokeCall, expr)