Properly handle Object types in override variance
This CL fixes a bug where if Unit is used in type arguments, we were
creating `out Unit` even when we shouldn't.
Seems like the check was including OBJECT classkinds by default. I'm not
sure why, couldn't find it in CL notes but that seems unnecessary. Added
a test to validate that it is not necessary (also, Unit is an `object`)
Added a couple more tests with parmeters that have function types.
Fixes: 190010217
Test: MethodSpecHelperTest
Change-Id: Ia628235a7385d3561ed7fb0eacfa9ebe486b75d5
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/OverrideVarianceResolver.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/OverrideVarianceResolver.kt
index 96cade3..b2f3cf8 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/OverrideVarianceResolver.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/OverrideVarianceResolver.kt
@@ -169,8 +169,7 @@
when (val decl = myType.declaration) {
is KSClassDeclaration -> {
decl.isOpen() ||
- decl.classKind == ClassKind.ENUM_CLASS ||
- decl.classKind == ClassKind.OBJECT
+ decl.classKind == ClassKind.ENUM_CLASS
}
else -> true
}
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt
index cfd143b..2032454 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt
@@ -93,6 +93,7 @@
package foo.bar;
import androidx.room.compiler.processing.testcode.OtherAnnotation;
+ object MyObject
abstract class Baz {
open fun method1() {
}
@@ -124,6 +125,18 @@
protected open fun listArg(r:List<String>) {
}
+ protected open fun listOfUnitArg(r:List<Unit>) {
+ }
+
+ protected open fun listOfCustomObjectArg(r:List<MyObject>) {
+ }
+
+ protected open fun listOfAnyArg(r:List<Any>) {
+ }
+
+ protected open fun listOfVoidArg(r:List<Void>) {
+ }
+
open suspend fun suspendUnitFun() {
}
@@ -155,6 +168,35 @@
}
@Test
+ fun kotlinParametersAsFunction() {
+ val source = Source.kotlin(
+ "Foo.kt",
+ """
+ package foo.bar;
+ interface MyInterface
+ interface Baz {
+ fun noArg_returnsUnit(operation: () -> Unit) {
+ }
+ fun singleArg_returnsUnit(operation: (Int) -> Unit) {
+ }
+ fun singleInterfaceArg_returnsUnit(operation: (MyInterface) -> Unit) {
+ }
+ fun singleReceiverArg_returnsUnit(operation: Int.() -> Unit) {
+ }
+ fun singleInterfaceReceiverArg_returnsUnit(operation: MyInterface.() -> Unit) {
+ }
+
+ fun noArg_returnsInt(operation: () -> Int) {
+ }
+ fun singleArg_returnsInterface(operation: (Int) -> MyInterface) {
+ }
+ }
+ """.trimIndent()
+ )
+ overridesCheck(source)
+ }
+
+ @Test
fun variance() {
// check our override impl matches javapoet
val source = Source.kotlin(