From 36ba8bf6a9ff25562877a26470ec9e16e0dcd027 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 6 Feb 2020 14:20:31 +0300 Subject: [PATCH] [FIR] Add test imitating complex smart casts on descriptors --- .../resolve/expresssions/genericDescriptor.kt | 10 ++++++++++ .../resolve/expresssions/genericDescriptor.txt | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.kt b/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.kt index 7557436a99f..764d16a0cd9 100644 --- a/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.kt +++ b/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.kt @@ -6,15 +6,21 @@ public interface Descriptor // FILE: ResolvedCall.java import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public interface ResolvedCall { @NotNull D getResultingDescriptor(); + + @Nullable + D getCandidateDescriptor(); } // FILE: test.kt val Descriptor.name = "123" +fun Descriptor.correct(): Boolean = true +fun Descriptor.foo() {} interface Call { val resultingDescriptor: D @@ -23,6 +29,10 @@ interface Call { fun test(call: Call, resolvedCall: ResolvedCall) { call.resultingDescriptor.name resolvedCall.resultingDescriptor.name + + val resolvedDescriptor = resolvedCall.candidateDescriptor + if (resolvedDescriptor?.correct() != true) return + resolvedDescriptor.foo() } fun otherTest(call: Call<*>, resolvedCall: ResolvedCall<*>) { diff --git a/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.txt b/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.txt index 8906e852aa8..b167bec8965 100644 --- a/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.txt +++ b/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.txt @@ -1,6 +1,11 @@ FILE: test.kt public final val R|Descriptor|.name: R|kotlin/String| = String(123) public get(): R|kotlin/String| + public final fun R|Descriptor|.correct(): R|kotlin/Boolean| { + ^correct Boolean(true) + } + public final fun R|Descriptor|.foo(): R|kotlin/Unit| { + } public abstract interface Call : R|kotlin/Any| { public abstract val resultingDescriptor: R|D| public get(): R|D| @@ -9,6 +14,14 @@ FILE: test.kt public final fun test(call: R|Call|, resolvedCall: R|ResolvedCall|): R|kotlin/Unit| { R|/call|.R|FakeOverride|.R|/name| R|/resolvedCall|.R|/ResolvedCall.resultingDescriptor|.R|/name| + lval resolvedDescriptor: R|D?| = R|/resolvedCall|.R|/ResolvedCall.candidateDescriptor| + when () { + !=(R|/resolvedDescriptor|?.R|/correct|(), Boolean(true)) -> { + ^test Unit + } + } + + R|/resolvedDescriptor|.#() } public final fun otherTest(call: R|Call<*>|, resolvedCall: R|ResolvedCall<*>|): R|kotlin/Unit| { R|/call|.R|FakeOverride|.R|/name|