Fix decompilation of types based on local classifiers
If deserializing a type with arguments based on a local class for decompiler, then just return Any type (without arguments). Previously Any constructor was used with serialized arguments, that lead to exception Note that in case of deserialization for compiler nothing changes about local-classes-based types (LocalClassifierResolverImpl is just inlined) #KT-13408 Fixed
This commit is contained in:
-41
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import javax.inject.Inject
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class LocalClassifierResolverImpl : LocalClassifierResolver {
|
||||
var components: DeserializationComponents by Delegates.notNull()
|
||||
|
||||
// component dependency cycle
|
||||
@Inject fun setDeserializationComponents(components: DeserializationComponents) {
|
||||
this.components = components
|
||||
}
|
||||
|
||||
override fun resolveLocalClass(classId: ClassId): ClassDescriptor? {
|
||||
return components.deserializeClass(classId)
|
||||
}
|
||||
|
||||
override fun resolveLocalTypeAlias(typeAliasId: ClassId): ClassifierDescriptor? {
|
||||
return components.deserializeTypeAlias(typeAliasId)
|
||||
}
|
||||
}
|
||||
+8
-6
@@ -16,11 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
|
||||
interface LocalClassifierResolver {
|
||||
fun resolveLocalClass(classId: ClassId): ClassDescriptor?
|
||||
fun resolveLocalTypeAlias(typeAliasId: ClassId): ClassifierDescriptor?
|
||||
interface LocalClassifierTypeSettings {
|
||||
val replacementTypeForLocalClassifiers: SimpleType?
|
||||
|
||||
object Default : LocalClassifierTypeSettings {
|
||||
override val replacementTypeForLocalClassifiers: SimpleType?
|
||||
get() = null
|
||||
}
|
||||
}
|
||||
+20
-3
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
@@ -68,6 +70,14 @@ class TypeDeserializer(
|
||||
}
|
||||
|
||||
fun simpleType(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): SimpleType {
|
||||
val localClassifierType = when {
|
||||
proto.hasClassName() -> computeLocalClassifierReplacementType(proto.className)
|
||||
proto.hasTypeAliasName() -> computeLocalClassifierReplacementType(proto.typeAliasName)
|
||||
else -> null
|
||||
}
|
||||
|
||||
if (localClassifierType != null) return localClassifierType
|
||||
|
||||
val constructor = typeConstructor(proto)
|
||||
if (ErrorUtils.isError(constructor.declarationDescriptor)) {
|
||||
return ErrorUtils.createErrorTypeWithCustomConstructor(constructor.toString(), constructor)
|
||||
@@ -122,15 +132,22 @@ class TypeDeserializer(
|
||||
val id = c.nameResolver.getClassId(fqNameIndex)
|
||||
if (id.isLocal) {
|
||||
// Local classes can't be found in scopes
|
||||
return c.components.localClassifierResolver.resolveLocalClass(id)
|
||||
return c.components.deserializeClass(id)
|
||||
}
|
||||
return c.components.moduleDescriptor.findClassAcrossModuleDependencies(id)
|
||||
}
|
||||
|
||||
private fun computeLocalClassifierReplacementType(className: Int): SimpleType? {
|
||||
if (c.nameResolver.getClassId(className).isLocal) {
|
||||
return c.components.localClassifierTypeSettings.replacementTypeForLocalClassifiers
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun computeTypeAliasDescriptor(fqNameIndex: Int): ClassifierDescriptor? {
|
||||
val id = c.nameResolver.getClassId(fqNameIndex)
|
||||
return if (id.isLocal) {
|
||||
c.components.localClassifierResolver.resolveLocalTypeAlias(id)
|
||||
c.components.deserializeTypeAlias(id)
|
||||
}
|
||||
else {
|
||||
c.components.moduleDescriptor.findTypeAliasAcrossModuleDependencies(id)
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ class DeserializationComponents(
|
||||
val classDataFinder: ClassDataFinder,
|
||||
val annotationAndConstantLoader: AnnotationAndConstantLoader<AnnotationDescriptor, ConstantValue<*>, AnnotationWithTarget>,
|
||||
val packageFragmentProvider: PackageFragmentProvider,
|
||||
val localClassifierResolver: LocalClassifierResolver,
|
||||
val localClassifierTypeSettings: LocalClassifierTypeSettings,
|
||||
val errorReporter: ErrorReporter,
|
||||
val lookupTracker: LookupTracker,
|
||||
val flexibleTypeDeserializer: FlexibleTypeDeserializer,
|
||||
|
||||
Reference in New Issue
Block a user