KAPT+IR: support IR error types

#KT-49682
This commit is contained in:
Mikhael Bogdanov
2022-05-27 13:39:57 +02:00
committed by Space
parent 41d6f0dca4
commit 162ca4ac2b
21 changed files with 290 additions and 25 deletions
@@ -1009,13 +1009,14 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
parameters: JavacList<JCVariableDecl>,
valueParametersFromDescriptor: List<ValueParameterDescriptor>
): Pair<SignatureParser.MethodGenericSignature, JCExpression?> {
val psiElement = kaptContext.origins[method]?.element
val genericSignature = signatureParser.parseMethodSignature(
method.signature, parameters, exceptionTypes, jcReturnType,
nonErrorParameterTypeProvider = { index, lazyType ->
if (descriptor is PropertySetterDescriptor && valueParametersFromDescriptor.size == 1 && index == 0) {
getNonErrorType(descriptor.correspondingProperty.returnType, METHOD_PARAMETER_TYPE,
ktTypeProvider = {
val setterOrigin = (kaptContext.origins[method]?.element as? KtCallableDeclaration)
val setterOrigin = (psiElement as? KtCallableDeclaration)
?.takeIf { it !is KtFunction }
setterOrigin?.typeReference
@@ -1023,7 +1024,11 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
ifNonError = { lazyType() })
} else if (descriptor is FunctionDescriptor && valueParametersFromDescriptor.size == parameters.size) {
val parameterDescriptor = valueParametersFromDescriptor[index]
val sourceElement = kaptContext.origins[method]?.element as? KtFunction
val sourceElement = when {
psiElement is KtFunction -> psiElement
descriptor is ConstructorDescriptor && descriptor.isPrimary -> (psiElement as? KtClassOrObject)?.primaryConstructor
else -> null
}
getNonErrorType(
parameterDescriptor.type, METHOD_PARAMETER_TYPE,
@@ -1047,11 +1052,11 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
val returnType = getNonErrorType(
descriptor.returnType, RETURN_TYPE,
ktTypeProvider = {
when (val element = kaptContext.origins[method]?.element) {
is KtFunction -> element.typeReference
is KtProperty -> if (descriptor is PropertyGetterDescriptor) element.typeReference else null
is KtPropertyAccessor -> if (descriptor is PropertyGetterDescriptor) element.property.typeReference else null
is KtParameter -> if (descriptor is PropertyGetterDescriptor) element.typeReference else null
when (psiElement) {
is KtFunction -> psiElement.typeReference
is KtProperty -> if (descriptor is PropertyGetterDescriptor) psiElement.typeReference else null
is KtPropertyAccessor -> if (descriptor is PropertyGetterDescriptor) psiElement.property.typeReference else null
is KtParameter -> if (descriptor is PropertyGetterDescriptor) psiElement.typeReference else null
else -> null
}
},
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// CORRECT_ERROR_TYPES
@file:Suppress("UNRESOLVED_REFERENCE", "ANNOTATION_ARGUMENT_MUST_BE_CONST", "NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION")
@@ -28,6 +27,6 @@ class ErrorInDeclarations {
annotation class Anno(val a: KClass<Any>)
// EXPECTED_ERROR(kotlin:11:1) cannot find symbol
// EXPECTED_ERROR(kotlin:6:1) cannot find symbol
// EXPECTED_ERROR(kotlin:12:1) cannot find symbol
// EXPECTED_ERROR(kotlin:7:1) cannot find symbol
// EXPECTED_ERROR(kotlin:13:1) cannot find symbol
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// CORRECT_ERROR_TYPES
// NO_VALIDATION
// WITH_STDLIB
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// CORRECT_ERROR_TYPES
// FILE: a.kt
@@ -53,4 +52,4 @@ interface TestC {
fun e(): LibFooBar
}
// EXPECTED_ERROR(kotlin:17:5) cannot find symbol
// EXPECTED_ERROR(kotlin:16:5) cannot find symbol
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// CORRECT_ERROR_TYPES
// FILE: te/st/a/JavaClass
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// CORRECT_ERROR_TYPES
// JAVAC_OPTION -Xmaxerrs=1
@@ -12,4 +11,4 @@ class Test {
// There are two errors (unresolved identifier ABC, BCD) actually.
// But we specified the max error count, so the error output is limited.
// EXPECTED_ERROR(kotlin:8:5) cannot find symbol
// EXPECTED_ERROR(kotlin:7:5) cannot find symbol
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// CORRECT_ERROR_TYPES
// NON_EXISTENT_CLASS
// NO_VALIDATION
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// NON_EXISTENT_CLASS
// NO_VALIDATION
@@ -0,0 +1,129 @@
import java.lang.System;
@kotlin.Suppress(names = {"UNRESOLVED_REFERENCE"})
@kotlin.Metadata()
public final class NonExistentClassWIthoutCorrectionKt {
}
////////////////////
import java.lang.System;
@kotlin.Metadata()
public final class NonExistentType {
@org.jetbrains.annotations.Nullable()
private static final error.NonExistentClass a = null;
@org.jetbrains.annotations.Nullable()
private static final java.util.List<error.NonExistentClass> b = null;
@org.jetbrains.annotations.NotNull()
private static final kotlin.jvm.functions.Function1<error.NonExistentClass, kotlin.Unit> c = null;
@org.jetbrains.annotations.Nullable()
private static final error.NonExistentClass d = null;
public static java.lang.String string2;
public static error.NonExistentClass coocoo;
public static error.NonExistentClass coocoo2;
public static error.NonExistentClass coocoo21;
public static error.NonExistentClass coocoo3;
public static error.NonExistentClass coocoo31;
@org.jetbrains.annotations.NotNull()
public static final NonExistentType INSTANCE = null;
private NonExistentType() {
super();
}
@org.jetbrains.annotations.Nullable()
public final error.NonExistentClass getA() {
return null;
}
@org.jetbrains.annotations.Nullable()
public final java.util.List<error.NonExistentClass> getB() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final kotlin.jvm.functions.Function1<error.NonExistentClass, kotlin.Unit> getC() {
return null;
}
@org.jetbrains.annotations.Nullable()
public final error.NonExistentClass getD() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final java.lang.String getString2() {
return null;
}
public final void setString2(@org.jetbrains.annotations.NotNull()
java.lang.String p0) {
}
@org.jetbrains.annotations.NotNull()
public final error.NonExistentClass getCoocoo() {
return null;
}
public final void setCoocoo(@org.jetbrains.annotations.NotNull()
error.NonExistentClass p0) {
}
@org.jetbrains.annotations.NotNull()
public final error.NonExistentClass getCoocoo2() {
return null;
}
public final void setCoocoo2(@org.jetbrains.annotations.NotNull()
error.NonExistentClass p0) {
}
@org.jetbrains.annotations.NotNull()
public final error.NonExistentClass getCoocoo21() {
return null;
}
public final void setCoocoo21(@org.jetbrains.annotations.NotNull()
error.NonExistentClass p0) {
}
@org.jetbrains.annotations.NotNull()
public final error.NonExistentClass getCoocoo3() {
return null;
}
public final void setCoocoo3(@org.jetbrains.annotations.NotNull()
error.NonExistentClass p0) {
}
@org.jetbrains.annotations.NotNull()
public final error.NonExistentClass getCoocoo31() {
return null;
}
public final void setCoocoo31(@org.jetbrains.annotations.NotNull()
error.NonExistentClass p0) {
}
@org.jetbrains.annotations.NotNull()
public final error.NonExistentClass a(@org.jetbrains.annotations.NotNull()
error.NonExistentClass a, @org.jetbrains.annotations.NotNull()
java.lang.String s) {
return null;
}
@org.jetbrains.annotations.NotNull()
public final error.NonExistentClass b(@org.jetbrains.annotations.NotNull()
java.lang.String s) {
return null;
}
}
////////////////////
package error;
public final class NonExistentClass {
}
@@ -0,0 +1,65 @@
import java.lang.System;
@kotlin.Suppress(names = {"UNRESOLVED_REFERENCE"})
@kotlin.Metadata()
public final class NonExistentType {
@org.jetbrains.annotations.Nullable()
private static final ABCDEF a = null;
@org.jetbrains.annotations.Nullable()
private static final java.util.List<ABCDEF> b = null;
@org.jetbrains.annotations.NotNull()
private static final Function1<ABCDEF, kotlin.Unit> c = null;
@org.jetbrains.annotations.Nullable()
private static final ABCDEF<java.lang.String, Function1<java.util.List<ABCDEF>, kotlin.Unit>> d = null;
@org.jetbrains.annotations.NotNull()
public static final NonExistentType INSTANCE = null;
private NonExistentType() {
super();
}
@org.jetbrains.annotations.Nullable()
public final ABCDEF getA() {
return null;
}
@org.jetbrains.annotations.Nullable()
public final java.util.List<ABCDEF> getB() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final Function1<ABCDEF, kotlin.Unit> getC() {
return null;
}
@org.jetbrains.annotations.Nullable()
public final ABCDEF<java.lang.String, Function1<java.util.List<ABCDEF>, kotlin.Unit>> getD() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final Foo getFoo() {
return null;
}
@org.jetbrains.annotations.NotNull()
public final ABCDEF a(@org.jetbrains.annotations.NotNull()
ABCDEF a, @org.jetbrains.annotations.NotNull()
java.lang.String s) {
return null;
}
@org.jetbrains.annotations.NotNull()
public final ABCDEF b(@org.jetbrains.annotations.NotNull()
java.lang.String s) {
return null;
}
}
////////////////////
package error;
public final class NonExistentClass {
}