From ac590fa4c9adfeb84adead48659079921ca412b1 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 18 Nov 2019 16:08:34 +0300 Subject: [PATCH] [FIR] Fix deserializing nullability of type parameters --- .../kotlin/fir/deserialization/FirTypeDeserializer.kt | 2 +- .../fir/resolve/testData/builtIns/kotlin-collections.txt | 7 ++++--- compiler/fir/resolve/testData/builtIns/kotlin.txt | 3 ++- .../loadCompiledKotlin/class/ClassMemberConflict.txt | 4 ++-- .../InheritMethodsDifferentReturnTypesGeneric.txt | 8 ++++---- .../loadCompiledKotlin/fromLoadJava/MethosWithPRefTP.txt | 2 +- .../error/WrongTypeParameterBoundStructure1.txt | 2 +- .../error/WrongTypeParameterBoundStructure2.txt | 2 +- .../kotlinSignature/error/WrongTypeParametersCount.txt | 2 +- .../kotlinSignature/propagation/parameter/Kt3302.txt | 2 +- .../propagation/parameter/OverrideWithErasedParameter.txt | 4 ++-- .../loadCompiledKotlin/fromLoadJava/library/Max.txt | 2 +- .../loadCompiledKotlin/prop/ExtValIntTQInClass.txt | 4 ++-- .../loadCompiledKotlin/prop/ExtVarIntTQInClass.txt | 6 +++--- .../loadCompiledKotlin/prop/ExtVarTQIntInClass.txt | 2 +- .../testData/resolve/stdlib/nullableTypeParameter.kt | 3 +++ .../testData/resolve/stdlib/nullableTypeParameter.txt | 4 ++++ .../testData/resolve/stdlib/typeParameterDerived.txt | 4 ++-- .../kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java | 5 +++++ compiler/testData/ir/irText/stubs/builtinMap.fir.txt | 2 +- 20 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 compiler/fir/resolve/testData/resolve/stdlib/nullableTypeParameter.kt create mode 100644 compiler/fir/resolve/testData/resolve/stdlib/nullableTypeParameter.txt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt index 37c7281deb8..b1eb8985d9c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt @@ -116,7 +116,7 @@ class FirTypeDeserializer( fun simpleType(proto: ProtoBuf.Type): ConeLookupTagBasedType? { val constructor = typeSymbol(proto) ?: return null - if (constructor is ConeTypeParameterLookupTag) return ConeTypeParameterTypeImpl(constructor, isNullable = false) + if (constructor is ConeTypeParameterLookupTag) return ConeTypeParameterTypeImpl(constructor, isNullable = proto.nullable) if (constructor !is ConeClassLikeLookupTag) return null fun ProtoBuf.Type.collectAllArguments(): List = diff --git a/compiler/fir/resolve/testData/builtIns/kotlin-collections.txt b/compiler/fir/resolve/testData/builtIns/kotlin-collections.txt index e3012be285e..c02b5d6372a 100644 --- a/compiler/fir/resolve/testData/builtIns/kotlin-collections.txt +++ b/compiler/fir/resolve/testData/builtIns/kotlin-collections.txt @@ -133,7 +133,7 @@ public abstract interface Map : R|kotlin/Any| { public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| - public abstract operator fun get(key: R|K|): R|V| + public abstract operator fun get(key: R|K|): R|V?| @R|kotlin/SinceKotlin|(version = String(1.1)) @R|kotlin/internal/PlatformDependent|() public open fun getOrDefault(key: R|K|, defaultValue: R|V|): R|V| @@ -234,11 +234,11 @@ public abstract interface MutableListIterator : R|kotlin/collections/ListIter public abstract interface MutableMap : R|kotlin/collections/Map| { public abstract fun clear(): R|kotlin/Unit| - public abstract fun put(key: R|K|, value: R|V|): R|V| + public abstract fun put(key: R|K|, value: R|V|): R|V?| public abstract fun putAll(from: R|kotlin/collections/Map|): R|kotlin/Unit| - public abstract fun remove(key: R|K|): R|V| + public abstract fun remove(key: R|K|): R|V?| @R|kotlin/SinceKotlin|(version = String(1.1)) @R|kotlin/internal/PlatformDependent|() public open fun remove(key: R|K|, value: R|V|): R|kotlin/Boolean| @@ -297,3 +297,4 @@ public abstract class ShortIterator : R|kotlin/collections/Iterator arrayOf(vararg elements: R|kotlin/Array|): R|kotlin/Array| -public final fun arrayOfNulls(size: R|kotlin/Int|): R|kotlin/Array| +public final fun arrayOfNulls(size: R|kotlin/Int|): R|kotlin/Array| public final fun booleanArrayOf(vararg elements: R|kotlin/BooleanArray|): R|kotlin/BooleanArray| @@ -1306,3 +1306,4 @@ public final object Unit : R|kotlin/Any| { public constructor(): R|kotlin/UnsafeVariance| } + diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/class/ClassMemberConflict.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/class/ClassMemberConflict.txt index 7157ad4fc12..f8787ee4870 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/class/ClassMemberConflict.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/class/ClassMemberConflict.txt @@ -15,8 +15,8 @@ public final class ConstructorTypeParamClassObjectConflict : R|kotlin/Any| } public final class ConstructorTypeParamClassObjectTypeConflict : R|kotlin/Any| { - public final val some: R|test| - public get(): R|test| + public final val some: R|test?| + public get(): R|test?| public constructor(): R|test/ConstructorTypeParamClassObjectTypeConflict| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/InheritMethodsDifferentReturnTypesGeneric.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/InheritMethodsDifferentReturnTypesGeneric.txt index ee6ba40e2c2..dbedd16c582 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/InheritMethodsDifferentReturnTypesGeneric.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/InheritMethodsDifferentReturnTypesGeneric.txt @@ -5,16 +5,16 @@ public final class InheritMethodsDifferentReturnTypesGeneric : R|kotlin/Any| { } public abstract interface Super1 : R|kotlin/Any| { - public abstract fun bar(): R|B| + public abstract fun bar(): R|B?| - public abstract fun foo(): R|F| + public abstract fun foo(): R|F?| } public abstract interface Super2 : R|kotlin/Any| { - public abstract fun bar(): R|BB| + public abstract fun bar(): R|BB?| - public abstract fun foo(): R|FF| + public abstract fun foo(): R|FF?| } diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/MethosWithPRefTP.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/MethosWithPRefTP.txt index 231c35ce24f..a7d6916c9b6 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/MethosWithPRefTP.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/MethosWithPRefTP.txt @@ -1,5 +1,5 @@ public final class MethosWithPRefTP : R|kotlin/Any| { - public final fun

f(p0: R|P|): R|kotlin/Unit| + public final fun

f(p0: R|P?|): R|kotlin/Unit| public constructor(): R|test/MethosWithPRefTP| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.txt index 2b838fb2961..ea363f95548 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.txt @@ -1,5 +1,5 @@ public open class WrongTypeParameterBoundStructure1 : R|kotlin/Any| { - public open fun ?|> foo(p0: R|A|, p1: R|kotlin/collections/List?|): R|kotlin/Unit| + public open fun ?|> foo(p0: R|A?|, p1: R|kotlin/collections/List?|): R|kotlin/Unit| public constructor(): R|test/WrongTypeParameterBoundStructure1| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.txt index f0b1b1ca441..91aea1827fe 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.txt @@ -1,5 +1,5 @@ public open class WrongTypeParameterBoundStructure2 : R|kotlin/Any| { - public open fun ?|> foo(p0: R|A|, p1: R|kotlin/collections/List?|): R|kotlin/Unit| + public open fun ?|> foo(p0: R|A?|, p1: R|kotlin/collections/List?|): R|kotlin/Unit| public constructor(): R|test/WrongTypeParameterBoundStructure2| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/error/WrongTypeParametersCount.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/error/WrongTypeParametersCount.txt index 3b11ae96156..9264c0f69ba 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/error/WrongTypeParametersCount.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/error/WrongTypeParametersCount.txt @@ -1,5 +1,5 @@ public open class WrongTypeParametersCount : R|kotlin/Any| { - public open fun foo(p0: R|A|, p1: R|kotlin/collections/List?|): R|kotlin/Unit| + public open fun foo(p0: R|A?|, p1: R|kotlin/collections/List?|): R|kotlin/Unit| public constructor(): R|test/WrongTypeParametersCount| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/propagation/parameter/Kt3302.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/propagation/parameter/Kt3302.txt index 61a64bd5ce3..e7a0f662ea3 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/propagation/parameter/Kt3302.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/propagation/parameter/Kt3302.txt @@ -14,7 +14,7 @@ public abstract interface Kt3302 : R|kotlin/Any| { public abstract interface LinkedHashMap : R|kotlin/Any| { public abstract fun dummy(): R|kotlin/Unit| - public abstract fun put(key: R|K|, value: R|V|): R|V| + public abstract fun put(key: R|K|, value: R|V|): R|V?| } diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/propagation/parameter/OverrideWithErasedParameter.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/propagation/parameter/OverrideWithErasedParameter.txt index d840a18ceb3..94107157eea 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/propagation/parameter/OverrideWithErasedParameter.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/kotlinSignature/propagation/parameter/OverrideWithErasedParameter.txt @@ -1,13 +1,13 @@ public abstract interface OverrideWithErasedParameter : R|kotlin/Any| { public abstract interface Sub : R|test/OverrideWithErasedParameter.Super| { - public abstract fun foo(p0: R|T|): R|kotlin/Unit| + public abstract fun foo(p0: R|T?|): R|kotlin/Unit| } public abstract interface Super : R|kotlin/Any| { public abstract fun dummy(): R|kotlin/Unit| - public abstract fun foo(p0: R|T|): R|kotlin/Unit| + public abstract fun foo(p0: R|T?|): R|kotlin/Unit| } diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/library/Max.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/library/Max.txt index c640981adad..94d8db00a70 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/library/Max.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/fromLoadJava/library/Max.txt @@ -1,5 +1,5 @@ public open class Max : R|kotlin/Any| { - public open fun ?|> max(p0: R|kotlin/collections/Collection?|): R|T| + public open fun ?|> max(p0: R|kotlin/collections/Collection?|): R|T?| public constructor(): R|test/Max| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/prop/ExtValIntTQInClass.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/prop/ExtValIntTQInClass.txt index 7998749f48d..31ef57469d9 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/prop/ExtValIntTQInClass.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/prop/ExtValIntTQInClass.txt @@ -1,6 +1,6 @@ public final class ExtValInClass

: R|kotlin/Any| { - public final val R|kotlin/Int|.asas: R|P| - public get(): R|P| + public final val R|kotlin/Int|.asas: R|P?| + public get(): R|P?| public constructor

(): R|test/ExtValInClass

| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/prop/ExtVarIntTQInClass.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/prop/ExtVarIntTQInClass.txt index 2307e36a632..8062ac3845a 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/prop/ExtVarIntTQInClass.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/prop/ExtVarIntTQInClass.txt @@ -1,7 +1,7 @@ public final class ExtValInClass

: R|kotlin/Any| { - public final var R|kotlin/Int|.asas: R|P| - public get(): R|P| - public set(value: R|P|): R|kotlin/Unit| + public final var R|kotlin/Int|.asas: R|P?| + public get(): R|P?| + public set(value: R|P?|): R|kotlin/Unit| public constructor

(): R|test/ExtValInClass

| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/prop/ExtVarTQIntInClass.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/prop/ExtVarTQIntInClass.txt index 1f4a4e58946..bfc9a67dae0 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/prop/ExtVarTQIntInClass.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/prop/ExtVarTQIntInClass.txt @@ -1,5 +1,5 @@ public final class ExtValPIntInClass

: R|kotlin/Any| { - public final var R|P|.asas: R|kotlin/Int| + public final var R|P?|.asas: R|kotlin/Int| public get(): R|kotlin/Int| public set(value: R|kotlin/Int|): R|kotlin/Unit| diff --git a/compiler/fir/resolve/testData/resolve/stdlib/nullableTypeParameter.kt b/compiler/fir/resolve/testData/resolve/stdlib/nullableTypeParameter.kt new file mode 100644 index 00000000000..77e5ad0f268 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/nullableTypeParameter.kt @@ -0,0 +1,3 @@ +fun test(set: Set) { + val filtered = set.filterNotNull() +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/stdlib/nullableTypeParameter.txt b/compiler/fir/resolve/testData/resolve/stdlib/nullableTypeParameter.txt new file mode 100644 index 00000000000..ace6edee0a9 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/nullableTypeParameter.txt @@ -0,0 +1,4 @@ +FILE: nullableTypeParameter.kt + public final fun test(set: R|kotlin/collections/Set|): R|kotlin/Unit| { + lval filtered: R|kotlin/collections/List| = R|/set|.R|kotlin/collections/filterNotNull|() + } diff --git a/compiler/fir/resolve/testData/resolve/stdlib/typeParameterDerived.txt b/compiler/fir/resolve/testData/resolve/stdlib/typeParameterDerived.txt index 79e35c54b58..f7e5755cf01 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/typeParameterDerived.txt +++ b/compiler/fir/resolve/testData/resolve/stdlib/typeParameterDerived.txt @@ -1,10 +1,10 @@ FILE: typeParameterDerived.kt public final inline fun R|kotlin/collections/MutableMap|.getOrPut(key: R|K|, defaultValue: R|(K) -> VA|, postCompute: R|(VA) -> kotlin/Unit|): R|V| { - lval value: R|V| = this@R|kotlin/collections/Map|.R|FakeOverride|(R|/key|) + lval value: R|V?| = this@R|kotlin/collections/Map|.R|FakeOverride|(R|/key|) ^getOrPut when () { ==(R|/value|, Null(null)) -> { lval answer: R|VA| = R|/defaultValue|.R|FakeOverride|(R|/key|) - this@R|kotlin/collections/MutableMap|.R|FakeOverride|(R|/key|, R|/answer|) + this@R|kotlin/collections/MutableMap|.R|FakeOverride|(R|/key|, R|/answer|) R|/postCompute|.R|FakeOverride|(R|/answer|) R|/answer| } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java index 3bb1e51ae39..299e57f9d50 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java @@ -118,6 +118,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic runTest("compiler/fir/resolve/testData/resolve/stdlib/multipleImplicitReceivers.kt"); } + @TestMetadata("nullableTypeParameter.kt") + public void testNullableTypeParameter() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/stdlib/nullableTypeParameter.kt"); + } + @TestMetadata("problems.kt") public void testProblems() throws Exception { runTest("compiler/fir/resolve/testData/resolve/stdlib/problems.kt"); diff --git a/compiler/testData/ir/irText/stubs/builtinMap.fir.txt b/compiler/testData/ir/irText/stubs/builtinMap.fir.txt index fa0465a7f06..c050aff1f9f 100644 --- a/compiler/testData/ir/irText/stubs/builtinMap.fir.txt +++ b/compiler/testData/ir/irText/stubs/builtinMap.fir.txt @@ -22,7 +22,7 @@ FILE fqName: fileName:/builtinMap.kt block: FUN_EXPR type=kotlin.Function1.plus, V1 of .plus>, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - CALL 'public open fun put (p0: K1 of .plus, p1: V1 of .plus): V1 of .plus declared in java.util.HashMap' type=V1 of .plus origin=null + CALL 'public open fun put (p0: K1 of .plus, p1: V1 of .plus): V1 of .plus? declared in java.util.HashMap' type=V1 of .plus? origin=null $this: GET_VAR ': java.util.HashMap declared in java.util.HashMap' type=java.util.HashMap<*, *> origin=null p0: CALL 'public final fun (): K1 of .plus declared in kotlin.Pair' type=K1 of .plus origin=null $this: GET_VAR 'pair: kotlin.Pair.plus, V1 of .plus> declared in .plus' type=kotlin.Pair.plus, V1 of .plus> origin=null