From c77884f0678ee8f89dd53fed8fda2f20e69af008 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 17 Jun 2021 13:37:19 +0300 Subject: [PATCH] Refactor SAM type handling, replace non-approximated arguments with `*` --- .../kotlin/backend/common/SamType.kt | 89 +------ .../kotlin/backend/common/SamTypeFactory.kt | 76 ++++++ .../kotlin/codegen/JvmSamTypeFactory.kt | 7 +- .../binding/CodegenAnnotatingVisitor.java | 31 ++- .../kotlin/codegen/state/GenerationState.kt | 10 +- .../FirBlackBoxCodegenTestGenerated.java | 6 + .../runners/ir/Fir2IrTextTestGenerated.java | 6 + .../backend/jvm/JvmGeneratorExtensionsImpl.kt | 7 - .../lower/indy/LambdaMetafactoryArguments.kt | 6 +- .../generators/ArgumentsGenerationUtils.kt | 26 +- .../psi2ir/generators/GeneratorContext.kt | 9 +- .../psi2ir/generators/GeneratorExtensions.kt | 8 - .../approximation/approxToSingleUpperBound.kt | 2 + .../types/intersectionTypeInSamType.fir.txt | 241 +++++++++++++++++ .../irText/types/intersectionTypeInSamType.kt | 44 ++++ .../types/intersectionTypeInSamType.txt | 243 ++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 + .../IrBlackBoxCodegenTestGenerated.java | 6 + .../test/runners/ir/IrTextTestGenerated.java | 6 + .../LightAnalysisModeTestGenerated.java | 5 + .../IrJsCodegenBoxES6TestGenerated.java | 5 + .../IrJsCodegenBoxTestGenerated.java | 5 + .../semantics/JsCodegenBoxTestGenerated.java | 5 + 23 files changed, 721 insertions(+), 128 deletions(-) create mode 100644 compiler/backend-common/src/org/jetbrains/kotlin/backend/common/SamTypeFactory.kt create mode 100644 compiler/testData/ir/irText/types/intersectionTypeInSamType.fir.txt create mode 100644 compiler/testData/ir/irText/types/intersectionTypeInSamType.kt create mode 100644 compiler/testData/ir/irText/types/intersectionTypeInSamType.txt diff --git a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/SamType.kt b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/SamType.kt index 67edfb64cf7..d79ee77a8e5 100644 --- a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/SamType.kt +++ b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/SamType.kt @@ -5,18 +5,12 @@ package org.jetbrains.kotlin.backend.common -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor -import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.resolve.sam.getAbstractMembers -import org.jetbrains.kotlin.types.* -import org.jetbrains.kotlin.types.checker.intersectWrappedTypes -import org.jetbrains.kotlin.types.typeUtil.builtIns -import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithNothing +import org.jetbrains.kotlin.types.KotlinType -class SamType constructor(val type: KotlinType, val hasUnapproximatableArguments: Boolean = false) { +class SamType constructor(val type: KotlinType) { val classDescriptor: ClassDescriptor get() = type.constructor.declarationDescriptor as? ClassDescriptor ?: error("Sam/Fun interface not a class descriptor: $type") @@ -40,82 +34,3 @@ class SamType constructor(val type: KotlinType, val hasUnapproximatableArguments } } -open class SamTypeFactory { - private lateinit var typeApproximator: TypeApproximator - - fun createByValueParameter(valueParameter: ValueParameterDescriptor, languageVersionSettings: LanguageVersionSettings): SamType? { - val singleArgumentType: KotlinType - val originalSingleArgumentType: KotlinType? - val varargElementType = valueParameter.varargElementType - if (varargElementType != null) { - singleArgumentType = varargElementType - originalSingleArgumentType = valueParameter.original.varargElementType - assert(originalSingleArgumentType != null) { - "Value parameter and original value parameter have inconsistent varargs: " + - valueParameter + "; " + valueParameter.original - } - } else { - singleArgumentType = valueParameter.type - originalSingleArgumentType = valueParameter.original.type - } - if (singleArgumentType.isError || originalSingleArgumentType!!.isError) { - return null - } - - if (!::typeApproximator.isInitialized) { - typeApproximator = TypeApproximator(singleArgumentType.builtIns, languageVersionSettings) - } - - // This can be true in case when the value parameter is in the method of a generic type with out-projection. - // We approximate Inv to Nothing, while Inv itself can be a SAM interface safe to call here - // (see testData genericSamProjectedOut.kt for details) - // In such a case we can't have a proper supertype since wildcards are not allowed there, - // so we use Nothing arguments instead that leads to a raw type used for a SAM wrapper. - // See org.jetbrains.kotlin.codegen.state.KotlinTypeMapper#writeGenericType to understand how - // raw types and Nothing arguments relate. - val originalTypeToUse = if (KotlinBuiltIns.isNothing(singleArgumentType)) - originalSingleArgumentType.replaceArgumentsWithNothing() - else singleArgumentType - val approximatedOriginalTypeToUse = typeApproximator.approximateToSubType( - originalTypeToUse, - TypeApproximatorConfiguration.UpperBoundAwareIntersectionTypeApproximator - ) ?: originalTypeToUse - approximatedOriginalTypeToUse as KotlinType - val hasUnapproximatableArguments = hasUnapproximatableArguments(approximatedOriginalTypeToUse) - - return create((approximatedOriginalTypeToUse).removeExternalProjections(), hasUnapproximatableArguments) - } - - /* - * declaration site: `class Foo where T: X, T: Y {}`, X and Y aren't related by subtyping - * use site: Foo - * => `in {X & Y}` is unapproximatable type argument - */ - fun hasUnapproximatableArguments(type: KotlinType) = - type.arguments.isNotEmpty() && type.arguments.withIndex().any { (i, argument) -> - if (argument.projectionKind != Variance.IN_VARIANCE) return@any false - if (argument.type.constructor !is IntersectionTypeConstructor) return@any false - val typeParameter = type.constructor.parameters.getOrNull(i) ?: return@any false - // we have really intersection type as the result => at least there are two upper bounds which aren't related by subtyping - intersectWrappedTypes(typeParameter.upperBounds).constructor is IntersectionTypeConstructor - } - - open fun isSamType(type: KotlinType): Boolean { - val descriptor = type.constructor.declarationDescriptor - return descriptor is ClassDescriptor && descriptor.isFun - } - - @JvmOverloads - fun create(originalType: KotlinType, hasUnapproximatableArguments: Boolean = false): SamType? { - return if (isSamType(originalType)) SamType(originalType, hasUnapproximatableArguments) else null - } - - private fun KotlinType.removeExternalProjections(): KotlinType { - val newArguments = arguments.map { TypeProjectionImpl(Variance.INVARIANT, it.type) } - return replace(newArguments) - } - - companion object { - val INSTANCE = SamTypeFactory() - } -} diff --git a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/SamTypeFactory.kt b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/SamTypeFactory.kt new file mode 100644 index 00000000000..a5e035968e3 --- /dev/null +++ b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/SamTypeFactory.kt @@ -0,0 +1,76 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.backend.common + +import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.config.LanguageVersionSettings +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor +import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.checker.intersectWrappedTypes +import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithNothing + +class SamTypeApproximator(builtIns: KotlinBuiltIns, languageVersionSettings: LanguageVersionSettings) { + private val typeApproximator = TypeApproximator(builtIns, languageVersionSettings) + + fun getSamTypeForValueParameter(valueParameter: ValueParameterDescriptor): KotlinType? { + val singleArgumentType: KotlinType + val originalSingleArgumentType: KotlinType? + val varargElementType = valueParameter.varargElementType + if (varargElementType != null) { + singleArgumentType = varargElementType + originalSingleArgumentType = valueParameter.original.varargElementType + assert(originalSingleArgumentType != null) { + "Value parameter and original value parameter have inconsistent varargs: " + + valueParameter + "; " + valueParameter.original + } + } else { + singleArgumentType = valueParameter.type + originalSingleArgumentType = valueParameter.original.type + } + if (singleArgumentType.isError || originalSingleArgumentType!!.isError) { + return null + } + + // This can be true in case when the value parameter is in the method of a generic type with out-projection. + // We approximate Inv to Nothing, while Inv itself can be a SAM interface safe to call here + // (see testData genericSamProjectedOut.kt for details) + // In such a case we can't have a proper supertype since wildcards are not allowed there, + // so we use Nothing arguments instead that leads to a raw type used for a SAM wrapper. + // See org.jetbrains.kotlin.codegen.state.KotlinTypeMapper#writeGenericType to understand how + // raw types and Nothing arguments relate. + val originalTypeToUse = + if (KotlinBuiltIns.isNothing(singleArgumentType)) + originalSingleArgumentType.replaceArgumentsWithNothing() + else + singleArgumentType + val approximatedOriginalTypeToUse = + typeApproximator.approximateToSubType( + originalTypeToUse, + TypeApproximatorConfiguration.UpperBoundAwareIntersectionTypeApproximator + ) ?: originalTypeToUse + approximatedOriginalTypeToUse as KotlinType + + return approximatedOriginalTypeToUse.removeExternalProjections() + } + + private fun KotlinType.removeExternalProjections(): KotlinType { + val newArguments = arguments.map { TypeProjectionImpl(Variance.INVARIANT, it.type) } + return replace(newArguments) + } + +} + +open class SamTypeFactory { + open fun isSamType(type: KotlinType): Boolean { + val descriptor = type.constructor.declarationDescriptor + return descriptor is ClassDescriptor && descriptor.isFun + } + + fun create(originalType: KotlinType): SamType? { + return if (isSamType(originalType)) SamType(originalType) else null + } +} \ No newline at end of file diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmSamTypeFactory.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmSamTypeFactory.kt index fc8c667913d..29a73f46694 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmSamTypeFactory.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmSamTypeFactory.kt @@ -5,10 +5,11 @@ package org.jetbrains.kotlin.codegen +import org.jetbrains.kotlin.backend.common.SamTypeFactory import org.jetbrains.kotlin.load.java.sam.JavaSingleAbstractMethodUtils import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.backend.common.SamTypeFactory -object JvmSamTypeFactory : SamTypeFactory() { - override fun isSamType(type: KotlinType) = JavaSingleAbstractMethodUtils.isSamType(type) +class JvmSamTypeFactory : SamTypeFactory() { + override fun isSamType(type: KotlinType) = + JavaSingleAbstractMethodUtils.isSamType(type) } \ No newline at end of file diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java index 092867ccf31..bc3d476dc45 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java @@ -15,6 +15,7 @@ import kotlin.Pair; import kotlin.collections.CollectionsKt; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.backend.common.SamTypeApproximator; import org.jetbrains.kotlin.builtins.FunctionTypesKt; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.builtins.ReflectionTypes; @@ -34,6 +35,7 @@ import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor; import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor; import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil; import org.jetbrains.kotlin.load.java.JvmAbi; +import org.jetbrains.kotlin.load.java.sam.JavaSingleAbstractMethodUtils; import org.jetbrains.kotlin.name.ClassId; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.*; @@ -90,6 +92,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { private final ClassBuilderMode classBuilderMode; private final DelegatedPropertiesCodegenHelper delegatedPropertiesCodegenHelper; private final JvmDefaultMode jvmDefaultMode; + private final SamTypeApproximator samTypeApproximator; public CodegenAnnotatingVisitor(@NotNull GenerationState state) { this.bindingTrace = state.getBindingTrace(); @@ -100,7 +103,8 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { this.languageVersionSettings = state.getLanguageVersionSettings(); this.classBuilderMode = state.getClassBuilderMode(); this.delegatedPropertiesCodegenHelper = new DelegatedPropertiesCodegenHelper(state); - jvmDefaultMode = state.getJvmDefaultMode(); + this.jvmDefaultMode = state.getJvmDefaultMode(); + this.samTypeApproximator = new SamTypeApproximator(state.getModule().getBuiltIns(), state.getLanguageVersionSettings()); } @NotNull @@ -855,6 +859,20 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { } } + @Nullable + private SamType createSamType(KotlinType kotlinType) { + if (!JavaSingleAbstractMethodUtils.isSamType(kotlinType)) return null; + return new SamType(kotlinType); + } + + @Nullable + private SamType createSamTypeByValueParameter(ValueParameterDescriptor valueParameterDescriptor) { + KotlinType kotlinSamType = samTypeApproximator.getSamTypeForValueParameter(valueParameterDescriptor); + if (kotlinSamType == null) return null; + if (!JavaSingleAbstractMethodUtils.isSamType(kotlinSamType)) return null; + return new SamType(kotlinSamType); + } + private void writeSamValueForValueParameters( @NotNull Collection valueParametersWithSAMConversion, @Nullable List valueArguments @@ -862,7 +880,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { if (valueArguments == null) return; for (ValueParameterDescriptor valueParameter : valueParametersWithSAMConversion) { - SamType samType = JvmSamTypeFactory.INSTANCE.createByValueParameter(valueParameter, this.languageVersionSettings); + SamType samType = createSamTypeByValueParameter(valueParameter); if (samType == null) continue; ResolvedValueArgument resolvedValueArgument = valueArguments.get(valueParameter.getIndex()); @@ -874,7 +892,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { } private void recordSamTypeOnArgumentExpression(ValueParameterDescriptor valueParameter, ValueArgument valueArgument) { - SamType samType = JvmSamTypeFactory.INSTANCE.createByValueParameter(valueParameter, this.languageVersionSettings); + SamType samType = createSamTypeByValueParameter(valueParameter); if (samType == null) return; recordSamTypeOnArgumentExpression(samType, valueArgument); @@ -955,8 +973,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { KtExpression argumentExpression = argument.getArgumentExpression(); bindingTrace.record(SAM_CONSTRUCTOR_TO_ARGUMENT, expression, argumentExpression); - //noinspection ConstantConditions - SamType samType = JvmSamTypeFactory.INSTANCE.create(callableDescriptor.getReturnType()); + SamType samType = createSamType(callableDescriptor.getReturnType()); bindingTrace.record(SAM_VALUE, argumentExpression, samType); } @@ -973,7 +990,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { FunctionDescriptor original = SamCodegenUtil.getOriginalIfSamAdapter((FunctionDescriptor) operationDescriptor); if (original == null) return; - SamType samType = JvmSamTypeFactory.INSTANCE.createByValueParameter(original.getValueParameters().get(0), this.languageVersionSettings); + SamType samType = createSamTypeByValueParameter(original.getValueParameters().get(0)); if (samType == null) return; IElementType token = expression.getOperationToken(); @@ -1002,7 +1019,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { List indexExpressions = expression.getIndexExpressions(); List parameters = original.getValueParameters(); for (ValueParameterDescriptor valueParameter : parameters) { - SamType samType = JvmSamTypeFactory.INSTANCE.createByValueParameter(valueParameter, this.languageVersionSettings); + SamType samType = createSamTypeByValueParameter(valueParameter); if (samType == null) continue; if (isSetter && valueParameter.getIndex() == parameters.size() - 1) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt index 26c27684873..a82df7c794f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt @@ -147,16 +147,18 @@ class GenerationState private constructor( } } + val languageVersionSettings = configuration.languageVersionSettings + val inlineCache: InlineCache = InlineCache() val incrementalCacheForThisTarget: IncrementalCache? val packagesWithObsoleteParts: Set val obsoleteMultifileClasses: List val deserializationConfiguration: DeserializationConfiguration = - CompilerDeserializationConfiguration(configuration.languageVersionSettings) + CompilerDeserializationConfiguration(languageVersionSettings) val deprecationProvider = DeprecationResolver( - LockBasedStorageManager.NO_LOCKS, configuration.languageVersionSettings, CoroutineCompatibilitySupport.ENABLED, + LockBasedStorageManager.NO_LOCKS, languageVersionSettings, CoroutineCompatibilitySupport.ENABLED, JavaDeprecationSettings ) @@ -197,8 +199,6 @@ class GenerationState private constructor( extraJvmDiagnosticsTrace.bindingContext.diagnostics } - val languageVersionSettings = configuration.languageVersionSettings - val useOldManglingSchemeForFunctionsWithInlineClassesInSignatures = configuration.getBoolean(JVMConfigurationKeys.USE_OLD_INLINE_CLASSES_MANGLING_SCHEME) || languageVersionSettings.languageVersion.run { major == 1 && minor < 4 } @@ -264,7 +264,7 @@ class GenerationState private constructor( val globalInlineContext: GlobalInlineContext = GlobalInlineContext(diagnostics) val mappingsClassesForWhenByEnum: MappingsClassesForWhenByEnum = MappingsClassesForWhenByEnum(this) val jvmRuntimeTypes: JvmRuntimeTypes = JvmRuntimeTypes( - module, configuration.languageVersionSettings, generateOptimizedCallableReferenceSuperClasses + module, languageVersionSettings, generateOptimizedCallableReferenceSuperClasses ) val factory: ClassFileFactory private var duplicateSignatureFactory: BuilderFactoryForDuplicateSignatureDiagnostics? = null diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index e02853b9923..4af0908ad80 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -17749,6 +17749,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/inference/builderInference/kt44241.kt"); } + @Test + @TestMetadata("kt45083.kt") + public void testKt45083() throws Exception { + runTest("compiler/testData/codegen/box/inference/builderInference/kt45083.kt"); + } + @Test @TestMetadata("kt47052.kt") public void testKt47052() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java index 30ee4f7dbcd..79ad5052d1f 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java @@ -2686,6 +2686,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/types/intersectionType3_OI.kt"); } + @Test + @TestMetadata("intersectionTypeInSamType.kt") + public void testIntersectionTypeInSamType() throws Exception { + runTest("compiler/testData/ir/irText/types/intersectionTypeInSamType.kt"); + } + @Test @TestMetadata("javaWildcardType.kt") public void testJavaWildcardType() throws Exception { diff --git a/compiler/ir/backend.jvm/entrypoint/src/org/jetbrains/kotlin/backend/jvm/JvmGeneratorExtensionsImpl.kt b/compiler/ir/backend.jvm/entrypoint/src/org/jetbrains/kotlin/backend/jvm/JvmGeneratorExtensionsImpl.kt index eab98001e4d..ebb19665b9f 100644 --- a/compiler/ir/backend.jvm/entrypoint/src/org/jetbrains/kotlin/backend/jvm/JvmGeneratorExtensionsImpl.kt +++ b/compiler/ir/backend.jvm/entrypoint/src/org/jetbrains/kotlin/backend/jvm/JvmGeneratorExtensionsImpl.kt @@ -7,8 +7,6 @@ package org.jetbrains.kotlin.backend.jvm import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor import org.jetbrains.kotlin.backend.common.ir.createParameterDeclarations -import org.jetbrains.kotlin.codegen.JvmSamTypeFactory -import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations import org.jetbrains.kotlin.incremental.components.NoLookupLocation @@ -60,11 +58,6 @@ open class JvmGeneratorExtensionsImpl(private val generateFacades: Boolean = tru override fun isPlatformSamType(type: KotlinType): Boolean = JavaSingleAbstractMethodUtils.isSamType(type) - override fun getSamTypeForValueParameter( - valueParameter: ValueParameterDescriptor, - languageVersionSettings: LanguageVersionSettings - ): KotlinType? = JvmSamTypeFactory.createByValueParameter(valueParameter, languageVersionSettings)?.type - companion object Instance : JvmSamConversion() } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt index 1c73860d41f..3749ad1e401 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt @@ -127,8 +127,10 @@ internal class LambdaMetafactoryArgumentsBuilder( // Don't try to use indy on SAM types with non-invariant projections because buildFakeOverrideMember doesn't support such supertypes // (and rightly so: supertypes in Kotlin can't have projections in immediate type arguments). This can happen for example in case // the SAM type is instantiated with an intersection type in arguments, which is approximated to an out-projection in psi2ir. - if (samType is IrSimpleType && samType.arguments.any { it is IrTypeProjection && it.variance != Variance.INVARIANT }) - return null + if (samType is IrSimpleType) { + if (samType.arguments.any { it is IrStarProjection || it is IrTypeProjection && it.variance != Variance.INVARIANT }) + return null + } // Do the hard work of matching Kotlin functional interface hierarchy against LambdaMetafactory constraints. // Briefly: sometimes we have to force boxing on the primitive and inline class values, sometimes we have to keep them unboxed. diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt index 6fd225ea3de..66cab2c162a 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt @@ -51,10 +51,7 @@ import org.jetbrains.kotlin.resolve.calls.components.isVararg import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.tower.NewResolvedCallImpl import org.jetbrains.kotlin.resolve.scopes.receivers.* -import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.TypeProjectionImpl -import org.jetbrains.kotlin.types.TypeSubstitutor -import org.jetbrains.kotlin.types.Variance +import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.isUnit import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -567,7 +564,7 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca val typeSubstitutor = TypeSubstitutor.create(substitutionContext) for (i in underlyingValueParameters.indices) { - val underlyingValueParameter = underlyingValueParameters[i] + val underlyingValueParameter: ValueParameterDescriptor = underlyingValueParameters[i] val expectedSamConversionTypesForVararg = if (expectSamConvertedArgumentToBeAvailableInResolvedCall && resolvedCall is NewResolvedCallImpl<*>) { @@ -585,7 +582,7 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca if (!originalValueParameters[i].type.isFunctionTypeOrSubtype) continue } - val samKotlinType = samConversion.getSamTypeForValueParameter(underlyingValueParameter, context.languageVersionSettings) + val samKotlinType = getSamTypeForValueParameter(underlyingValueParameter) ?: underlyingValueParameter.varargElementType // If we have a vararg, vararg element type will be taken ?: underlyingValueParameter.type @@ -645,6 +642,23 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca } } +private fun StatementGenerator.getSamTypeForValueParameter(valueParameter: ValueParameterDescriptor): KotlinType? { + val approximatedSamType = context.samTypeApproximator.getSamTypeForValueParameter(valueParameter) + ?: return null + if (!context.extensions.samConversion.isSamType(approximatedSamType)) + return null + val classDescriptor = approximatedSamType.constructor.declarationDescriptor + ?: throw AssertionError("SAM type is expected to be a class type: $approximatedSamType") + return approximatedSamType.replace( + approximatedSamType.arguments.mapIndexed { index: Int, typeProjection: TypeProjection -> + if (typeProjection.type.constructor.isDenotable) + typeProjection + else + StarProjectionImpl(classDescriptor.typeConstructor.parameters[index]) + } + ) +} + fun StatementGenerator.pregenerateValueArgumentsUsing( call: CallBuilder, resolvedCall: ResolvedCall<*>, diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/GeneratorContext.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/GeneratorContext.kt index d6ebb3de287..2bd7271ed5c 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/GeneratorContext.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/GeneratorContext.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.psi2ir.generators +import org.jetbrains.kotlin.backend.common.SamTypeApproximator import org.jetbrains.kotlin.builtins.ReflectionTypes import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.CallableDescriptor @@ -33,10 +34,12 @@ class GeneratorContext( ) : IrGeneratorContext { internal val callToSubstitutedDescriptorMap = mutableMapOf() - // TODO: inject a correct StorageManager instance, or store NotFoundClasses inside ModuleDescriptor - val reflectionTypes = ReflectionTypes(moduleDescriptor, NotFoundClasses(LockBasedStorageManager.NO_LOCKS, moduleDescriptor)) - fun IrDeclarationReference.commitSubstituted(descriptor: CallableDescriptor) { callToSubstitutedDescriptorMap[this] = descriptor } + + // TODO: inject a correct StorageManager instance, or store NotFoundClasses inside ModuleDescriptor + val reflectionTypes = ReflectionTypes(moduleDescriptor, NotFoundClasses(LockBasedStorageManager.NO_LOCKS, moduleDescriptor)) + + val samTypeApproximator = SamTypeApproximator(moduleDescriptor.builtIns, languageVersionSettings) } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/GeneratorExtensions.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/GeneratorExtensions.kt index bc97737549b..d45c16a5ad9 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/GeneratorExtensions.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/GeneratorExtensions.kt @@ -8,15 +8,12 @@ package org.jetbrains.kotlin.psi2ir.generators import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DescriptorVisibility import org.jetbrains.kotlin.descriptors.PropertyDescriptor -import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.ir.expressions.IrDelegatingConstructorCall import org.jetbrains.kotlin.ir.symbols.IrScriptSymbol import org.jetbrains.kotlin.ir.util.StubGeneratorExtensions import org.jetbrains.kotlin.psi.KtPureClassOrObject import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.backend.common.SamTypeFactory -import org.jetbrains.kotlin.config.LanguageVersionSettings open class GeneratorExtensions : StubGeneratorExtensions() { open val samConversion: SamConversion @@ -25,11 +22,6 @@ open class GeneratorExtensions : StubGeneratorExtensions() { open class SamConversion { open fun isPlatformSamType(type: KotlinType): Boolean = false - open fun getSamTypeForValueParameter( - valueParameter: ValueParameterDescriptor, - languageVersionSettings: LanguageVersionSettings - ): KotlinType? = SamTypeFactory.INSTANCE.createByValueParameter(valueParameter, languageVersionSettings)?.type - companion object Instance : SamConversion() } diff --git a/compiler/testData/codegen/box/sam/approximation/approxToSingleUpperBound.kt b/compiler/testData/codegen/box/sam/approximation/approxToSingleUpperBound.kt index a298c4d7714..28078eb431a 100644 --- a/compiler/testData/codegen/box/sam/approximation/approxToSingleUpperBound.kt +++ b/compiler/testData/codegen/box/sam/approximation/approxToSingleUpperBound.kt @@ -1,3 +1,5 @@ +// IGNORE_BACKEND: WASM + interface X interface Z diff --git a/compiler/testData/ir/irText/types/intersectionTypeInSamType.fir.txt b/compiler/testData/ir/irText/types/intersectionTypeInSamType.fir.txt new file mode 100644 index 00000000000..7d28ee3526c --- /dev/null +++ b/compiler/testData/ir/irText/types/intersectionTypeInSamType.fir.txt @@ -0,0 +1,241 @@ +FILE fqName: fileName:/intersectionTypeInSamType.kt + CLASS INTERFACE name:X modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.X + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:Z modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Z + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:A modality:ABSTRACT visibility:public superTypes:[.X; .Z] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .X + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .Z + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .X + public open fun hashCode (): kotlin.Int [fake_override] declared in .Z + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .X + public open fun toString (): kotlin.String [fake_override] declared in .Z + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:B modality:ABSTRACT visibility:public superTypes:[.X; .Z] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.B + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .X + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .Z + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .X + public open fun hashCode (): kotlin.Int [fake_override] declared in .Z + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .X + public open fun toString (): kotlin.String [fake_override] declared in .Z + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:IFoo modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IFoo.IFoo> + TYPE_PARAMETER name:T index:0 variance: superTypes:[.X] + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.IFoo.IFoo>, t:T of .IFoo) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.IFoo.IFoo> + VALUE_PARAMETER name:t index:0 type:T of .IFoo + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:IBar1 modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IBar1.IBar1> + TYPE_PARAMETER name:T index:0 variance: superTypes:[.X; .Z] + FUN name:bar visibility:public modality:ABSTRACT <> ($this:.IBar1.IBar1>, t:T of .IBar1) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.IBar1.IBar1> + VALUE_PARAMETER name:t index:0 type:T of .IBar1 + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:IBar2 modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IBar2.IBar2> + TYPE_PARAMETER name:T index:0 variance: superTypes:[.X; .Z] + FUN name:bar visibility:public modality:ABSTRACT <> ($this:.IBar2.IBar2>, t:T of .IBar2) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.IBar2.IBar2> + VALUE_PARAMETER name:t index:0 type:T of .IBar2 + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:sel visibility:public modality:FINAL (x:T of .sel, y:T of .sel) returnType:T of .sel + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + VALUE_PARAMETER name:x index:0 type:T of .sel + VALUE_PARAMETER name:y index:1 type:T of .sel + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun sel (x: T of .sel, y: T of .sel): T of .sel declared in ' + GET_VAR 'x: T of .sel declared in .sel' type=T of .sel origin=null + CLASS CLASS name:G1 modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.G1.G1> + TYPE_PARAMETER name:T index:0 variance: superTypes:[.X] + CONSTRUCTOR visibility:public <> () returnType:.G1.G1> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:G1 modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:checkFoo visibility:public modality:FINAL <> ($this:.G1.G1>, x:.IFoo.G1>) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.G1.G1> + VALUE_PARAMETER name:x index:0 type:.IFoo.G1> + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:G2 modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.G2.G2> + TYPE_PARAMETER name:T index:0 variance: superTypes:[.X; .Z] + CONSTRUCTOR visibility:public <> () returnType:.G2.G2> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:G2 modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:checkFoo visibility:public modality:FINAL <> ($this:.G2.G2>, x:.IFoo.G2>) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.G2.G2> + VALUE_PARAMETER name:x index:0 type:.IFoo.G2> + BLOCK_BODY + FUN name:checkBar1 visibility:public modality:FINAL <> ($this:.G2.G2>, x:.IBar1.G2>) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.G2.G2> + VALUE_PARAMETER name:x index:0 type:.IBar1.G2> + BLOCK_BODY + FUN name:checkBar2 visibility:public modality:FINAL <> ($this:.G2.G2>, x:.IBar2.G2>) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.G2.G2> + VALUE_PARAMETER name:x index:0 type:.IBar2.G2> + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + VAR name:g type:.G1<*> [val] + CALL 'public final fun sel (x: T of .sel, y: T of .sel): T of .sel declared in ' type=.G1<*> origin=null + : .G1<*> + x: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .G1' type=.G1<.A> origin=null + : .A + y: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .G1' type=.G1<.B> origin=null + : .B + CALL 'public final fun checkFoo (x: .IFoo.G1>): kotlin.Unit declared in .G1' type=kotlin.Unit origin=null + $this: GET_VAR 'val g: .G1<*> [val] declared in .test1' type=.G1<*> origin=null + x: TYPE_OP type=.IFoo origin=SAM_CONVERSION typeOperand=.IFoo + FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:.X) returnType:kotlin.Unit + VALUE_PARAMETER name:it index:0 type:.X + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (it: .X): kotlin.Unit declared in .test1' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + VAR name:g type:.G2<*> [val] + CALL 'public final fun sel (x: T of .sel, y: T of .sel): T of .sel declared in ' type=.G2<*> origin=null + : .G2<*> + x: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .G2' type=.G2<.A> origin=null + : .A + y: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .G2' type=.G2<.B> origin=null + : .B + CALL 'public final fun checkFoo (x: .IFoo.G2>): kotlin.Unit declared in .G2' type=kotlin.Unit origin=null + $this: GET_VAR 'val g: .G2<*> [val] declared in .test2' type=.G2<*> origin=null + x: TYPE_OP type=.IFoo origin=SAM_CONVERSION typeOperand=.IFoo + FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:.X) returnType:kotlin.Unit + VALUE_PARAMETER name:it index:0 type:.X + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (it: .X): kotlin.Unit declared in .test2' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + CALL 'public final fun checkBar1 (x: .IBar1.G2>): kotlin.Unit declared in .G2' type=kotlin.Unit origin=null + $this: GET_VAR 'val g: .G2<*> [val] declared in .test2' type=.G2<*> origin=null + x: TYPE_OP type=.IBar1 origin=SAM_CONVERSION typeOperand=.IBar1 + FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:.X) returnType:kotlin.Unit + VALUE_PARAMETER name:it index:0 type:.X + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (it: .X): kotlin.Unit declared in .test2' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + CALL 'public final fun checkBar2 (x: .IBar2.G2>): kotlin.Unit declared in .G2' type=kotlin.Unit origin=null + $this: GET_VAR 'val g: .G2<*> [val] declared in .test2' type=.G2<*> origin=null + x: TYPE_OP type=.IBar2 origin=SAM_CONVERSION typeOperand=.IBar2 + FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:.X) returnType:kotlin.Unit + VALUE_PARAMETER name:it index:0 type:.X + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (it: .X): kotlin.Unit declared in .test2' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit diff --git a/compiler/testData/ir/irText/types/intersectionTypeInSamType.kt b/compiler/testData/ir/irText/types/intersectionTypeInSamType.kt new file mode 100644 index 00000000000..3c03f8a4a2e --- /dev/null +++ b/compiler/testData/ir/irText/types/intersectionTypeInSamType.kt @@ -0,0 +1,44 @@ +// SKIP_KT_DUMP + +interface X +interface Z + +interface A : X, Z +interface B : X, Z + +fun interface IFoo { + fun foo(t: T) +} + +fun interface IBar1 where T : X, T : Z { + fun bar(t: T) +} + +fun interface IBar2 where T : X, T : Z { + fun bar(t: T) +} + +fun sel(x: T, y: T) = x + +class G1 { + fun checkFoo(x: IFoo) {} +} + +class G2 where T : X, T : Z { + fun checkFoo(x: IFoo) {} + fun checkBar1(x: IBar1) {} + fun checkBar2(x: IBar2) {} +} + + +fun test1() { + val g = sel(G1(), G1()) + g.checkFoo {} +} + +fun test2() { + val g = sel(G2(), G2()) + g.checkFoo {} + g.checkBar1 {} + g.checkBar2 {} +} diff --git a/compiler/testData/ir/irText/types/intersectionTypeInSamType.txt b/compiler/testData/ir/irText/types/intersectionTypeInSamType.txt new file mode 100644 index 00000000000..60c4361575c --- /dev/null +++ b/compiler/testData/ir/irText/types/intersectionTypeInSamType.txt @@ -0,0 +1,243 @@ +FILE fqName: fileName:/intersectionTypeInSamType.kt + CLASS INTERFACE name:X modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.X + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:Z modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Z + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:A modality:ABSTRACT visibility:public superTypes:[.X; .Z] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .X + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .Z + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .X + public open fun hashCode (): kotlin.Int [fake_override] declared in .Z + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .X + public open fun toString (): kotlin.String [fake_override] declared in .Z + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:B modality:ABSTRACT visibility:public superTypes:[.X; .Z] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.B + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .X + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .Z + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .X + public open fun hashCode (): kotlin.Int [fake_override] declared in .Z + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .X + public open fun toString (): kotlin.String [fake_override] declared in .Z + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:IFoo modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IFoo.IFoo> + TYPE_PARAMETER name:T index:0 variance: superTypes:[.X] + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.IFoo.IFoo>, t:T of .IFoo) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.IFoo.IFoo> + VALUE_PARAMETER name:t index:0 type:T of .IFoo + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:IBar1 modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IBar1.IBar1> + TYPE_PARAMETER name:T index:0 variance: superTypes:[.X; .Z] + FUN name:bar visibility:public modality:ABSTRACT <> ($this:.IBar1.IBar1>, t:T of .IBar1) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.IBar1.IBar1> + VALUE_PARAMETER name:t index:0 type:T of .IBar1 + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:IBar2 modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IBar2.IBar2> + TYPE_PARAMETER name:T index:0 variance: superTypes:[.X; .Z] + FUN name:bar visibility:public modality:ABSTRACT <> ($this:.IBar2.IBar2>, t:T of .IBar2) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.IBar2.IBar2> + VALUE_PARAMETER name:t index:0 type:T of .IBar2 + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:sel visibility:public modality:FINAL (x:T of .sel, y:T of .sel) returnType:T of .sel + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + VALUE_PARAMETER name:x index:0 type:T of .sel + VALUE_PARAMETER name:y index:1 type:T of .sel + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun sel (x: T of .sel, y: T of .sel): T of .sel declared in ' + GET_VAR 'x: T of .sel declared in .sel' type=T of .sel origin=null + CLASS CLASS name:G1 modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.G1.G1> + TYPE_PARAMETER name:T index:0 variance: superTypes:[.X] + CONSTRUCTOR visibility:public <> () returnType:.G1.G1> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:G1 modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:checkFoo visibility:public modality:FINAL <> ($this:.G1.G1>, x:.IFoo.G1>) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.G1.G1> + VALUE_PARAMETER name:x index:0 type:.IFoo.G1> + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:G2 modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.G2.G2> + TYPE_PARAMETER name:T index:0 variance: superTypes:[.X; .Z] + CONSTRUCTOR visibility:public <> () returnType:.G2.G2> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:G2 modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:checkFoo visibility:public modality:FINAL <> ($this:.G2.G2>, x:.IFoo.G2>) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.G2.G2> + VALUE_PARAMETER name:x index:0 type:.IFoo.G2> + BLOCK_BODY + FUN name:checkBar1 visibility:public modality:FINAL <> ($this:.G2.G2>, x:.IBar1.G2>) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.G2.G2> + VALUE_PARAMETER name:x index:0 type:.IBar1.G2> + BLOCK_BODY + FUN name:checkBar2 visibility:public modality:FINAL <> ($this:.G2.G2>, x:.IBar2.G2>) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.G2.G2> + VALUE_PARAMETER name:x index:0 type:.IBar2.G2> + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + VAR name:g type:.G1<*> [val] + CALL 'public final fun sel (x: T of .sel, y: T of .sel): T of .sel declared in ' type=.G1<*> origin=null + : .G1<*> + x: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .G1' type=.G1<.A> origin=null + : .A + y: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .G1' type=.G1<.B> origin=null + : .B + CALL 'public final fun checkFoo (x: .IFoo.G1>): kotlin.Unit declared in .G1' type=kotlin.Unit origin=null + $this: GET_VAR 'val g: .G1<*> [val] declared in .test1' type=.G1<*> origin=null + x: TYPE_OP type=.IFoo<.X> origin=SAM_CONVERSION typeOperand=.IFoo<.X> + TYPE_OP type=kotlin.Function1<@[ParameterName(name = 't')] .X, kotlin.Unit> origin=IMPLICIT_CAST typeOperand=kotlin.Function1<@[ParameterName(name = 't')] .X, kotlin.Unit> + FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:kotlin.Any) returnType:kotlin.Unit + VALUE_PARAMETER name:it index:0 type:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (it: kotlin.Any): kotlin.Unit declared in .test1' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + VAR name:g type:.G2<*> [val] + CALL 'public final fun sel (x: T of .sel, y: T of .sel): T of .sel declared in ' type=.G2<*> origin=null + : .G2<*> + x: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .G2' type=.G2<.A> origin=null + : .A + y: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .G2' type=.G2<.B> origin=null + : .B + CALL 'public final fun checkFoo (x: .IFoo.G2>): kotlin.Unit declared in .G2' type=kotlin.Unit origin=null + $this: GET_VAR 'val g: .G2<*> [val] declared in .test2' type=.G2<*> origin=null + x: TYPE_OP type=.IFoo<.X> origin=SAM_CONVERSION typeOperand=.IFoo<.X> + TYPE_OP type=kotlin.Function1<@[ParameterName(name = 't')] .X, kotlin.Unit> origin=IMPLICIT_CAST typeOperand=kotlin.Function1<@[ParameterName(name = 't')] .X, kotlin.Unit> + FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:kotlin.Any) returnType:kotlin.Unit + VALUE_PARAMETER name:it index:0 type:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (it: kotlin.Any): kotlin.Unit declared in .test2' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + CALL 'public final fun checkBar1 (x: .IBar1.G2>): kotlin.Unit declared in .G2' type=kotlin.Unit origin=null + $this: GET_VAR 'val g: .G2<*> [val] declared in .test2' type=.G2<*> origin=null + x: TYPE_OP type=.IBar1<*> origin=SAM_CONVERSION typeOperand=.IBar1<*> + FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:kotlin.Any) returnType:kotlin.Unit + VALUE_PARAMETER name:it index:0 type:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (it: kotlin.Any): kotlin.Unit declared in .test2' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + CALL 'public final fun checkBar2 (x: .IBar2.G2>): kotlin.Unit declared in .G2' type=kotlin.Unit origin=null + $this: GET_VAR 'val g: .G2<*> [val] declared in .test2' type=.G2<*> origin=null + x: TYPE_OP type=.IBar2<*> origin=SAM_CONVERSION typeOperand=.IBar2<*> + FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:kotlin.Any) returnType:kotlin.Unit + VALUE_PARAMETER name:it index:0 type:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (it: kotlin.Any): kotlin.Unit declared in .test2' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 39988fa095a..c4b0998814b 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -17713,6 +17713,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inference/builderInference/kt44241.kt"); } + @Test + @TestMetadata("kt45083.kt") + public void testKt45083() throws Exception { + runTest("compiler/testData/codegen/box/inference/builderInference/kt45083.kt"); + } + @Test @TestMetadata("kt47052.kt") public void testKt47052() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 8076f0e6ecf..b0a28b54a17 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -17749,6 +17749,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inference/builderInference/kt44241.kt"); } + @Test + @TestMetadata("kt45083.kt") + public void testKt45083() throws Exception { + runTest("compiler/testData/codegen/box/inference/builderInference/kt45083.kt"); + } + @Test @TestMetadata("kt47052.kt") public void testKt47052() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java index 34c27332858..cc19212feaa 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java @@ -2686,6 +2686,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest { runTest("compiler/testData/ir/irText/types/intersectionType3_OI.kt"); } + @Test + @TestMetadata("intersectionTypeInSamType.kt") + public void testIntersectionTypeInSamType() throws Exception { + runTest("compiler/testData/ir/irText/types/intersectionTypeInSamType.kt"); + } + @Test @TestMetadata("javaWildcardType.kt") public void testJavaWildcardType() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 8f91bbd0036..d05e7c8b814 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -14666,6 +14666,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inference/builderInference/kt44241.kt"); } + @TestMetadata("kt45083.kt") + public void testKt45083() throws Exception { + runTest("compiler/testData/codegen/box/inference/builderInference/kt45083.kt"); + } + @TestMetadata("kt47052.kt") public void testKt47052() throws Exception { runTest("compiler/testData/codegen/box/inference/builderInference/kt47052.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index bda657f841e..b38ed687250 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -12820,6 +12820,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/inference/builderInference/kt44241.kt"); } + @TestMetadata("kt45083.kt") + public void testKt45083() throws Exception { + runTest("compiler/testData/codegen/box/inference/builderInference/kt45083.kt"); + } + @TestMetadata("kt47052.kt") public void testKt47052() throws Exception { runTest("compiler/testData/codegen/box/inference/builderInference/kt47052.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 47016356f74..7f9bafbe0a7 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -12226,6 +12226,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inference/builderInference/kt44241.kt"); } + @TestMetadata("kt45083.kt") + public void testKt45083() throws Exception { + runTest("compiler/testData/codegen/box/inference/builderInference/kt45083.kt"); + } + @TestMetadata("kt47052.kt") public void testKt47052() throws Exception { runTest("compiler/testData/codegen/box/inference/builderInference/kt47052.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 8f191cd0c02..d23a445774c 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -12291,6 +12291,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inference/builderInference/kt44241.kt"); } + @TestMetadata("kt45083.kt") + public void testKt45083() throws Exception { + runTest("compiler/testData/codegen/box/inference/builderInference/kt45083.kt"); + } + @TestMetadata("kt47052.kt") public void testKt47052() throws Exception { runTest("compiler/testData/codegen/box/inference/builderInference/kt47052.kt");