Skip to content

Commit 83d1f44

Browse files
authored
Use KotlinTypeUtils.isKotlinUnit to match Kotlin void return types (#971)
Follow-up to #970, which disabled `doNotChangeAlreadyUnitTestMethods` with comment "flaky on CI but I don't know why". Root cause: as of rewrite 8.79.4 (openrewrite/rewrite#7364), the Kotlin parser maps non-nullable `kotlin.Unit` to JVM `JavaType.Primitive.Void`. `TypeUtils.isOfClassType(type, "kotlin.Unit")` returns false for a primitive, so the recipe no longer skips already-Unit methods and rewrites them unnecessarily — tripping the single-cycle stability check on CI. Locally, stale `rewrite-kotlin` snapshots still carry the pre-change behaviour, which is why the failure was CI-only. Use `KotlinTypeUtils.isKotlinUnit` (introduced in the same PR #7364) which accepts either `JavaType.Primitive.Void` or a `kotlin.Unit` class reference, and re-enable the disabled test.
1 parent 675b57d commit 83d1f44

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

src/main/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodsShouldReturnUnit.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.openrewrite.kotlin.marker.KObject;
2727
import org.openrewrite.kotlin.marker.SingleExpressionBlock;
2828
import org.openrewrite.kotlin.tree.K;
29+
import org.openrewrite.kotlin.tree.KotlinTypeUtils;
2930
import org.openrewrite.marker.Markers;
3031

3132
import static java.util.Collections.emptyList;
@@ -52,7 +53,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
5253

5354
// Skip invalid signatures or already-correct return types
5455
JavaType.Method methodType = m.getMethodType();
55-
if (m.getBody() == null || methodType == null || TypeUtils.isOfClassType(methodType.getReturnType(), KOTLIN_UNIT.getFullyQualifiedName())) {
56+
if (m.getBody() == null || methodType == null || KotlinTypeUtils.isKotlinUnit(methodType.getReturnType())) {
5657
return m;
5758
}
5859

src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodsShouldReturnUnitTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.openrewrite.java.testing.cleanup;
1717

18-
import org.junit.jupiter.api.Disabled;
1918
import org.junit.jupiter.api.Test;
2019
import org.openrewrite.DocumentExample;
2120
import org.openrewrite.InMemoryExecutionContext;
@@ -309,7 +308,6 @@ fun getValue() : String {
309308
);
310309
}
311310

312-
@Disabled("flaky on CI but I don't know why")
313311
@Test
314312
void doNotChangeAlreadyUnitTestMethods() {
315313
//language=kotlin

0 commit comments

Comments
 (0)