From 47cf7373af29faa10b0be46a56bee070ebc6914c Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 23 Oct 2019 09:31:59 +0300 Subject: [PATCH] Add extra tests for FIR J/K type mapping --- .../testData/diagnostics/j+k/MyException.kt | 24 ++++++++++++++- .../testData/diagnostics/j+k/MyException.txt | 16 ++++++++-- .../testData/diagnostics/j+k/MyIterable.kt | 5 ++++ .../testData/diagnostics/j+k/MyIterable.txt | 4 +++ .../resolve/testData/diagnostics/j+k/MyMap.kt | 26 ++++++++++++++++ .../testData/diagnostics/j+k/MyMap.txt | 30 +++++++++++++++++++ 6 files changed, 102 insertions(+), 3 deletions(-) diff --git a/compiler/fir/resolve/testData/diagnostics/j+k/MyException.kt b/compiler/fir/resolve/testData/diagnostics/j+k/MyException.kt index f44ba543a30..7a3c32ff4a0 100644 --- a/compiler/fir/resolve/testData/diagnostics/j+k/MyException.kt +++ b/compiler/fir/resolve/testData/diagnostics/j+k/MyException.kt @@ -1,6 +1,28 @@ // FULL_JDK +// FILE: YourException.java +class YourException extends Exception { + +} + +// FILE: test.kt +import java.io.PrintStream + class MyException : Exception() -fun test(e: MyException) { +fun test(e: MyException, stream: PrintStream) { e.printStackTrace() // Cannot be resolved with early J2K mapping due deriving of kotlin.Throwable instead of java.lang.Throwable + e.printStackTrace(stream) + val result = e.getLocalizedMessage() +} + +fun test(e: YourException, stream: PrintStream) { + e.printStackTrace() + e.printStackTrace(stream) + val result = e.getLocalizedMessage() +} + +fun test(e: Exception, stream: PrintStream) { + e.printStackTrace() + e.printStackTrace(stream) + val result = e.getLocalizedMessage() } \ No newline at end of file diff --git a/compiler/fir/resolve/testData/diagnostics/j+k/MyException.txt b/compiler/fir/resolve/testData/diagnostics/j+k/MyException.txt index acfde2191b0..dad4eeb6c3d 100644 --- a/compiler/fir/resolve/testData/diagnostics/j+k/MyException.txt +++ b/compiler/fir/resolve/testData/diagnostics/j+k/MyException.txt @@ -1,10 +1,22 @@ -FILE: MyException.kt +FILE: test.kt public final class MyException : R|kotlin/Exception| { public constructor(): R|MyException| { super() } } - public final fun test(e: R|MyException|): R|kotlin/Unit| { + public final fun test(e: R|MyException|, stream: R|java/io/PrintStream|): R|kotlin/Unit| { R|/e|.R|kotlin/printStackTrace|() + R|/e|.R|kotlin/printStackTrace|(R|/stream|) + lval result: = R|/e|.#() + } + public final fun test(e: R|YourException|, stream: R|java/io/PrintStream|): R|kotlin/Unit| { + R|/e|.R|kotlin/printStackTrace|() + R|/e|.R|kotlin/printStackTrace|(R|/stream|) + lval result: = R|/e|.#() + } + public final fun test(e: R|kotlin/Exception|, stream: R|java/io/PrintStream|): R|kotlin/Unit| { + R|/e|.R|kotlin/printStackTrace|() + R|/e|.R|kotlin/printStackTrace|(R|/stream|) + lval result: = R|/e|.#() } diff --git a/compiler/fir/resolve/testData/diagnostics/j+k/MyIterable.kt b/compiler/fir/resolve/testData/diagnostics/j+k/MyIterable.kt index 8e1a1ebb29f..b41a527a260 100644 --- a/compiler/fir/resolve/testData/diagnostics/j+k/MyIterable.kt +++ b/compiler/fir/resolve/testData/diagnostics/j+k/MyIterable.kt @@ -9,3 +9,8 @@ interface UseIterable : MyIterable { val split = spliterator() } } + +fun test(some: Iterable) { + val it = some.iterator() + val split = some.spliterator() +} diff --git a/compiler/fir/resolve/testData/diagnostics/j+k/MyIterable.txt b/compiler/fir/resolve/testData/diagnostics/j+k/MyIterable.txt index e12de89aeb2..b10f1123687 100644 --- a/compiler/fir/resolve/testData/diagnostics/j+k/MyIterable.txt +++ b/compiler/fir/resolve/testData/diagnostics/j+k/MyIterable.txt @@ -6,3 +6,7 @@ FILE: test.kt } } + public final fun test(some: R|kotlin/collections/Iterable|): R|kotlin/Unit| { + lval it: R|kotlin/collections/Iterator| = R|/some|.R|FakeOverride|>|() + lval split: = R|/some|.#() + } diff --git a/compiler/fir/resolve/testData/diagnostics/j+k/MyMap.kt b/compiler/fir/resolve/testData/diagnostics/j+k/MyMap.kt index 865504946b4..e3a1282f9da 100644 --- a/compiler/fir/resolve/testData/diagnostics/j+k/MyMap.kt +++ b/compiler/fir/resolve/testData/diagnostics/j+k/MyMap.kt @@ -6,4 +6,30 @@ public abstract class MyMap implements java.util.Map {} // FILE: test.kt fun test(map: MyMap) { val result = map.getOrPut("key") { "value" } // Cannot be resolved without early J2K mapping + // In contrast, should be taken from JDK + val otherResult = map.getOrDefault("key", "value") + val anotherResult = map.replace("key", "value") + // Java forEach + map.forEach { key, value -> + println("$key: $value") + } + // Kotlin forEach + map.forEach { (key, value) -> + println("$key: $value") + } +} + +fun test(map: MutableMap) { + val result = map.getOrPut("key") { "value" } // Cannot be resolved without early J2K mapping + // In contrast, should be taken from JDK + val otherResult = map.getOrDefault("key", "value") + val anotherResult = map.replace("key", "value") + // Java forEach + map.forEach { key, value -> + println("$key: $value") + } + // Kotlin forEach + map.forEach { (key, value) -> + println("$key: $value") + } } \ No newline at end of file diff --git a/compiler/fir/resolve/testData/diagnostics/j+k/MyMap.txt b/compiler/fir/resolve/testData/diagnostics/j+k/MyMap.txt index eac9909fa35..199ffd120b4 100644 --- a/compiler/fir/resolve/testData/diagnostics/j+k/MyMap.txt +++ b/compiler/fir/resolve/testData/diagnostics/j+k/MyMap.txt @@ -4,4 +4,34 @@ FILE: test.kt String(value) } ) + lval otherResult: R|kotlin/String| = R|/map|.R|FakeOverride|(String(key), String(value)) + lval anotherResult: = R|/map|.#(String(key), String(value)) + R|/map|.R|kotlin/collections/forEach|( = forEach@fun (key: R|kotlin/collections/Map.Entry|, value: R|kotlin/Any?|): R|kotlin/Unit| { + R|kotlin/io/println|((R|/key|, String(: ), R|/value|)) + } + ) + R|/map|.R|kotlin/collections/forEach|( = forEach@fun (: R|kotlin/collections/Map.Entry|): R|kotlin/Unit| { + lval key: R|kotlin/String| = R|/|.R|kotlin/collections/component1|() + lval value: R|kotlin/String| = R|/|.R|kotlin/collections/component2|() + R|kotlin/io/println|((R|/key|, String(: ), R|/value|)) + } + ) + } + public final fun test(map: R|kotlin/collections/MutableMap|): R|kotlin/Unit| { + lval result: R|kotlin/String| = R|/map|.R|kotlin/collections/getOrPut|(String(key), = getOrPut@fun (): R|kotlin/String| { + String(value) + } + ) + lval otherResult: R|kotlin/String| = R|/map|.R|FakeOverride|(String(key), String(value)) + lval anotherResult: = R|/map|.#(String(key), String(value)) + R|/map|.R|kotlin/collections/forEach|( = forEach@fun (key: R|kotlin/collections/Map.Entry|, value: R|kotlin/Any?|): R|kotlin/Unit| { + R|kotlin/io/println|((R|/key|, String(: ), R|/value|)) + } + ) + R|/map|.R|kotlin/collections/forEach|( = forEach@fun (: R|kotlin/collections/Map.Entry|): R|kotlin/Unit| { + lval key: R|kotlin/String| = R|/|.R|kotlin/collections/component1|() + lval value: R|kotlin/String| = R|/|.R|kotlin/collections/component2|() + R|kotlin/io/println|((R|/key|, String(: ), R|/value|)) + } + ) }