From 83824d0ba61e3caf9ef473172907423c47ca2397 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Thu, 20 Feb 2020 03:08:29 +0300 Subject: [PATCH] [NI] Don't stop on a candidate with unstable smartcast error #KT-36847 Fixed --- .../calls/model/KotlinCallDiagnostics.kt | 4 +- .../diagnostics/tests/resolve/kt36264.kt | 2 +- .../tests/smartCasts/elvis/impossible.kt | 4 +- ...lityOfSmartcastsAgainstGenericFunctions.kt | 2 +- .../diagnostics/notLinked/dfa/neg/46.kt | 88 ------------------- .../diagnostics/notLinked/dfa/pos/53.kt | 81 +++++++++++++++++ .../DiagnosticsTestSpecGenerated.java | 5 -- 7 files changed, 86 insertions(+), 100 deletions(-) delete mode 100644 compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/46.kt diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt index da1bbce5da5..01a824982f8 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt @@ -152,9 +152,7 @@ sealed class UnstableSmartCast( targetType: UnwrappedType, isReceiver: Boolean = false, // for reproducing OI behaviour ): UnstableSmartCast { - return if (isReceiver) - UnstableSmartCastResolutionError(argument, targetType) - else UnstableSmartCastDiagnosticError(argument, targetType) + return UnstableSmartCastResolutionError(argument, targetType) } } } diff --git a/compiler/testData/diagnostics/tests/resolve/kt36264.kt b/compiler/testData/diagnostics/tests/resolve/kt36264.kt index 8b3b9f3af38..fe0d372a3c3 100644 --- a/compiler/testData/diagnostics/tests/resolve/kt36264.kt +++ b/compiler/testData/diagnostics/tests/resolve/kt36264.kt @@ -12,7 +12,7 @@ class Cls { fun test(s: String) { if (s.ext is B) - take(s.ext) + take(s.ext) } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvis/impossible.kt b/compiler/testData/diagnostics/tests/smartCasts/elvis/impossible.kt index dec520aab65..8174bd0da67 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/elvis/impossible.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/elvis/impossible.kt @@ -18,7 +18,7 @@ fun foo(list: StringList, arg: Unstable) { list.remove(arg.first) if (arg.first?.isEmpty() ?: false) { // Should be still resolved to extension, without smart cast or smart cast impossible - list.remove(arg.first) + list.remove(arg.first) } } @@ -36,6 +36,6 @@ fun bar(list: BooleanList, arg: UnstableBoolean) { list.remove(arg.first) if (arg.first ?: false) { // Should be still resolved to extension, without smart cast or smart cast impossible - list.remove(arg.first) + list.remove(arg.first) } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/stabilityOfSmartcastsAgainstGenericFunctions.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/stabilityOfSmartcastsAgainstGenericFunctions.kt index d56545ff296..66555836e54 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/inference/stabilityOfSmartcastsAgainstGenericFunctions.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/stabilityOfSmartcastsAgainstGenericFunctions.kt @@ -9,5 +9,5 @@ fun main() { var y: Number? = null y = 2 { y = 1 } - Test.foo(y) + Test.foo(y) } \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/46.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/46.kt deleted file mode 100644 index 10f8361a2ac..00000000000 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/46.kt +++ /dev/null @@ -1,88 +0,0 @@ -// !LANGUAGE: +NewInference -// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER -// SKIP_TXT - -/* - * KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (NEGATIVE) - * - * SECTIONS: dfa - * NUMBER: 46 - * DESCRIPTION: Raw data flow analysis test - * HELPERS: classes, objects, typealiases, functions, enumClasses, interfaces, sealedClasses - */ - -// TESTCASE NUMBER: 1 -fun case_1(x: Int) = "" -fun case_1(x: Int?) = 10 -fun case_1() { - var x: Int? = 10 - var y = { x = null } - if (x != null) { - val z = case_1(x) - z - } -} - -// TESTCASE NUMBER: 2 -val case_2_prop: Int? - get() = 10 -fun case_2(x: Int) = "" -fun case_2(x: Int?) = 10 -fun case_2() { - if (case_2_prop != null) { - val z = case_2(case_2_prop) - z - } -} - -// TESTCASE NUMBER: 3 -class Case4 { - var x: Int? = 10 -} -fun case_3(x: Int) = "" -fun case_3(x: Int?) = 10 -fun case_3(y: Case4) { - if (y.x != null) { - val z = case_3(y.x) - z - } -} - -// TESTCASE NUMBER: 4 -open class Case5 { - open val x: Int? = 10 -} -fun case_4(x: Int) = "" -fun case_4(x: Int?) = 10 -fun case_4(y: Case4) { - if (y.x != null) { - val z = case_4(y.x) - z - } -} - -// TESTCASE NUMBER: 5 -class Case6 { - val x: Int? by lazy { 10 } -} -fun case_5(x: Int) = "" -fun case_5(x: Int?) = 10 -fun case_5(y: Case4) { - if (y.x != null) { - val z = case_5(y.x) - z - } -} - -// TESTCASE NUMBER: 6 -var case_6_prop: Int? - get() = 10 - set(value) {} -fun case_6(x: Int) = "" -fun case_6(x: Int?) = 10 -fun case_6() { - if (case_6_prop != null) { - val z = case_6(case_6_prop) - z - } -} diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/53.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/53.kt index 56601aeb3c1..c156aaee8a6 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/53.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/53.kt @@ -21,3 +21,84 @@ fun case_1() { z } } + +// TESTCASE NUMBER: 2 +fun case_2(x: Int) = "" +fun case_2(x: Int?) = 10 +fun case_2() { + var x: Int? = 10 + var y = { x = null } + if (x != null) { + val z = case_2(x) + z + } +} + +// TESTCASE NUMBER: 3 +val case_3_prop: Int? + get() = 10 + +fun case_3(x: Int) = "" +fun case_3(x: Int?) = 10 +fun case_3() { + if (case_3_prop != null) { + val z = case_3(case_3_prop) + z + } +} + +// TESTCASE NUMBER: 4 +class Case4 { + var x: Int? = 10 +} + +fun case_4(x: Int) = "" +fun case_4(x: Int?) = 10 +fun case_4(y: Case4) { + if (y.x != null) { + val z = case_4(y.x) + z + } +} + +// TESTCASE NUMBER: 5 +open class Case5 { + open val x: Int? = 10 +} + +fun case_5(x: Int) = "" +fun case_5(x: Int?) = 10 +fun case_5(y: Case4) { + if (y.x != null) { + val z = case_5(y.x) + z + } +} + +// TESTCASE NUMBER: 6 +class Case6 { + val x: Int? by lazy { 10 } +} + +fun case_6(x: Int) = "" +fun case_6(x: Int?) = 10 +fun case_6(y: Case4) { + if (y.x != null) { + val z = case_6(y.x) + z + } +} + +// TESTCASE NUMBER: 7 +var case_7_prop: Int? + get() = 10 + set(value) {} + +fun case_7(x: Int) = "" +fun case_7(x: Int?) = 10 +fun case_7() { + if (case_7_prop != null) { + val z = case_7(case_7_prop) + z + } +} diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java index 42534c28f5e..822dd5227b0 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/checkers/DiagnosticsTestSpecGenerated.java @@ -4842,11 +4842,6 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { runTest("compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/45.kt"); } - @TestMetadata("46.kt") - public void test46() throws Exception { - runTest("compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/46.kt"); - } - @TestMetadata("5.kt") public void test5() throws Exception { runTest("compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/5.kt");