From 78b6432cedda8a277748b46a7d3c5ae96489d021 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 21 Feb 2024 13:58:26 +0100 Subject: [PATCH] K2: don't make T = Type! substitutions for constructors, including SAM Without this commit we get some ABI changes and it looks bad. Related to KT-65596 --- ...tructorViaTypeAlias.descriptors.pretty.txt | 1 - .../resolve/arguments/lambdaInLambda2.fir.txt | 2 +- .../resolve/defaultJavaImportHiding.fir.txt | 4 +- .../expresssions/genericDiagnostic.fir.txt | 4 +- .../flexibleTypeVarAgainstNull.fir.txt | 2 +- .../samConstructors/genericSam.fir.txt | 2 +- .../smartcasts/smartcastedField.fir.txt | 8 +-- .../concurrentMapOfAliases.fir.txt | 4 +- .../javaLangComparator.fir.txt | 2 +- .../NamedParameterInConcurrentMap.fir.txt | 2 +- .../problems/malformedRawTypes.fir.txt | 4 +- .../problems/weakHashMap.fir.txt | 4 +- .../typeAliasWithForEach.fir.txt | 4 +- ...CreateFreshTypeVariableSubstitutorStage.kt | 55 ++++++++++++++++++- .../fir/javaTypeParameterBy.jvm_abi.txt | 9 --- .../fir/javaTypeParameterBy.kt | 2 - .../contravariantIntersectionType.jvm_abi.txt | 2 - .../strictMode/interconnectedGenerics.fir.txt | 2 +- .../samConversionToGeneric.fir.kt | 2 +- .../samConversionToGeneric.fir.txt | 43 +++++++++++++++ .../samConversions/samConversionToGeneric.kt | 2 +- ...ructorWithOwnTypeParametersCall.fir.ir.txt | 12 ++-- ...ructorWithOwnTypeParametersCall.fir.kt.txt | 5 +- .../sam/samConversionToGeneric.fir.ir.txt | 6 +- .../sam/samConversionToGeneric.fir.kt.txt | 4 +- ...vaConstructorWithTypeParameters.fir.ir.txt | 32 +++++------ ...vaConstructorWithTypeParameters.fir.kt.txt | 16 +++--- 27 files changed, 159 insertions(+), 76 deletions(-) delete mode 100644 analysis/analysis-api/testData/symbols/symbolByReference/constructorViaTypeAlias.descriptors.pretty.txt delete mode 100644 compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.jvm_abi.txt create mode 100644 compiler/testData/diagnostics/tests/samConversions/samConversionToGeneric.fir.txt diff --git a/analysis/analysis-api/testData/symbols/symbolByReference/constructorViaTypeAlias.descriptors.pretty.txt b/analysis/analysis-api/testData/symbols/symbolByReference/constructorViaTypeAlias.descriptors.pretty.txt deleted file mode 100644 index 68acaedb3d3..00000000000 --- a/analysis/analysis-api/testData/symbols/symbolByReference/constructorViaTypeAlias.descriptors.pretty.txt +++ /dev/null @@ -1 +0,0 @@ -constructor(c: kotlin.collections.(Mutable)Collection!) \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/arguments/lambdaInLambda2.fir.txt b/compiler/fir/analysis-tests/testData/resolve/arguments/lambdaInLambda2.fir.txt index 003cf064027..bb18e9b2ca6 100644 --- a/compiler/fir/analysis-tests/testData/resolve/arguments/lambdaInLambda2.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/arguments/lambdaInLambda2.fir.txt @@ -7,7 +7,7 @@ FILE: main.kt public abstract interface PsiClass : R|kotlin/Any| { } public final fun test(): R|kotlin/Unit| { - lval processor: R|AdapterProcessor| = R|/AdapterProcessor.AdapterProcessor|(R|/Function|( = Function@fun (method: R|PsiMethod?|): R|PsiClass?| { + lval processor: R|AdapterProcessor| = R|/AdapterProcessor.AdapterProcessor|(R|/Function|( = Function@fun (method: R|PsiMethod?|): R|PsiClass?| { ^ R|/method|?.{ $subj$.R|/PsiMethod.containingClass| } } )) diff --git a/compiler/fir/analysis-tests/testData/resolve/defaultJavaImportHiding.fir.txt b/compiler/fir/analysis-tests/testData/resolve/defaultJavaImportHiding.fir.txt index 0303e443ffe..17376191360 100644 --- a/compiler/fir/analysis-tests/testData/resolve/defaultJavaImportHiding.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/defaultJavaImportHiding.fir.txt @@ -26,13 +26,13 @@ FILE: main.kt } public final fun test_1(): R|kotlin/Unit| { - lval map: R|util/HashMap| = R|util/HashMap.HashMap|() + lval map: R|util/HashMap| = R|util/HashMap.HashMap|() } public final fun test_2(): R|kotlin/Unit| { lval set: R|util/HashSet| = R|util/HashSet.HashSet|() } public final fun test_3(): R|kotlin/Unit| { - lval list: R|foo/ArrayList| = R|foo/ArrayList.ArrayList|() + lval list: R|foo/ArrayList| = R|foo/ArrayList.ArrayList|() } public final fun test_4(): R|kotlin/Unit| { lval list: R|foo/LinkedList| = R|foo/LinkedList.LinkedList|() diff --git a/compiler/fir/analysis-tests/testData/resolve/expresssions/genericDiagnostic.fir.txt b/compiler/fir/analysis-tests/testData/resolve/expresssions/genericDiagnostic.fir.txt index cc560fe19c6..2356f2c98de 100644 --- a/compiler/fir/analysis-tests/testData/resolve/expresssions/genericDiagnostic.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/expresssions/genericDiagnostic.fir.txt @@ -13,8 +13,8 @@ FILE: test.kt lval element: R|DE| = R|/d|.R|/Diagnostic.element| R|/Fix.Fix|(R|/element|) } - private final val DERIVED_FACTORY: R|DiagnosticFactory0| = R|/DiagnosticFactory0.DiagnosticFactory0|() - private get(): R|DiagnosticFactory0| + private final val DERIVED_FACTORY: R|DiagnosticFactory0| = R|/DiagnosticFactory0.DiagnosticFactory0|() + private get(): R|DiagnosticFactory0| public final fun createViaFactory(d: R|EmptyDiagnostic|): R|kotlin/Unit| { lval casted: R|Diagnostic| = R|/DERIVED_FACTORY|.R|SubstitutionOverride|>|(R|/d|) lval element: R|DerivedElement| = R|/casted|.R|/Diagnostic.element| diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/flexibleTypeVarAgainstNull.fir.txt b/compiler/fir/analysis-tests/testData/resolve/problems/flexibleTypeVarAgainstNull.fir.txt index a95e188c7d4..a9922199723 100644 --- a/compiler/fir/analysis-tests/testData/resolve/problems/flexibleTypeVarAgainstNull.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/problems/flexibleTypeVarAgainstNull.fir.txt @@ -1,4 +1,4 @@ FILE: main.kt public final fun main(): R|kotlin/Unit| { - R|/JavaClass.JavaClass|(Null(null)).R|SubstitutionOverride|().R|kotlin/String.length| + R|/JavaClass.JavaClass|(Null(null)).R|SubstitutionOverride|().R|kotlin/String.length| } diff --git a/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSam.fir.txt b/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSam.fir.txt index ac5c36ea0f0..f7d7f5ea70a 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSam.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSam.fir.txt @@ -1,6 +1,6 @@ FILE: main.kt public final fun main(): R|kotlin/Unit| { - R|/MyFunction|( = MyFunction@fun (x: R|kotlin/Int!|): R|kotlin/String!| { + R|/MyFunction|( = MyFunction@fun (x: R|kotlin/Int!|): R|kotlin/String!| { ^ R|/x|.R|kotlin/Int.toInt|().R|kotlin/Int.toString|() } ) diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastedField.fir.txt b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastedField.fir.txt index 4e05967570c..449cc8faeaf 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastedField.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastedField.fir.txt @@ -1,8 +1,8 @@ FILE: main.kt - private final val anyProperty: R|Property| = R|/Property.Property|() - private get(): R|Property| - private final val boundedProperty: R|Property| = R|/Property.Property|() - private get(): R|Property| + private final val anyProperty: R|Property| = R|/Property.Property|() + private get(): R|Property| + private final val boundedProperty: R|Property| = R|/Property.Property|() + private get(): R|Property| public final fun test_1(x: R|Property|): R|kotlin/Unit| { when () { (R|/x| is R|Reference|) -> { diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/concurrentMapOfAliases.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/concurrentMapOfAliases.fir.txt index 67cbd334f26..8d3fa46a413 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/concurrentMapOfAliases.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/concurrentMapOfAliases.fir.txt @@ -5,8 +5,8 @@ FILE: concurrentMapOfAliases.kt super() } - private final val foo: R|java/util/concurrent/ConcurrentHashMap| = Q|java/util/concurrent|.R|java/util/concurrent/ConcurrentHashMap.ConcurrentHashMap|() - private get(): R|java/util/concurrent/ConcurrentHashMap| + private final val foo: R|java/util/concurrent/ConcurrentHashMap| = Q|java/util/concurrent|.R|java/util/concurrent/ConcurrentHashMap.ConcurrentHashMap|() + private get(): R|java/util/concurrent/ConcurrentHashMap| private final fun bar(): R|kotlin/Unit| { this@R|/A|.R|/A.foo|.R|SubstitutionOverride|(String(dd))?.{ (this@R|/A|, $subj$).R|/A.baz|() } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/javaLangComparator.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/javaLangComparator.fir.txt index 781f8d24264..f79a31161e3 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/javaLangComparator.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/javaLangComparator.fir.txt @@ -1,6 +1,6 @@ FILE: javaLangComparator.kt public final fun test_2(list: R|kotlin/collections/List|): R|kotlin/Unit| { - lval comp: R|java/util/Comparator| = Q|java/util|.R|java/util/Comparator|( = Comparator@fun (x: R|kotlin/Int!|, y: R|kotlin/Int!|): R|kotlin/Int| { + lval comp: R|java/util/Comparator| = Q|java/util|.R|java/util/Comparator|( = Comparator@fun (x: R|kotlin/Int!|, y: R|kotlin/Int!|): R|kotlin/Int| { ^ Int(1) } ) diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/NamedParameterInConcurrentMap.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/NamedParameterInConcurrentMap.fir.txt index 46d1480c955..5a8588c350c 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/NamedParameterInConcurrentMap.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/NamedParameterInConcurrentMap.fir.txt @@ -1,5 +1,5 @@ FILE: NamedParameterInConcurrentMap.kt public final fun main(): R|kotlin/Unit| { - lval map: R|java/util/concurrent/ConcurrentHashMap| = R|java/util/concurrent/ConcurrentHashMap.ConcurrentHashMap|() + lval map: R|java/util/concurrent/ConcurrentHashMap| = R|java/util/concurrent/ConcurrentHashMap.ConcurrentHashMap|() R|/map|.R|SubstitutionOverride|(key = String(key), value = String(value)) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/malformedRawTypes.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/malformedRawTypes.fir.txt index c1eeb56455c..b2126ae3e11 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/malformedRawTypes.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/malformedRawTypes.fir.txt @@ -2,7 +2,7 @@ FILE: Main.kt public final fun main(): R|kotlin/Unit| { lvar generic: R|ft, Generic<*>?>| = Q|Generic|.R|/Generic.raw*s| lvar inner1: R|ft, Generic.Inner<*>?>| = R|/generic|.R|SubstitutionOverride| - R|/inner1| = R|/Generic.Generic|().R|SubstitutionOverride|() + R|/inner1| = R|/Generic.Generic|().R|SubstitutionOverride|() lvar inner2: R|ft, Generic.Inner<*>?>| = R|/generic|.R|SubstitutionOverride| - R|/inner2| = R|/Generic.Generic|().R|SubstitutionOverride|() + R|/inner2| = R|/Generic.Generic|().R|SubstitutionOverride|() } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/weakHashMap.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/weakHashMap.fir.txt index cf244330b65..6f3187fc599 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/weakHashMap.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/weakHashMap.fir.txt @@ -1,6 +1,6 @@ FILE: weakHashMap.kt - public final val someMap: R|java/util/WeakHashMap| = R|java/util/WeakHashMap.WeakHashMap|() - public get(): R|java/util/WeakHashMap| + public final val someMap: R|java/util/WeakHashMap| = R|java/util/WeakHashMap.WeakHashMap|() + public get(): R|java/util/WeakHashMap| public final fun foo(): R|kotlin/Unit| { R|/someMap|.R|SubstitutionOverride|(String()) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/typeAliasWithForEach.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/typeAliasWithForEach.fir.txt index fa5f3fe2096..e00e26606fe 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/typeAliasWithForEach.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/typeAliasWithForEach.fir.txt @@ -9,9 +9,9 @@ FILE: typeAliasWithForEach.kt } public final typealias Arguments = R|kotlin/collections/Map| public final fun R|Arguments|.deepCopy(): R|Arguments| { - lval result: R|java/util/HashMap| = R|java/util/HashMap.HashMap|() + lval result: R|java/util/HashMap| = R|java/util/HashMap.HashMap|() this@R|/deepCopy|.R|SubstitutionOverride|( = SAM(forEach@fun (key: R|@EnhancedNullability kotlin/String|, value: R|@EnhancedNullability ArgsInfo|): R|kotlin/Unit| { - R|/result|.R|kotlin/collections/set|(R|/key|, R|/ArgsInfoImpl.ArgsInfoImpl|(R|/value|)) + R|/result|.R|kotlin/collections/set|(R|/key|, R|/ArgsInfoImpl.ArgsInfoImpl|(R|/value|)) Unit } )) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt index a76ace8d654..fd15cce144d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap import org.jetbrains.kotlin.fir.scopes.impl.toConeType import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag +import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.name.StandardClassIds @@ -82,12 +83,64 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() { } } + /** + * This function provides a type for a newly created EQUALS constraint on a fresh type variable, + * for a situation when we have an explicit type argument and type parameter is a Java type parameter without known nullability. + * + * For a normal function call, like foo, we create a constraint T = SomeType!. + * This is an unsafe solution, however yet we have to keep it, otherwise a lot of code becomes red. + * Typical "strange" example: + * + * ``` + * // Java + * public class Foo { + * static T id(T foo) { + * return null; + * } + * } + * + * // Kotlin + * fun test(): String { + * return Foo.id(null) // OK... + * } + * ``` + * + * We keep more sound constraint T = SomeType for regular and SAM constructor calls. Typical examples are: + * + * ``` + * fun test1() = J1() // type should be J1, not J1 + * // J1.java + * public class J1 {} + * ``` + * + * or + * + * ``` + * // Again, type should be J and not J + * fun test1() = J { x -> x } + * + * + * // FILE: J.java + * public interface J { + * T foo(T x); + * } + * ``` + * + * @return type which is chosen for EQUALS constraint + */ private fun getTypePreservingFlexibilityWrtTypeVariable( type: ConeKotlinType, typeParameter: FirTypeParameterRef, session: FirSession, ): ConeKotlinType { - return if (typeParameter.shouldBeFlexible(session.typeContext)) { + val containingDeclarationSymbol = typeParameter.symbol.containingDeclarationSymbol + // To remove constructors (they use class type parameters) + return if ( + containingDeclarationSymbol is FirCallableSymbol && + // To remove SAMs + containingDeclarationSymbol !is FirSyntheticFunctionSymbol && + typeParameter.shouldBeFlexible(session.typeContext) + ) { val notNullType = type.withNullability(ConeNullability.NOT_NULL, session.typeContext) as ConeSimpleKotlinType ConeFlexibleType(notNullType, notNullType.withNullability(ConeNullability.NULLABLE, session.typeContext)) } else { diff --git a/compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.jvm_abi.txt b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.jvm_abi.txt deleted file mode 100644 index 0e34ad9b0bd..00000000000 --- a/compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.jvm_abi.txt +++ /dev/null @@ -1,9 +0,0 @@ -MODULE lib - CLASS A.class - CLASS METADATA - FUNCTION foo()Ljava/lang/Comparable; - Property: class.metadata.function.typeParameters - K1 - !> - K2 - !> diff --git a/compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.kt b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.kt index 29cdd4c1c99..eba02923b30 100644 --- a/compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.kt +++ b/compiler/testData/codegen/box/compileKotlinAgainstKotlin/fir/javaTypeParameterBy.kt @@ -2,8 +2,6 @@ // WITH_STDLIB // MODULE: lib -// JVM_ABI_K1_K2_DIFF: KT-63870 - // FILE: JavaInterface.java public interface JavaInterface { > K foo(); diff --git a/compiler/testData/codegen/box/sam/contravariantIntersectionType.jvm_abi.txt b/compiler/testData/codegen/box/sam/contravariantIntersectionType.jvm_abi.txt index 8925ee1bf6c..fe049233a5c 100644 --- a/compiler/testData/codegen/box/sam/contravariantIntersectionType.jvm_abi.txt +++ b/compiler/testData/codegen/box/sam/contravariantIntersectionType.jvm_abi.txt @@ -1,6 +1,4 @@ MODULE main - Missing in K2 - TestKt$example$2.class CLASS TestKt$example$1.class Property: class.signature K1 diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/interconnectedGenerics.fir.txt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/interconnectedGenerics.fir.txt index 8c5a52a5efc..fca21f65196 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/interconnectedGenerics.fir.txt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/interconnectedGenerics.fir.txt @@ -34,7 +34,7 @@ FILE: Eq.kt public get(): R|lib/a/A| public open override fun withL(l: R|kotlin/Int|): R|lib/a/C.WithL| { - ^withL Q|lib/a/C|.R|lib/a/C.MyWithL.MyWithL|() + ^withL Q|lib/a/C|.R|lib/a/C.MyWithL.MyWithL|() } } diff --git a/compiler/testData/diagnostics/tests/samConversions/samConversionToGeneric.fir.kt b/compiler/testData/diagnostics/tests/samConversions/samConversionToGeneric.fir.kt index 8df5c9a6ada..2bf9789f4f4 100644 --- a/compiler/testData/diagnostics/tests/samConversions/samConversionToGeneric.fir.kt +++ b/compiler/testData/diagnostics/tests/samConversions/samConversionToGeneric.fir.kt @@ -1,4 +1,4 @@ - +// FIR_DUMP // FILE: samConversionToGeneric.kt fun test1() = J { x -> x } diff --git a/compiler/testData/diagnostics/tests/samConversions/samConversionToGeneric.fir.txt b/compiler/testData/diagnostics/tests/samConversions/samConversionToGeneric.fir.txt new file mode 100644 index 00000000000..44db1ef5e8d --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/samConversionToGeneric.fir.txt @@ -0,0 +1,43 @@ +FILE: samConversionToGeneric.kt + public final fun test1(): R|J| { + ^test1 R|/J|( = J@fun (x: R|kotlin/String!|): R|kotlin/String!| { + ^ R|/x| + } + ) + } + public final fun test2(): R|J| { + ^test2 R|/J|( = J@fun (x: R|kotlin/String|): R|kotlin/String!| { + ^ R|/x| + } + ) + } + public final fun test3(): R|kotlin/Unit| { + ^test3 Q|H|.R|/H.bar*s|( = SAM(bar@fun (x: R|kotlin/String|): R|kotlin/String!| { + ^ R|/x| + } + )) + } + public final fun test4(a: R|kotlin/Any|): R|kotlin/Unit| { + (R|/a| as R|J|) + Q|H|.R|/H.bar*s|(R|/a|) + } + public final fun test5(a: R|kotlin/Any|): R|kotlin/Unit| { + (R|/a| as R|(kotlin/String) -> kotlin/String|) + Q|H|.R|/H.bar*s|(SAM(R|/a|)) + } + public final fun test6(a: R|(T) -> T|): R|kotlin/Unit| { + Q|H|.R|/H.bar*s|(SAM(R|/a|)) + } + public final fun test7(a: R|kotlin/Any|): R|kotlin/Unit| { + (R|/a| as R|(T) -> T|) + Q|H|.R|/H.bar*s|(SAM(R|/a|)) + } + public final fun test8(efn: R|kotlin/String.() -> kotlin/String|): R|J| { + ^test8 R|/J|(R|/efn|) + } + public final fun test9(efn: R|kotlin/String.() -> kotlin/String|): R|kotlin/Unit| { + Q|H|.R|/H.bar*s|(SAM(R|/efn|)) + } + public final fun test10(fn: R|(kotlin/Int) -> kotlin/String|): R|kotlin/Unit| { + Q|H|.R|/H.bar2x*s|(SAM(R|/fn|)) + } diff --git a/compiler/testData/diagnostics/tests/samConversions/samConversionToGeneric.kt b/compiler/testData/diagnostics/tests/samConversions/samConversionToGeneric.kt index 7fab6d479e9..85e7a4ad263 100644 --- a/compiler/testData/diagnostics/tests/samConversions/samConversionToGeneric.kt +++ b/compiler/testData/diagnostics/tests/samConversions/samConversionToGeneric.kt @@ -1,4 +1,4 @@ - +// FIR_DUMP // FILE: samConversionToGeneric.kt fun test1() = J { x -> x } diff --git a/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.ir.txt b/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.ir.txt index 2ad89ee285c..3a987c02c8f 100644 --- a/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.ir.txt @@ -40,14 +40,14 @@ FILE fqName: fileName:/constructorWithOwnTypeParametersCall.kt overridden: public open fun toString (): kotlin.String declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any - FUN name:testJava visibility:public modality:FINAL <> () returnType:.J1.J2<@[FlexibleNullability] kotlin.Double?, @[FlexibleNullability] kotlin.Int?> + FUN name:testJava visibility:public modality:FINAL <> () returnType:.J1.J2 BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun testJava (): .J1.J2<@[FlexibleNullability] kotlin.Double?, @[FlexibleNullability] kotlin.Int?> declared in ' - CONSTRUCTOR_CALL 'public constructor () declared in .J1.J2' type=.J1.J2<@[FlexibleNullability] kotlin.Double?, @[FlexibleNullability] kotlin.Int?> origin=null - : @[FlexibleNullability] kotlin.Double? + RETURN type=kotlin.Nothing from='public final fun testJava (): .J1.J2 declared in ' + CONSTRUCTOR_CALL 'public constructor () declared in .J1.J2' type=.J1.J2 origin=null + : kotlin.Double : @[FlexibleNullability] kotlin.CharSequence? - $outer: CONSTRUCTOR_CALL 'public constructor () declared in .J1' type=.J1<@[FlexibleNullability] kotlin.Int?> origin=null - : @[FlexibleNullability] kotlin.Int? + $outer: CONSTRUCTOR_CALL 'public constructor () declared in .J1' type=.J1 origin=null + : kotlin.Int : @[FlexibleNullability] kotlin.String? FUN name:testKotlin visibility:public modality:FINAL <> () returnType:.K1.K2 BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.kt.txt b/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.kt.txt index 36e1cc5bbd2..d125539ab45 100644 --- a/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/constructorWithOwnTypeParametersCall.fir.kt.txt @@ -16,10 +16,11 @@ class K1 { } -fun testJava(): J2<@FlexibleNullability Double?, @FlexibleNullability Int?> { - return J1<@FlexibleNullability Int?, @FlexibleNullability String?>().J2<@FlexibleNullability Double?, @FlexibleNullability CharSequence?>() +fun testJava(): J2 { + return J1().J2() } fun testKotlin(): K2 { return K1().K2() } + diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.ir.txt b/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.ir.txt index a63757f9beb..a0724f2867f 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.ir.txt @@ -1,8 +1,8 @@ FILE fqName: fileName:/samConversionToGeneric.kt - FUN name:test1 visibility:public modality:FINAL <> () returnType:.J<@[FlexibleNullability] kotlin.String?> + FUN name:test1 visibility:public modality:FINAL <> () returnType:.J BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test1 (): .J<@[FlexibleNullability] kotlin.String?> declared in ' - TYPE_OP type=.J<@[FlexibleNullability] kotlin.String?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] kotlin.String?> + RETURN type=kotlin.Nothing from='public final fun test1 (): .J declared in ' + TYPE_OP type=.J origin=SAM_CONVERSION typeOperand=.J FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.String?, @[FlexibleNullability] kotlin.String?> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (x:@[FlexibleNullability] kotlin.String?) returnType:@[FlexibleNullability] kotlin.String? VALUE_PARAMETER name:x index:0 type:@[FlexibleNullability] kotlin.String? diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.kt.txt index 2d11ecf271f..b52b2ddb903 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.kt.txt @@ -1,8 +1,8 @@ -fun test1(): J<@FlexibleNullability String?> { +fun test1(): J { return local fun (x: @FlexibleNullability String?): @FlexibleNullability String? { return x } - /*-> J<@FlexibleNullability String?> */ + /*-> J */ } fun test10(fn: Function1) { diff --git a/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.ir.txt b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.ir.txt index ac75c666454..4e57a788a3a 100644 --- a/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.ir.txt +++ b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.ir.txt @@ -1,29 +1,29 @@ FILE fqName: fileName:/javaConstructorWithTypeParameters.kt - FUN name:test1 visibility:public modality:FINAL <> () returnType:.J1<@[FlexibleNullability] kotlin.Int?> + FUN name:test1 visibility:public modality:FINAL <> () returnType:.J1 BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test1 (): .J1<@[FlexibleNullability] kotlin.Int?> declared in ' - CONSTRUCTOR_CALL 'public constructor () declared in .J1' type=.J1<@[FlexibleNullability] kotlin.Int?> origin=null - : @[FlexibleNullability] kotlin.Int? - FUN name:test2 visibility:public modality:FINAL <> () returnType:.J1<@[FlexibleNullability] kotlin.Int?> + RETURN type=kotlin.Nothing from='public final fun test1 (): .J1 declared in ' + CONSTRUCTOR_CALL 'public constructor () declared in .J1' type=.J1 origin=null + : kotlin.Int + FUN name:test2 visibility:public modality:FINAL <> () returnType:.J1 BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test2 (): .J1<@[FlexibleNullability] kotlin.Int?> declared in ' - CONSTRUCTOR_CALL 'public constructor (x1: @[FlexibleNullability] X1 of .J1.?) declared in .J1' type=.J1<@[FlexibleNullability] kotlin.Int?> origin=null - : @[FlexibleNullability] kotlin.Int? + RETURN type=kotlin.Nothing from='public final fun test2 (): .J1 declared in ' + CONSTRUCTOR_CALL 'public constructor (x1: @[FlexibleNullability] X1 of .J1.?) declared in .J1' type=.J1 origin=null + : kotlin.Int : @[FlexibleNullability] kotlin.Int? x1: CONST Int type=kotlin.Int value=1 - FUN name:test3 visibility:public modality:FINAL <> (j1:.J1) returnType:.J1.J2<@[FlexibleNullability] kotlin.Int?, kotlin.Any> + FUN name:test3 visibility:public modality:FINAL <> (j1:.J1) returnType:.J1.J2 VALUE_PARAMETER name:j1 index:0 type:.J1 BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test3 (j1: .J1): .J1.J2<@[FlexibleNullability] kotlin.Int?, kotlin.Any> declared in ' - CONSTRUCTOR_CALL 'public constructor () declared in .J1.J2' type=.J1.J2<@[FlexibleNullability] kotlin.Int?, kotlin.Any> origin=null - : @[FlexibleNullability] kotlin.Int? + RETURN type=kotlin.Nothing from='public final fun test3 (j1: .J1): .J1.J2 declared in ' + CONSTRUCTOR_CALL 'public constructor () declared in .J1.J2' type=.J1.J2 origin=null + : kotlin.Int $outer: GET_VAR 'j1: .J1 declared in .test3' type=.J1 origin=null - FUN name:test4 visibility:public modality:FINAL <> (j1:.J1) returnType:.J1.J2<@[FlexibleNullability] kotlin.Int?, kotlin.Any> + FUN name:test4 visibility:public modality:FINAL <> (j1:.J1) returnType:.J1.J2 VALUE_PARAMETER name:j1 index:0 type:.J1 BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test4 (j1: .J1): .J1.J2<@[FlexibleNullability] kotlin.Int?, kotlin.Any> declared in ' - CONSTRUCTOR_CALL 'public constructor (x2: @[FlexibleNullability] X2 of .J1.J2.?) declared in .J1.J2' type=.J1.J2<@[FlexibleNullability] kotlin.Int?, kotlin.Any> origin=null - : @[FlexibleNullability] kotlin.Int? + RETURN type=kotlin.Nothing from='public final fun test4 (j1: .J1): .J1.J2 declared in ' + CONSTRUCTOR_CALL 'public constructor (x2: @[FlexibleNullability] X2 of .J1.J2.?) declared in .J1.J2' type=.J1.J2 origin=null + : kotlin.Int : @[FlexibleNullability] kotlin.Int? $outer: GET_VAR 'j1: .J1 declared in .test4' type=.J1 origin=null x2: CONST Int type=kotlin.Int value=1 diff --git a/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.kt.txt b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.kt.txt index d932d1df450..754811e5678 100644 --- a/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.kt.txt +++ b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.kt.txt @@ -1,15 +1,15 @@ -fun test1(): J1<@FlexibleNullability Int?> { - return J1<@FlexibleNullability Int?>() +fun test1(): J1 { + return J1() } -fun test2(): J1<@FlexibleNullability Int?> { - return J1<@FlexibleNullability Int?, @FlexibleNullability Int?>(x1 = 1) +fun test2(): J1 { + return J1(x1 = 1) } -fun test3(j1: J1): J2<@FlexibleNullability Int?, Any> { - return j1.J2<@FlexibleNullability Int?>() +fun test3(j1: J1): J2 { + return j1.J2() } -fun test4(j1: J1): J2<@FlexibleNullability Int?, Any> { - return j1.J2<@FlexibleNullability Int?, @FlexibleNullability Int?>(x2 = 1) +fun test4(j1: J1): J2 { + return j1.J2(x2 = 1) }