From fedadfb8db49753617d73225b14ba70b96a76334 Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Fri, 13 Oct 2023 16:00:49 +0300 Subject: [PATCH] [FIR] Show ARGUMENTS_MAPPING_ERROR diagnostics along with INAPPLICABLE K1 reports `ARGUMENT_TYPE_MISMATCH` and `TOO_MANY_ARGUMENTS` together, and one way to do it in K2 is to say that their kinds of inapplicability difference is not relevant to the user. Note that K1 doesn't do such filtering, so this change "makes K2 closer to K1", but still different. ^KT-62541 Fixed fixup! [FIR] Show ARGUMENTS_MAPPING_ERROR diagnostics along with INAPPLICABLE --- .../resolve/arguments/argumentsOfAnnotations.kt | 2 +- .../testData/resolve/arguments/default.kt | 2 +- .../testData/resolve/arguments/lambda.kt | 8 ++++---- .../testData/resolve/arguments/vararg.kt | 2 +- .../diagnostics/coneDiagnosticToFirDiagnostic.kt | 10 +++++++++- compiler/testData/cli/jvm/wrongAbiVersion.out | 3 +++ .../tests/argumentTypeMismatchVsTooManyArgs.fir.kt | 2 +- .../tests/checkArguments/kt1897_diagnostic_part.fir.kt | 10 +++++----- .../diagnostics/tests/delegation/kt44843.fir.kt | 4 ++-- .../diagnostics/tests/extensions/variableInvoke.fir.kt | 2 +- .../namedArgumentsAndDefaultValues.fir.kt | 2 +- .../diagnostics/tests/regressions/kt10633.fir.kt | 2 +- .../resolve/incompleteConstructorInvocation.fir.kt | 4 ++-- .../errors/wrongReceiverForInvokeOnExpression.fir.kt | 2 +- .../functionExpectedWhenSeveralInvokesExist.fir.kt | 2 +- .../diagnostics/tests/resolve/newLineLambda.fir.kt | 4 ++-- .../prohibitPositionedArgument/tooManyArgs.fir.kt | 2 +- 17 files changed, 37 insertions(+), 26 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolve/arguments/argumentsOfAnnotations.kt b/compiler/fir/analysis-tests/testData/resolve/arguments/argumentsOfAnnotations.kt index 011caf4c598..00edbbbefcc 100644 --- a/compiler/fir/analysis-tests/testData/resolve/arguments/argumentsOfAnnotations.kt +++ b/compiler/fir/analysis-tests/testData/resolve/arguments/argumentsOfAnnotations.kt @@ -5,5 +5,5 @@ class A annotation class AnnVarargs(val x: Int, vararg val y: String, val z: Int) -@AnnVarargs(1, "a", "b", "c", 2) +@AnnVarargs(1, "a", "b", "c", 2) class B diff --git a/compiler/fir/analysis-tests/testData/resolve/arguments/default.kt b/compiler/fir/analysis-tests/testData/resolve/arguments/default.kt index ac097bd9833..3e73a30ebbd 100644 --- a/compiler/fir/analysis-tests/testData/resolve/arguments/default.kt +++ b/compiler/fir/analysis-tests/testData/resolve/arguments/default.kt @@ -15,7 +15,7 @@ fun test() { bar(1, 2.0, true) bar(1, 2.0, true, "my") - bar(1, true) + bar(1, true) baz(1) baz(1, "my", "yours") diff --git a/compiler/fir/analysis-tests/testData/resolve/arguments/lambda.kt b/compiler/fir/analysis-tests/testData/resolve/arguments/lambda.kt index a6e28c278e9..b4a477462ca 100644 --- a/compiler/fir/analysis-tests/testData/resolve/arguments/lambda.kt +++ b/compiler/fir/analysis-tests/testData/resolve/arguments/lambda.kt @@ -10,7 +10,7 @@ fun test() { foo({}) // Bad - foo(1) {} + foo(1) {} foo(f = {}) {} // OK @@ -21,14 +21,14 @@ fun test() { // Bad bar {} - bar({}) + bar({}) // OK baz(other = false, f = {}) baz({}, false) // Bad - baz {} - baz() {} + baz {} + baz() {} baz(other = false) {} } diff --git a/compiler/fir/analysis-tests/testData/resolve/arguments/vararg.kt b/compiler/fir/analysis-tests/testData/resolve/arguments/vararg.kt index 57da9476ce9..1d48314a728 100644 --- a/compiler/fir/analysis-tests/testData/resolve/arguments/vararg.kt +++ b/compiler/fir/analysis-tests/testData/resolve/arguments/vararg.kt @@ -13,6 +13,6 @@ fun test() { bar(1, z = true, y = *arrayOf("my", "yours")) bar(0, z = false, y = "", y = "other") - bar(0, "", true) + bar(0, "", true) bar(0, z = false, y = "", y = "other", y = "yet other") } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 1bfd996d9a0..ddba7722f77 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -259,7 +259,9 @@ private fun mapInapplicableCandidateError( ): List { val typeContext = session.typeContext val genericDiagnostic = FirErrors.INAPPLICABLE_CANDIDATE.createOn(source, diagnostic.candidate.symbol) - val diagnostics = diagnostic.candidate.diagnostics.filter { it.applicability == diagnostic.applicability }.mapNotNull { rootCause -> + val diagnostics = diagnostic.candidate.diagnostics.filter { + it.applicability.userRelevantApplicability == diagnostic.applicability.userRelevantApplicability + }.mapNotNull { rootCause -> when (rootCause) { is VarargArgumentOutsideParentheses -> FirErrors.VARARG_OUTSIDE_PARENTHESES.createOn( rootCause.argument.source ?: qualifiedAccessSource @@ -368,6 +370,12 @@ private fun mapInapplicableCandidateError( } } +private val CandidateApplicability.userRelevantApplicability: CandidateApplicability + get() = when (this) { + CandidateApplicability.INAPPLICABLE_ARGUMENTS_MAPPING_ERROR -> CandidateApplicability.INAPPLICABLE + else -> this + } + private fun mapSystemHasContradictionError( session: FirSession, diagnostic: ConeConstraintSystemHasContradiction, diff --git a/compiler/testData/cli/jvm/wrongAbiVersion.out b/compiler/testData/cli/jvm/wrongAbiVersion.out index e5b32c9bc65..7d1ae2c4724 100644 --- a/compiler/testData/cli/jvm/wrongAbiVersion.out +++ b/compiler/testData/cli/jvm/wrongAbiVersion.out @@ -7,6 +7,9 @@ fun foo(x: ClassWithWrongAbiVersion) { compiler/testData/cli/jvm/wrongAbiVersion.kt:4:5: error: unresolved reference 'bar'. bar() ^ +compiler/testData/cli/jvm/wrongAbiVersion.kt:6:21: error: argument type mismatch: actual type is 'kotlin.Int', but 'kotlin.String' was expected. + 1.replaceIndent(2, 3) + ^ compiler/testData/cli/jvm/wrongAbiVersion.kt:6:24: error: too many arguments for 'public final fun kotlin/String.kotlin/text/replaceIndent(newIndent: kotlin/String = STUB): kotlin/String'. 1.replaceIndent(2, 3) ^ diff --git a/compiler/testData/diagnostics/tests/argumentTypeMismatchVsTooManyArgs.fir.kt b/compiler/testData/diagnostics/tests/argumentTypeMismatchVsTooManyArgs.fir.kt index 14e27dd5a12..21f4972d5a5 100644 --- a/compiler/testData/diagnostics/tests/argumentTypeMismatchVsTooManyArgs.fir.kt +++ b/compiler/testData/diagnostics/tests/argumentTypeMismatchVsTooManyArgs.fir.kt @@ -3,7 +3,7 @@ fun foo(i1: Int) {} fun test() { - foo("", + foo("", 2 ) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/checkArguments/kt1897_diagnostic_part.fir.kt b/compiler/testData/diagnostics/tests/checkArguments/kt1897_diagnostic_part.fir.kt index 67ba488f8f7..a32e88bc069 100644 --- a/compiler/testData/diagnostics/tests/checkArguments/kt1897_diagnostic_part.fir.kt +++ b/compiler/testData/diagnostics/tests/checkArguments/kt1897_diagnostic_part.fir.kt @@ -12,17 +12,17 @@ fun test() { bar { } - foo("", 1, xx) + foo("", 1, xx) - foo(r = xx, i = "", s = "") + foo(r = xx, i = "", s = "") foo(i = 1, i = 1, s = 11) foo("", s = 2) - foo(i = "", s = 2, 33) + foo(i = "", s = 2, 33) - foo("", 1) {} + foo("", 1) {} - foo("", 1) {} {} + foo("", 1) {} {} } diff --git a/compiler/testData/diagnostics/tests/delegation/kt44843.fir.kt b/compiler/testData/diagnostics/tests/delegation/kt44843.fir.kt index b0aaa61274f..b00f001dd65 100644 --- a/compiler/testData/diagnostics/tests/delegation/kt44843.fir.kt +++ b/compiler/testData/diagnostics/tests/delegation/kt44843.fir.kt @@ -1,13 +1,13 @@ // WITH_STDLIB // FILE: test.kt -val bar2 by bar2() +val bar2 by bar2() // FILE: lt/neworld/compiler/Foo.kt package lt.neworld.compiler class Foo { - val bar by bar() + val bar by bar() } // FILE: lt/neworld/compiler/bar/Bar.kt diff --git a/compiler/testData/diagnostics/tests/extensions/variableInvoke.fir.kt b/compiler/testData/diagnostics/tests/extensions/variableInvoke.fir.kt index 2a4208f86a3..696e846d50a 100644 --- a/compiler/testData/diagnostics/tests/extensions/variableInvoke.fir.kt +++ b/compiler/testData/diagnostics/tests/extensions/variableInvoke.fir.kt @@ -6,6 +6,6 @@ class A(foo: Int.() -> Unit) { fun test(foo: Int.(String) -> Unit) { 4.foo("") - 4.foo(p1 = "") + 4.foo(p1 = "") 4.foo(p2 = "") } diff --git a/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsAndDefaultValues.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsAndDefaultValues.fir.kt index 762d18f3200..d2df37bf784 100644 --- a/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsAndDefaultValues.fir.kt +++ b/compiler/testData/diagnostics/tests/namedArguments/namedArgumentsAndDefaultValues.fir.kt @@ -15,7 +15,7 @@ fun test() { bar(z = "") bar() - bar("") + bar("") bar(1, 1, "") bar(1, 1, "") bar(1, z = "") diff --git a/compiler/testData/diagnostics/tests/regressions/kt10633.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt10633.fir.kt index 76d3a221907..c4d40fb40d8 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt10633.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt10633.fir.kt @@ -15,5 +15,5 @@ fun main() { 1.set(2, z = 1) 1[2] += 1 - 1.set(2, 1) + 1.set(2, 1) } diff --git a/compiler/testData/diagnostics/tests/resolve/incompleteConstructorInvocation.fir.kt b/compiler/testData/diagnostics/tests/resolve/incompleteConstructorInvocation.fir.kt index 11d1435e5e4..becedfa1865 100644 --- a/compiler/testData/diagnostics/tests/resolve/incompleteConstructorInvocation.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/incompleteConstructorInvocation.fir.kt @@ -4,7 +4,7 @@ class X(provider: () -> V, trackValue: Boolean) { } class B { - val c = X { + val c = X { "e" - } + } } diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt index d944dd6727f..9b35f1fddd6 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.fir.kt @@ -6,7 +6,7 @@ fun test1() { fun test2(f: String.(Int) -> Unit) { 11.(f)(1) - 11.(f)() + 11.(f)() } fun test3() { diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt index ade7feeb8ad..134ad957b31 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt @@ -8,6 +8,6 @@ class SomeClass fun test(identifier: SomeClass, fn: String.() -> Unit) { identifier() identifier(123) - identifier(1, 2) + identifier(1, 2) 1.fn() } diff --git a/compiler/testData/diagnostics/tests/resolve/newLineLambda.fir.kt b/compiler/testData/diagnostics/tests/resolve/newLineLambda.fir.kt index aa778e14fa5..86b296be1dd 100644 --- a/compiler/testData/diagnostics/tests/resolve/newLineLambda.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/newLineLambda.fir.kt @@ -82,8 +82,8 @@ fun testVararg() { varargFn(1,2,3) // comment // comment {} - varargFn(1,2,3) {} {} - varargFn(1,2,3) {} + varargFn(1,2,3) {} {} + varargFn(1,2,3) {} {} } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/tooManyArgs.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/tooManyArgs.fir.kt index 91d7187dd78..0d030278322 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/tooManyArgs.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/tooManyArgs.fir.kt @@ -6,6 +6,6 @@ public @interface A { } // FILE: b.kt -@A(false, +@A(false, 1.0, false, 1, 2) fun foo1() {}