Skip to content
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 @@ -10,6 +10,7 @@ import core.Contexts.{Context, ctx, inContext}
import core.DenotTransformers.IdentityDenotTransformer
import core.Symbols.{defn, Symbol}
import core.Constants.Constant
import core.NameKinds.DefaultGetterName
import core.NameOps.isContextFunction
import core.StdNames.nme
import core.Types.*
Expand Down Expand Up @@ -554,6 +555,7 @@ class InstrumentCoverage extends MacroTransform with IdentityDenotTransformer:
!sym.isOneOf(ExcludeMethodFlags)
&& !isCompilerIntrinsicMethod(sym)
&& !(sym.isClassConstructor && isSecondaryCtorDelegateCall)
&& !sym.name.is(DefaultGetterName) // https://github.com/scala/scala3/issues/20255
&& (tree.typeOpt match
case AppliedType(tycon: NamedType, _) =>
/* If the last expression in a block is a context function, we'll try to
Expand Down Expand Up @@ -590,6 +592,7 @@ class InstrumentCoverage extends MacroTransform with IdentityDenotTransformer:
&& sym.info.isParameterless
&& !isCompilerIntrinsicMethod(sym)
&& !sym.info.typeSymbol.name.isContextFunction // exclude context functions like in canInstrumentApply
&& !sym.name.is(DefaultGetterName) // https://github.com/scala/scala3/issues/20255

/** Does sym refer to a "compiler intrinsic" method, which only exist during compilation,
* like Any.isInstanceOf?
Expand Down
29 changes: 29 additions & 0 deletions tests/coverage/pos/DefaultArgs.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package covtest

// Test case for default arguments with coverage.
// Default getter methods ($default$N) should not be instrumented/lifted
// as this can cause issues with ScalaJS IR (https://github.com/scala/scala3/issues/20255).

class DefaultArgs:
def methodWithDefaults(
a: String,
b: Int = 0,
c: Boolean = true
): String =
s"$a, $b, $c"

def caller(): String =
// This call uses default arguments for b and c
methodWithDefaults("test")

def callerPartial(): String =
// This call uses default argument only for c
methodWithDefaults("test", 42)

object DefaultArgs:
def staticMethod(x: Int = 10, y: Int = 20): Int =
x + y

def staticCaller(): Int =
staticMethod() + staticMethod(5) + staticMethod(5, 15)

Loading
Loading