From 661812b25583ef447287d36ec43da8b65ad7cb47 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Tue, 7 Apr 2020 11:12:10 +0300 Subject: [PATCH] NI: add test for KT-37628 --- .../testsWithStdLib/inference/kt37627.fir.kt | 21 +++++++++++++++++++ .../testsWithStdLib/inference/kt37627.kt | 17 ++++++++++++--- .../testsWithStdLib/inference/kt37627.txt | 3 ++- 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/kt37627.fir.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt37627.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt37627.fir.kt new file mode 100644 index 00000000000..e0aac42b51a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt37627.fir.kt @@ -0,0 +1,21 @@ +// FIR_IDENTICAL +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -NAME_SHADOWING -UNUSED_VARIABLE + +fun foo1(x: Int) { + val x = if (true) { // OI: Map?, NI: Nothing?, error + "" to { x } + } else { null } + + x +} + +fun foo2(x: Int) { + val x = if (true) { + mapOf("" to { x }) // `Map` is in type info in IDE + } else { + null + } // Fixed the problem: "type of entire `if` is `Map?` (NI) instead of `Map?` (OI)" + + x +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt37627.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt37627.kt index c9026d6a44e..f74d0c326b4 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/kt37627.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt37627.kt @@ -1,9 +1,20 @@ -// FIR_IDENTICAL // !LANGUAGE: +NewInference -// !DIAGNOSTICS: -NAME_SHADOWING -UNUSED_VARIABLE +// !DIAGNOSTICS: -NAME_SHADOWING -UNUSED_VARIABLE -UNUSED_EXPRESSION -fun foo(x: Int) { +fun foo1(x: Int) { val x = if (true) { // OI: Map?, NI: Nothing?, error "" to { x } } else { null } + + kotlin.Int>?")!>x +} + +fun foo2(x: Int) { + val x = if (true) { + mapOf("" to { x }) // `Map` is in type info in IDE + } else { + null + } // Fixed the problem: "type of entire `if` is `Map?` (NI) instead of `Map?` (OI)" + + kotlin.Int>?")!>x } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt37627.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt37627.txt index 3afacee3aa4..90e8b1a4c84 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/kt37627.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt37627.txt @@ -1,3 +1,4 @@ package -public fun foo(/*0*/ x: kotlin.Int): kotlin.Unit +public fun foo1(/*0*/ x: kotlin.Int): kotlin.Unit +public fun foo2(/*0*/ x: kotlin.Int): kotlin.Unit