diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinTypes.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinTypes.kt index 3873e63d278..2f7309aac63 100644 --- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinTypes.kt +++ b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinTypes.kt @@ -102,9 +102,11 @@ class KotlinTypes(val javaPsiFacade: JavaPsiFacade, val psiManager: PsiManager, override fun getPrimitiveType(kind: TypeKind) = kind.toJePrimitiveType() override fun erasure(t: TypeMirror): TypeMirror { - if (t is NoType) throw IllegalArgumentException("Invalid type: $t") - t as? JePsiType ?: return t - return TypeConversionUtil.erasure(t.psiType).toJeType(psiManager) + if (t.kind == TypeKind.PACKAGE) throw IllegalArgumentException("Invalid type: $t") + return when (t) { + is JePsiType -> TypeConversionUtil.erasure(t.psiType).toJeType(psiManager) + else -> t + } } override fun directSupertypes(t: TypeMirror): List { diff --git a/plugins/annotation-processing/testData/processors/ErasureSimple.kt b/plugins/annotation-processing/testData/processors/ErasureSimple.kt new file mode 100644 index 00000000000..b66e20d43e3 --- /dev/null +++ b/plugins/annotation-processing/testData/processors/ErasureSimple.kt @@ -0,0 +1,5 @@ +@Deprecated("") +class Test { + fun a(): Int = 5 + fun b(): Unit {} +} \ No newline at end of file diff --git a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ProcessorTests.kt b/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ProcessorTests.kt index df8a77c8543..0871062ee63 100644 --- a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ProcessorTests.kt +++ b/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ProcessorTests.kt @@ -153,4 +153,12 @@ class ProcessorTests : AbstractProcessorTest() { val typeArg = cai.typeArguments.first() assertTrue(typeArg is TypeVariable) } + + fun testErasureSimple() = test("ErasureSimple", "*") { set, roundEnv, env -> + val test = env.findClass("Test") + val int = test.findMethod("a").returnType + val void = test.findMethod("b").returnType + assertEquals(int, env.typeUtils.erasure(int)) + assertEquals(void, env.typeUtils.erasure(void)) + } } \ No newline at end of file