Do not load error classes in ReflectionTypes
Previously ReflectionTypes.find returned an error class in case a class is not found in the module dependencies. The problem with this approach is that each call site should call ErrorUtils.isError on the result and report an error if needed, in order to stop this type from reaching the codegen, which can't handle error types. Now we create a MockClassDescriptor instance instead. It's not an error class, so it'll be handled correctly in the codegen. Also its scope is empty and errors are reported on any non-trivial usage (see MissingDependencyClassChecker), so this approach is not worse than error classes #KT-16484 Fixed
This commit is contained in:
+6
-1
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.AbstractReflectionApiCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.NO_REFLECTION_IN_CLASS_PATH
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NotFoundClasses
|
||||
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
@@ -30,7 +31,11 @@ import org.jetbrains.kotlin.storage.getValue
|
||||
* If there's no Kotlin reflection implementation found in the classpath, checks that there are no usages
|
||||
* of reflection API which will fail at runtime.
|
||||
*/
|
||||
class JvmReflectionAPICallChecker(private val module: ModuleDescriptor, storageManager: StorageManager) : AbstractReflectionApiCallChecker(module, storageManager) {
|
||||
class JvmReflectionAPICallChecker(
|
||||
private val module: ModuleDescriptor,
|
||||
notFoundClasses: NotFoundClasses,
|
||||
storageManager: StorageManager
|
||||
) : AbstractReflectionApiCallChecker(module, notFoundClasses, storageManager) {
|
||||
override val isWholeReflectionApiAvailable by storageManager.createLazyValue {
|
||||
module.findClassAcrossModuleDependencies(JvmAbi.REFLECTION_FACTORY_IMPL) != null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user