From 4059fae1b78bf094c4367a90cdbd50e3efc4b7f1 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 26 Nov 2019 11:22:55 +0300 Subject: [PATCH] [FIR-TEST] Add test with type mismatch on receiver with captured type --- .../problems/receiverWithCapturedType.kt | 36 +++++++++++++++++++ .../problems/receiverWithCapturedType.txt | 34 ++++++++++++++++++ .../fir/FirDiagnosticsTestGenerated.java | 5 +++ 3 files changed, 75 insertions(+) create mode 100644 compiler/fir/resolve/testData/resolve/problems/receiverWithCapturedType.kt create mode 100644 compiler/fir/resolve/testData/resolve/problems/receiverWithCapturedType.txt diff --git a/compiler/fir/resolve/testData/resolve/problems/receiverWithCapturedType.kt b/compiler/fir/resolve/testData/resolve/problems/receiverWithCapturedType.kt new file mode 100644 index 00000000000..80f1a717edc --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/problems/receiverWithCapturedType.kt @@ -0,0 +1,36 @@ +interface ResolvedCall { + var d: D +} + +interface CallableDescriptor + +fun ResolvedCall.getParameterForArgument(): String = "" + +fun ResolvedCall.updateD(d: D): D { + this.d = d + return d +} + +fun test_1_1(resolvedCall: ResolvedCall) { + resolvedCall.getParameterForArgument() // should be ok +} + +fun test_1_2(resolvedCall: ResolvedCall) { + resolvedCall.getParameterForArgument() // should be ok +} + +fun test_1_3(resolvedCall: ResolvedCall) { + resolvedCall.getParameterForArgument() // should be ok +} + +fun test_2_1(resolvedCall: ResolvedCall, d: CallableDescriptor) { + val x = resolvedCall.updateD(d) // should fail +} + +fun test_2_2(resolvedCall: ResolvedCall, d: CallableDescriptor) { + val x = resolvedCall.updateD(d) // should be ok +} + +fun test_2_3(resolvedCall: ResolvedCall, d: CallableDescriptor) { + val x = resolvedCall.updateD(d) // should be ok +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/problems/receiverWithCapturedType.txt b/compiler/fir/resolve/testData/resolve/problems/receiverWithCapturedType.txt new file mode 100644 index 00000000000..0ef43564717 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/problems/receiverWithCapturedType.txt @@ -0,0 +1,34 @@ +FILE: receiverWithCapturedType.kt + public abstract interface ResolvedCall : R|kotlin/Any| { + public abstract var d: R|D| + public get(): R|D| + public set(value: R|D|): R|kotlin/Unit| + + } + public abstract interface CallableDescriptor : R|kotlin/Any| { + } + public final fun R|ResolvedCall|.getParameterForArgument(): R|kotlin/String| { + ^getParameterForArgument String() + } + public final fun R|ResolvedCall|.updateD(d: R|D|): R|D| { + this@R|/updateD|.R|FakeOverride| = R|/d| + ^updateD R|/d| + } + public final fun test_1_1(resolvedCall: R|ResolvedCall|): R|kotlin/Unit| { + R|/resolvedCall|.#() + } + public final fun test_1_2(resolvedCall: R|ResolvedCall|): R|kotlin/Unit| { + R|/resolvedCall|.R|/getParameterForArgument|() + } + public final fun test_1_3(resolvedCall: R|ResolvedCall|): R|kotlin/Unit| { + R|/resolvedCall|.R|/getParameterForArgument|() + } + public final fun test_2_1(resolvedCall: R|ResolvedCall|, d: R|CallableDescriptor|): R|kotlin/Unit| { + lval x: = R|/resolvedCall|.#(R|/d|) + } + public final fun test_2_2(resolvedCall: R|ResolvedCall|, d: R|CallableDescriptor|): R|kotlin/Unit| { + lval x: R|CallableDescriptor| = R|/resolvedCall|.R|/updateD|(R|/d|) + } + public final fun test_2_3(resolvedCall: R|ResolvedCall|, d: R|CallableDescriptor|): R|kotlin/Unit| { + lval x: R|CallableDescriptor| = R|/resolvedCall|.R|/updateD|(R|/d|) + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 2824b1abb03..08379404c2a 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -888,6 +888,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/resolve/problems/propertyFromJavaPlusAssign.kt"); } + @TestMetadata("receiverWithCapturedType.kt") + public void testReceiverWithCapturedType() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/problems/receiverWithCapturedType.kt"); + } + @TestMetadata("syntheticsVsNormalProperties.kt") public void testSyntheticsVsNormalProperties() throws Exception { runTest("compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.kt");