Skip to content

Commit

Permalink
synthetic methods that represent Kotlin suspend functions should not …
Browse files Browse the repository at this point in the history
…be ignored (bazelbuild#804)
  • Loading branch information
Godin authored and marchof committed Dec 27, 2018
1 parent f93bf2c commit fd90e3e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import org.jacoco.core.test.validation.targets.Stubs.nop
*/
object KotlinCoroutineTarget {

suspend fun suspendingFunction() {
private suspend fun suspendingFunction() {
nop() // assertFullyCovered()
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,19 @@ public void should_filter_synthetic_method_with_suffix_default_in_non_kotlin_cla
assertMethodIgnored(m);
}

@Test
public void should_not_filter_synthetic_methods_whose_last_argument_is_kotlin_coroutine_continuation() {
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
Opcodes.ACC_SYNTHETIC | Opcodes.ACC_STATIC, "example",
"(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", null,
null);
context.classAnnotations
.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);
m.visitInsn(Opcodes.NOP);

filter.filter(m, context, output);

assertIgnored();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
Expand All @@ -26,6 +27,13 @@
*/
public final class KotlinCoroutineFilter implements IFilter {

static boolean isLastArgumentContinuation(final MethodNode methodNode) {
final Type methodType = Type.getMethodType(methodNode.desc);
final int lastArgument = methodType.getArgumentTypes().length - 1;
return lastArgument >= 0 && "kotlin.coroutines.Continuation".equals(
methodType.getArgumentTypes()[lastArgument].getClassName());
}

public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ public void filter(final MethodNode methodNode,
return;
}

if (KotlinDefaultArgumentsFilter
.isDefaultArgumentsMethodName(methodNode.name)
&& KotlinGeneratedFilter.isKotlinClass(context)) {
return;
if (KotlinGeneratedFilter.isKotlinClass(context)) {
if (KotlinDefaultArgumentsFilter
.isDefaultArgumentsMethodName(methodNode.name)) {
return;
}

if (KotlinCoroutineFilter.isLastArgumentContinuation(methodNode)) {
return;
}
}

output.ignore(methodNode.instructions.getFirst(),
Expand Down
3 changes: 3 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ <h3>Fixed Bugs</h3>
<ul>
<li>Report code coverage correctly for Kotlin methods with default arguments
(GitHub <a href="https://github.com/jacoco/jacoco/issues/774">#774</a>).</li>
<li><code>synthetic</code> methods that represent Kotlin <code>suspend</code>
functions should not be ignored
(GitHub <a href="https://github.com/jacoco/jacoco/issues/804">#804</a>).</li>
</ul>

<h3>Non-functional Changes</h3>
Expand Down

0 comments on commit fd90e3e

Please sign in to comment.