Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update filter for Kotlin 1.5 suspending functions #1174

Merged
merged 3 commits into from Apr 13, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -130,6 +130,17 @@ public void should_not_filter_synthetic_constructor_containing_default_arguments
assertIgnored();
}

/**
* For private suspending function Kotlin compiler versions prior to 1.5
* produce package-local synthetic method that should not be filtered
*
* <pre>
* private suspend fun example() {
* }
* </pre>
*
* @see #should_filter_synthetic_methods_whose_name_starts_with_access_dollar_even_if_last_argument_is_kotlin_coroutine_continuation()
*/
@Test
public void should_not_filter_synthetic_methods_whose_last_argument_is_kotlin_coroutine_continuation() {
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
Expand All @@ -145,4 +156,36 @@ public void should_not_filter_synthetic_methods_whose_last_argument_is_kotlin_co
assertIgnored();
}

/**
* For private suspending function Kotlin compiler versions starting from
* 1.5 produce additional public synthetic method with name starting with
* "access$" that should be filtered
*
* <pre>
* private suspend fun example() {
* }
* </pre>
*
* @see #should_not_filter_synthetic_methods_whose_last_argument_is_kotlin_coroutine_continuation()
*/
@Test
public void should_filter_synthetic_methods_whose_name_starts_with_access_dollar_even_if_last_argument_is_kotlin_coroutine_continuation() {
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL
| Opcodes.ACC_SYNTHETIC,
"access$example",
"(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", null,
null);
context.classAnnotations
.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);
m.visitVarInsn(Opcodes.ALOAD, 0);
m.visitMethodInsn(Opcodes.INVOKESTATIC, "ExampleKt", "example",
"(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", false);
m.visitInsn(Opcodes.RETURN);

filter.filter(m, context, output);

assertMethodIgnored(m);
}

}
Expand Up @@ -29,7 +29,11 @@
*/
public final class KotlinCoroutineFilter implements IFilter {

static boolean isLastArgumentContinuation(final MethodNode methodNode) {
static boolean isImplementationOfSuspendFunction(
final MethodNode methodNode) {
if (methodNode.name.startsWith("access$")) {
return false;
}
final Type methodType = Type.getMethodType(methodNode.desc);
final int lastArgument = methodType.getArgumentTypes().length - 1;
return lastArgument >= 0 && "kotlin.coroutines.Continuation".equals(
Expand Down
Expand Up @@ -52,7 +52,8 @@ public void filter(final MethodNode methodNode,
return;
}

if (KotlinCoroutineFilter.isLastArgumentContinuation(methodNode)) {
if (KotlinCoroutineFilter
.isImplementationOfSuspendFunction(methodNode)) {
return;
}
}
Expand Down
3 changes: 3 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -30,6 +30,9 @@ <h3>New Features</h3>
<li>Branch added by the Kotlin compiler version 1.4.0 and above for "unsafe" cast
operator is filtered out during generation of report
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1143">#1143</a>).</li>
<li><code>synthetic</code> methods added by the Kotlin compiler version 1.5.0 and
above for <code>private</code> suspending functions are filtered out
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1174">#1174</a>).</li>
<li>Branches added by the Kotlin compiler version 1.4.20 and above for suspending
lambdas are filtered out during generation of report
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1149">#1149</a>).</li>
Expand Down