Report JVM signature clashes from JVM_IR
Also: * Do not rename public ABI fields This includes backing fields for const, lateinit, @JvmField properties, and instance fields for objects. * FAKE_OVERRIDE declarations for static members of parent Java classes Required to report cases when a Kotlin function accidentally overrides Java class member.
This commit is contained in:
@@ -30,6 +30,8 @@ class PsiErrorBuilder(
|
||||
?: throw AssertionError("No PsiElement found for '${irDeclaration.render()}'")
|
||||
)
|
||||
|
||||
fun <E : PsiElement> at(psiElement: E) = Location(psiElement)
|
||||
|
||||
fun <E : PsiElement> at(irElement: IrElement, irDeclaration: IrDeclaration, psiElementClass: KClass<E>): Location<E> =
|
||||
Location(
|
||||
psiSourceManager.findPsiElement(irElement, irDeclaration, psiElementClass)
|
||||
|
||||
@@ -19,8 +19,6 @@ package org.jetbrains.kotlin.psi2ir
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.SourceManager
|
||||
import org.jetbrains.kotlin.ir.SourceRangeInfo
|
||||
@@ -28,7 +26,6 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.util.fileOrNull
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import java.util.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@@ -78,7 +75,7 @@ class PsiSourceManager : SourceManager {
|
||||
fun findPsiElement(irElement: IrElement): PsiElement? {
|
||||
var psiElement = fileViewProvider.findElementAt(irElement.startOffset)
|
||||
while (psiElement != null) {
|
||||
if (psiElement.endOffset == irElement.endOffset) break
|
||||
if (irElement.endOffset == psiElement.textRange?.endOffset) break
|
||||
psiElement = psiElement.parent
|
||||
}
|
||||
return psiElement
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.ir.expressions.mapValueParameters
|
||||
import org.jetbrains.kotlin.ir.expressions.putTypeArguments
|
||||
import org.jetbrains.kotlin.ir.expressions.typeParametersCount
|
||||
import org.jetbrains.kotlin.ir.util.declareSimpleFunctionWithOverrides
|
||||
import org.jetbrains.kotlin.ir.util.fields
|
||||
import org.jetbrains.kotlin.ir.util.properties
|
||||
import org.jetbrains.kotlin.ir.util.referenceFunction
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
@@ -47,12 +46,12 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DelegationResolver
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.propertyIfAccessor
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.setSingleOverridden
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.kotlin.utils.newHashMapWithExpectedSize
|
||||
|
||||
class ClassGenerator(
|
||||
@@ -144,18 +143,44 @@ class ClassGenerator(
|
||||
private fun KtEnumEntry.hasMemberDeclarations() = declarations.isNotEmpty()
|
||||
|
||||
private fun generateFakeOverrideMemberDeclarations(irClass: IrClass, ktClassOrObject: KtPureClassOrObject) {
|
||||
irClass.descriptor.unsubstitutedMemberScope.getContributedDescriptors()
|
||||
.mapNotNull {
|
||||
it.safeAs<CallableMemberDescriptor>().takeIf { memberDescriptor ->
|
||||
memberDescriptor?.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE
|
||||
}
|
||||
val classDescriptor = irClass.descriptor
|
||||
|
||||
classDescriptor.unsubstitutedMemberScope.getContributedDescriptors()
|
||||
.filterIsInstance<CallableMemberDescriptor>()
|
||||
.filter {
|
||||
it.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE
|
||||
}
|
||||
.sortedByRenderer()
|
||||
.forEach { fakeOverride ->
|
||||
declarationGenerator.generateFakeOverrideDeclaration(fakeOverride, ktClassOrObject)?.let { irClass.declarations.add(it) }
|
||||
}
|
||||
|
||||
context.extensions.getParentClassStaticScope(classDescriptor)?.run {
|
||||
getContributedDescriptors()
|
||||
.filterIsInstance<FunctionDescriptor>()
|
||||
.filter {
|
||||
Visibilities.isVisibleIgnoringReceiver(it, classDescriptor)
|
||||
}
|
||||
.sortedByRenderer()
|
||||
.forEach { parentStaticMember ->
|
||||
val fakeOverride = createFakeOverrideDescriptorForParentStaticMember(classDescriptor, parentStaticMember)
|
||||
declarationGenerator.generateFakeOverrideDeclaration(fakeOverride, ktClassOrObject)?.let {
|
||||
irClass.declarations.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createFakeOverrideDescriptorForParentStaticMember(
|
||||
classDescriptor: ClassDescriptor,
|
||||
parentStaticMember: FunctionDescriptor
|
||||
): FunctionDescriptor =
|
||||
parentStaticMember.copy(
|
||||
classDescriptor, parentStaticMember.modality, parentStaticMember.visibility, CallableMemberDescriptor.Kind.FAKE_OVERRIDE, false
|
||||
).apply {
|
||||
setSingleOverridden(parentStaticMember)
|
||||
}
|
||||
|
||||
private fun generateMembersDeclaredInSupertypeList(irClass: IrClass, ktClassOrObject: KtClassOrObject) {
|
||||
val ktSuperTypeList = ktClassOrObject.getSuperTypeList() ?: return
|
||||
var delegateNumber = 0
|
||||
|
||||
+3
@@ -5,10 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.psi2ir.generators
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.ir.util.StubGeneratorExtensions
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
open class GeneratorExtensions : StubGeneratorExtensions() {
|
||||
@@ -37,4 +39,5 @@ open class GeneratorExtensions : StubGeneratorExtensions() {
|
||||
companion object Instance : EnhancedNullability()
|
||||
}
|
||||
|
||||
open fun getParentClassStaticScope(descriptor: ClassDescriptor): MemberScope? = null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user