PSI2IR KT-49053 skip fake overrides with unresolved types in signature
This commit is contained in:
committed by
TeamCityServer
parent
1c3a20fab9
commit
3d64c91375
+6
@@ -23278,6 +23278,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/javaInterop/superCallOfPrintStackTrace.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unresolvedJavaClassInDifferentFile.kt")
|
||||
public void testUnresolvedJavaClassInDifferentFile() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/unresolvedJavaClassInDifferentFile.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/javaInterop/generics")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+37
-5
@@ -18,6 +18,10 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrSetFieldImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrErrorType
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
|
||||
import org.jetbrains.kotlin.ir.util.declareSimpleFunctionWithOverrides
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -28,7 +32,6 @@ import org.jetbrains.kotlin.psi.psiUtil.pureStartOffset
|
||||
import org.jetbrains.kotlin.psi2ir.isConstructorDelegatingToSuper
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isAnnotationConstructor
|
||||
@@ -67,11 +70,35 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
||||
fun generateFakeOverrideFunction(functionDescriptor: FunctionDescriptor, ktElement: KtPureElement): IrSimpleFunction? =
|
||||
functionDescriptor.takeIf { it.visibility != DescriptorVisibilities.INVISIBLE_FAKE }
|
||||
?.let {
|
||||
declareSimpleFunctionInner(it, ktElement, IrDeclarationOrigin.FAKE_OVERRIDE).buildWithScope { irFunction ->
|
||||
generateFunctionParameterDeclarationsAndReturnType(irFunction, ktElement, null)
|
||||
}
|
||||
declareSimpleFunctionInner(it, ktElement, IrDeclarationOrigin.FAKE_OVERRIDE)
|
||||
.buildWithScope { irFunction ->
|
||||
generateFunctionParameterDeclarationsAndReturnType(irFunction, ktElement, null)
|
||||
}
|
||||
.takeUnless { irFunction ->
|
||||
irFunction.containsErrorTypesInSignature()
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrSimpleFunction.containsErrorTypesInSignature(): Boolean {
|
||||
if (this.typeParameters.any { it.superTypes.any { it.containsErrorType() } }) return true
|
||||
this.dispatchReceiverParameter?.let {
|
||||
if (it.type.containsErrorType()) return true
|
||||
}
|
||||
this.extensionReceiverParameter?.let {
|
||||
if (it.type.containsErrorType()) return true
|
||||
}
|
||||
if (this.valueParameters.any { it.type.containsErrorType() }) return true
|
||||
if (this.returnType.containsErrorType()) return true
|
||||
return false
|
||||
}
|
||||
|
||||
private fun IrType.containsErrorType(): Boolean =
|
||||
when (this) {
|
||||
is IrErrorType -> true
|
||||
is IrSimpleType -> arguments.any { it is IrTypeProjection && it.type.containsErrorType() }
|
||||
else -> false
|
||||
}
|
||||
|
||||
private inline fun declareSimpleFunction(
|
||||
ktFunction: KtFunction,
|
||||
ktReceiver: KtElement?,
|
||||
@@ -370,7 +397,12 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
||||
return call.resultingDescriptor.name.asString()
|
||||
}
|
||||
|
||||
private fun declareParameter(descriptor: ParameterDescriptor, ktElement: KtPureElement?, irOwnerElement: IrElement, name: Name? = null) =
|
||||
private fun declareParameter(
|
||||
descriptor: ParameterDescriptor,
|
||||
ktElement: KtPureElement?,
|
||||
irOwnerElement: IrElement,
|
||||
name: Name? = null
|
||||
) =
|
||||
context.symbolTable.declareValueParameter(
|
||||
ktElement?.pureStartOffset ?: irOwnerElement.startOffset,
|
||||
ktElement?.pureEndOffset ?: irOwnerElement.endOffset,
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeAbbreviation
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||
import org.jetbrains.kotlin.ir.types.impl.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
|
||||
import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypes
|
||||
@@ -143,6 +144,10 @@ abstract class TypeTranslator(
|
||||
val lowerTypeDescriptor =
|
||||
lowerType.constructor.declarationDescriptor as? ClassDescriptor
|
||||
?: throw AssertionError("No class descriptor for lower type $lowerType of $approximatedType")
|
||||
annotations = translateTypeAnnotations(upperType, approximatedType)
|
||||
if (lowerTypeDescriptor is NotFoundClasses.MockClassDescriptor) {
|
||||
return IrErrorTypeImpl(approximatedType, annotations, variance)
|
||||
}
|
||||
classifier = symbolTable.referenceClass(lowerTypeDescriptor)
|
||||
arguments = when {
|
||||
approximatedType is RawType ->
|
||||
@@ -152,7 +157,7 @@ abstract class TypeTranslator(
|
||||
else ->
|
||||
translateTypeArguments(upperType.arguments)
|
||||
}
|
||||
annotations = translateTypeAnnotations(upperType, approximatedType)
|
||||
|
||||
}
|
||||
|
||||
else ->
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: unresolvedJavaClassInDifferentFile.kt
|
||||
import j.Base
|
||||
|
||||
class Derived : Base() {
|
||||
fun ok() = "OK"
|
||||
}
|
||||
|
||||
fun box() =
|
||||
Derived().ok()
|
||||
|
||||
// FILE: j/Foo.java
|
||||
package j;
|
||||
|
||||
// NB package-private class 'j.Bar' in file 'j/Foo.java'
|
||||
class Bar {
|
||||
}
|
||||
|
||||
// FILE: j/Base.java
|
||||
package j;
|
||||
|
||||
public class Base {
|
||||
protected Bar bar() {
|
||||
return new Bar();
|
||||
}
|
||||
|
||||
protected void bar(Bar b) {
|
||||
}
|
||||
}
|
||||
+6
@@ -23140,6 +23140,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/superCallOfPrintStackTrace.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unresolvedJavaClassInDifferentFile.kt")
|
||||
public void testUnresolvedJavaClassInDifferentFile() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/unresolvedJavaClassInDifferentFile.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/javaInterop/generics")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+6
@@ -23278,6 +23278,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/javaInterop/superCallOfPrintStackTrace.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unresolvedJavaClassInDifferentFile.kt")
|
||||
public void testUnresolvedJavaClassInDifferentFile() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/unresolvedJavaClassInDifferentFile.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/javaInterop/generics")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+5
@@ -19417,6 +19417,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/javaInterop/superCallOfPrintStackTrace.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unresolvedJavaClassInDifferentFile.kt")
|
||||
public void testUnresolvedJavaClassInDifferentFile() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/unresolvedJavaClassInDifferentFile.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/javaInterop/generics")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user