diff --git a/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSam.txt b/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSam.txt index 6d3cc04eef8..303583bb3ba 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSam.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSam.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|ft!|): R|kotlin/String| { ^ R|/x|.R|kotlin/Int.toInt|().R|kotlin/Any.toString|() } ) @@ -8,7 +8,7 @@ FILE: main.kt ^ R|/x|.R|kotlin/Any.toString|() } ) - R|/MyFunction|!|>( = MyFunction@fun (x: R|kotlin/Any?|): R|kotlin/String| { + R|/MyFunction|!|>( = MyFunction@fun (x: R|ft?|): R|kotlin/String| { ^ String() } ) diff --git a/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSamInferenceFromExpectType.txt b/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSamInferenceFromExpectType.txt index e468bdcc691..edea02d289b 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSamInferenceFromExpectType.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConstructors/genericSamInferenceFromExpectType.txt @@ -6,11 +6,11 @@ FILE: main.kt public final fun foo3(f: R|MyFunction|, x: R|X|): R|kotlin/Unit| { } public final fun main(): R|kotlin/Unit| { - R|/foo1|(R|/MyFunction|( = MyFunction@fun (x: R|kotlin/Int|): R|kotlin/String| { + R|/foo1|(R|/MyFunction|( = MyFunction@fun (x: R|ft!|): R|kotlin/String| { ^ R|/x|.R|kotlin/Int.toInt|().R|kotlin/Any.toString|() } )) - R|/foo2|(R|/MyFunction|!|>( = MyFunction@fun (x: R|kotlin/Number|): R|kotlin/String| { + R|/foo2|(R|/MyFunction|!|>( = MyFunction@fun (x: R|ft!|): R|kotlin/String| { ^ R|/x|.R|kotlin/Number.toInt|().R|kotlin/Any.toString|() } )) @@ -18,7 +18,7 @@ FILE: main.kt ^ R|/x|.R|kotlin/Any.toString|() } )) - R|/foo3|!|>(R|/MyFunction|!|>( = MyFunction@fun (x: R|kotlin/Int|): R|kotlin/String| { + R|/foo3|!|>(R|/MyFunction|!|>( = MyFunction@fun (x: R|ft!|): R|kotlin/String| { ^ R|/x|.R|kotlin/Int.plus|(Int(1)).R|kotlin/Any.toString|() } ), Int(1)) diff --git a/compiler/fir/analysis-tests/testData/resolve/samConversions/genericSam.txt b/compiler/fir/analysis-tests/testData/resolve/samConversions/genericSam.txt index 90579edbf31..39caae7fff8 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConversions/genericSam.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConversions/genericSam.txt @@ -12,7 +12,7 @@ FILE: main.kt ^ R|/x|.R|kotlin/Any.toString|() } ) - Q|JavaUsage|.R|/JavaUsage.foo3|!|>(foo3@fun (x: R|kotlin/Int|): R|kotlin/String| { + Q|JavaUsage|.R|/JavaUsage.foo3|!|>(foo3@fun (x: R|ft!|): R|kotlin/String| { ^ R|/x|.R|kotlin/Int.plus|(Int(1)).R|kotlin/Any.toString|() } , Int(1)) diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/flexibleTypeInSystem.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/flexibleTypeInSystem.kt new file mode 100644 index 00000000000..248d78fa271 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/flexibleTypeInSystem.kt @@ -0,0 +1,17 @@ +// ISSUE: KT-37623 +// FULL_JDK +// FILE: JavaEnum.java + +public enum JavaEnum { + A; +} + +// FILE: main.kt + +import java.util.EnumMap + +val enumMap = EnumMap( + mapOf( + JavaEnum.A to "A" + ) +) \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/flexibleTypeInSystem.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/flexibleTypeInSystem.txt new file mode 100644 index 00000000000..2e77b232377 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/flexibleTypeInSystem.txt @@ -0,0 +1,3 @@ +FILE: main.kt + public final val enumMap: R|java/util/EnumMap!, ft!>| = R|java/util/EnumMap.EnumMap|!|, R|ft!|>(R|kotlin/collections/mapOf|!|, R|kotlin/String|>(Q|JavaEnum|.R|/JavaEnum.A|.R|kotlin/to|(String(A)))) + public get(): R|java/util/EnumMap!, ft!>| diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/FunctionTypeInJava.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/FunctionTypeInJava.txt index 87fa9c4604a..b0e5c16b064 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/FunctionTypeInJava.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/FunctionTypeInJava.txt @@ -17,7 +17,7 @@ FILE: main.kt } Q|JavaClass|.R|/JavaClass.foo2|(R|/y|) - Q|JavaClass|.R|/JavaClass.foo3|(foo3@fun (it: R|kotlin/Int|): R|ft!| { + Q|JavaClass|.R|/JavaClass.foo3|(foo3@fun (it: R|ft!|): R|ft!| { ^ R|/it|.R|kotlin/Int.plus|(Int(4)).R|kotlin/Any.toString|() } , Int(5)) diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/javaLangComparator.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/javaLangComparator.txt index ac8bda89f68..71c47b33f06 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/javaLangComparator.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/javaLangComparator.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|ft!|, y: R|ft!|): R|kotlin/Int| { ^ Int(1) } ) diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/kotlinComparatorAlias.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/kotlinComparatorAlias.txt index 359c24ba395..6fd1c9eda35 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/kotlinComparatorAlias.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/kotlinComparatorAlias.txt @@ -1,6 +1,6 @@ FILE: kotlinComparatorAlias.kt public final fun test_1(): R|kotlin/Unit| { - lval comp: R|java/util/Comparator| = R|java/util/Comparator|( = Comparator@fun (x: R|kotlin/Int|, y: R|kotlin/Int|): R|kotlin/Int| { + lval comp: R|java/util/Comparator| = R|java/util/Comparator|( = Comparator@fun (x: R|ft!|, y: R|ft!|): R|kotlin/Int| { ^ Int(1) } ) diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java index 80f6bab254b..186c2897041 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java @@ -556,6 +556,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic public void testComplexConstraintSystem() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/complexConstraintSystem.kt"); } + + @TestMetadata("flexibleTypeInSystem.kt") + public void testFlexibleTypeInSystem() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/flexibleTypeInSystem.kt"); + } } @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k") diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt index 91c24e9bb6b..f92a94e90e1 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt @@ -107,7 +107,7 @@ open class ConeFlexibleType(val lowerBound: ConeKotlinType, val upperBound: Cone } override val typeArguments: Array - get() = emptyArray() + get() = lowerBound.typeArguments override val nullability: ConeNullability get() = lowerBound.nullability.takeIf { it == upperBound.nullability } ?: ConeNullability.UNKNOWN diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index 1dfad011c54..b15d4fa777e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -288,6 +288,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo return object : AbstractConeSubstitutor(), TypeSubstitutorMarker { override fun substituteType(type: ConeKotlinType): ConeKotlinType? { + if (type !is ConeLookupTagBasedType) return null val new = map[type.typeConstructor()] ?: return null return (new as ConeKotlinType).approximateIntegerLiteralType().updateNullabilityIfNeeded(type) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.fir.kt index 64b9eb0da5b..42d31a64950 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.fir.kt @@ -5,4 +5,4 @@ typealias ComparatorStrT = ComparatorT val test1 = RunnableT { } val test2 = ComparatorT { s1, s2 -> s1.compareTo(s2) } -val test3 = ComparatorStrT { s1, s2 -> s1.compareTo(s2) } +val test3 = ComparatorStrT { s1, s2 -> s1.compareTo(s2) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.fir.kt index b353439a94d..63c2639f042 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.fir.kt @@ -23,5 +23,5 @@ typealias C2 = JHost.Consumer2 val test1 = R { } val test2 = C { s -> println(s.length) } val test3 = CStr { s -> println(s.length) } -val test4 = CStrList { ss -> for (s in ss) { println(s.length) } } +val test4 = CStrList { ss -> for (s in ss) { println(s.length) } } val test5 = C2 { a, b -> val x: Int = a + b; println(x)} diff --git a/compiler/testData/ir/irText/expressions/sam/samConstructors.fir.txt b/compiler/testData/ir/irText/expressions/sam/samConstructors.fir.txt index 642f9c5110a..5fa6c8181bf 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConstructors.fir.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConstructors.fir.txt @@ -25,12 +25,12 @@ FILE fqName: fileName:/samConstructors.kt RETURN type=kotlin.Nothing from='public final fun test4 (): java.util.Comparator declared in ' CALL 'public final fun Comparator (block: kotlin.Function2): java.util.Comparator declared in java.util' type=java.util.Comparator origin=null : kotlin.Int - block: FUN_EXPR type=kotlin.Function2 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (a:kotlin.Int, b:kotlin.Int) returnType:kotlin.Int - VALUE_PARAMETER name:a index:0 type:kotlin.Int - VALUE_PARAMETER name:b index:1 type:kotlin.Int + block: FUN_EXPR type=kotlin.Function2 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (a:kotlin.Int?, b:kotlin.Int?) returnType:kotlin.Int + VALUE_PARAMETER name:a index:0 type:kotlin.Int? + VALUE_PARAMETER name:b index:1 type:kotlin.Int? BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (a: kotlin.Int, b: kotlin.Int): kotlin.Int declared in .test4' + RETURN type=kotlin.Nothing from='local final fun (a: kotlin.Int?, b: kotlin.Int?): kotlin.Int declared in .test4' CALL 'public final fun minus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=MINUS - $this: GET_VAR 'a: kotlin.Int declared in .test4.' type=kotlin.Int origin=null - other: GET_VAR 'b: kotlin.Int declared in .test4.' type=kotlin.Int origin=null + $this: GET_VAR 'a: kotlin.Int? declared in .test4.' type=kotlin.Int? origin=null + other: GET_VAR 'b: kotlin.Int? declared in .test4.' type=kotlin.Int? origin=null diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.txt b/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.txt index 38d505d14cb..aa03b1c864d 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.txt @@ -4,12 +4,12 @@ FILE fqName: fileName:/samConversionToGeneric.kt RETURN type=kotlin.Nothing from='public final fun test1 (): .J declared in ' CALL 'public final fun J (block: kotlin.Function1.J?, T of .J?>): .J.J> declared in ' type=.J origin=null : kotlin.String - block: FUN_EXPR type=kotlin.Function1 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (x:kotlin.String) returnType:kotlin.String - VALUE_PARAMETER name:x index:0 type:kotlin.String + block: FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (x:kotlin.String?) returnType:kotlin.String? + VALUE_PARAMETER name:x index:0 type:kotlin.String? BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (x: kotlin.String): kotlin.String declared in .test1' - GET_VAR 'x: kotlin.String declared in .test1.' type=kotlin.String origin=null + RETURN type=kotlin.Nothing from='local final fun (x: kotlin.String?): kotlin.String? declared in .test1' + GET_VAR 'x: kotlin.String? declared in .test1.' type=kotlin.String? origin=null FUN name:test2 visibility:public modality:FINAL <> () returnType:.J BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test2 (): .J declared in '