aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Mandrikov <138671+Godin@users.noreply.github.com>2021-04-13 07:02:27 +0200
committerGitHub <noreply@github.com>2021-04-13 07:02:27 +0200
commit86dc5fd9f0531927054ba06991c6ee94c8da7785 (patch)
treea215dfdbd64281136e4d7504a7846e78678ed243
parentb68fe1a0a7fb86f12cda689ec473fd6633699b55 (diff)
downloadjacoco-86dc5fd9f0531927054ba06991c6ee94c8da7785.tar.gz
Update filter for Kotlin 1.5 suspending functions (#1174)
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java43
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinCoroutineFilter.java6
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java3
-rw-r--r--org.jacoco.doc/docroot/doc/changes.html3
4 files changed, 53 insertions, 2 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java
index 021add49..affc39bc 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java
@@ -130,6 +130,17 @@ public class SyntheticFilterTest extends FilterTestBase {
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,
@@ -145,4 +156,36 @@ public class SyntheticFilterTest extends FilterTestBase {
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);
+ }
+
}
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinCoroutineFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinCoroutineFilter.java
index 23943ab5..4b850f33 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinCoroutineFilter.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/KotlinCoroutineFilter.java
@@ -29,7 +29,11 @@ import org.objectweb.asm.tree.TableSwitchInsnNode;
*/
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(
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java
index 2e466114..127f7b03 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java
@@ -52,7 +52,8 @@ public final class SyntheticFilter implements IFilter {
return;
}
- if (KotlinCoroutineFilter.isLastArgumentContinuation(methodNode)) {
+ if (KotlinCoroutineFilter
+ .isImplementationOfSuspendFunction(methodNode)) {
return;
}
}
diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html
index 2f8ab6fc..d0cdea7c 100644
--- a/org.jacoco.doc/docroot/doc/changes.html
+++ b/org.jacoco.doc/docroot/doc/changes.html
@@ -30,6 +30,9 @@
<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>