From a83225218f9a597e366c7bfd45530df7c1da94b0 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Tue, 17 Sep 2019 17:22:35 +0300 Subject: [PATCH] [NI] Fix checks for infix/operator conventions --- .../resolve/calls/components/ResolutionParts.kt | 10 ++++------ .../resolve/calls/model/KotlinResolverContext.kt | 3 +-- .../declarationChecks/MultiDeclarationErrors.kt | 2 +- .../tests/modifiers/operatorInfix/LocalFunctions.kt | 3 +-- .../modifiers/operatorInfix/MemberFunctions.kt | 5 ++--- .../tests/modifiers/operatorInfix/Simple.kt | 13 ++++++------- .../tests/operatorsOverloading/kt11300.kt | 6 ++++-- .../resolve/invoke/errors/ambiguityForInvoke.kt | 5 +++-- 8 files changed, 22 insertions(+), 25 deletions(-) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index 1643a07249b..507e91122b5 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -373,9 +373,8 @@ internal object EagerResolveOfCallableReferences : ResolutionPart() { internal object CheckInfixResolutionPart : ResolutionPart() { override fun KotlinResolutionCandidate.process(workIndex: Int) { val candidateDescriptor = resolvedCall.candidateDescriptor - if (callComponents.statelessCallbacks.isInfixCall(kotlinCall) && - (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isInfix) - ) { + if (candidateDescriptor !is FunctionDescriptor) return + if (!candidateDescriptor.isInfix && callComponents.statelessCallbacks.isInfixCall(kotlinCall)) { addDiagnostic(InfixCallNoInfixModifier) } } @@ -384,9 +383,8 @@ internal object CheckInfixResolutionPart : ResolutionPart() { internal object CheckOperatorResolutionPart : ResolutionPart() { override fun KotlinResolutionCandidate.process(workIndex: Int) { val candidateDescriptor = resolvedCall.candidateDescriptor - if (callComponents.statelessCallbacks.isOperatorCall(kotlinCall) && - (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator) - ) { + if (candidateDescriptor !is FunctionDescriptor) return + if (!candidateDescriptor.isOperator && callComponents.statelessCallbacks.isOperatorCall(kotlinCall)) { addDiagnostic(InvokeConventionCallNoOperatorModifier) } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt index fb90657bd73..f2e261645f9 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt @@ -196,8 +196,6 @@ class SimpleCandidateFactory( enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) { VARIABLE( CheckVisibility, - CheckInfixResolutionPart, - CheckOperatorResolutionPart, CheckSuperExpressionCallPart, NoTypeArguments, NoArguments, @@ -210,6 +208,7 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) { CheckInstantiationOfAbstractClass, CheckVisibility, CheckInfixResolutionPart, + CheckOperatorResolutionPart, CheckSuperExpressionCallPart, MapTypeArguments, MapArguments, diff --git a/compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.kt b/compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.kt index 4f0debaae31..5679433248b 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.kt @@ -12,7 +12,7 @@ class MyClass2 {} fun test(mc1: MyClass, mc2: MyClass2) { val (a, b) = mc1 - val (c) = mc2 + val (c) = mc2 //a,b,c are error types use(a, b, c) diff --git a/compiler/testData/diagnostics/tests/modifiers/operatorInfix/LocalFunctions.kt b/compiler/testData/diagnostics/tests/modifiers/operatorInfix/LocalFunctions.kt index c4fe083ba22..58c21ffe96d 100644 --- a/compiler/testData/diagnostics/tests/modifiers/operatorInfix/LocalFunctions.kt +++ b/compiler/testData/diagnostics/tests/modifiers/operatorInfix/LocalFunctions.kt @@ -1,4 +1,3 @@ -// !WITH_NEW_INFERENCE // !DIAGNOSTICS: -UNUSED_PARAMETER class Example @@ -22,7 +21,7 @@ fun a() { val b = Example() consumeString(a + b) - consumeInt(a - b) + consumeInt(a - b) consumeString(a plus b) consumeInt(a minus b) diff --git a/compiler/testData/diagnostics/tests/modifiers/operatorInfix/MemberFunctions.kt b/compiler/testData/diagnostics/tests/modifiers/operatorInfix/MemberFunctions.kt index 407ddbbd32d..118c18e1137 100644 --- a/compiler/testData/diagnostics/tests/modifiers/operatorInfix/MemberFunctions.kt +++ b/compiler/testData/diagnostics/tests/modifiers/operatorInfix/MemberFunctions.kt @@ -1,4 +1,3 @@ -// !WITH_NEW_INFERENCE // !DIAGNOSTICS: -UNUSED_PARAMETER, -EXTENSION_SHADOWED_BY_MEMBER class Example { @@ -20,7 +19,7 @@ fun a() { val b = Example() a + b - a - b + a - b a * b a / b @@ -31,7 +30,7 @@ fun a() { with (Example()) { consumeInt(this + a) - consumeString(this - b) + consumeString(this - b) consumeInt(this * a) consumeInt(this / b) diff --git a/compiler/testData/diagnostics/tests/modifiers/operatorInfix/Simple.kt b/compiler/testData/diagnostics/tests/modifiers/operatorInfix/Simple.kt index 8d8e23988a0..b58a31a2e03 100644 --- a/compiler/testData/diagnostics/tests/modifiers/operatorInfix/Simple.kt +++ b/compiler/testData/diagnostics/tests/modifiers/operatorInfix/Simple.kt @@ -1,4 +1,3 @@ -// !WITH_NEW_INFERENCE // !DIAGNOSTICS: -UNUSED_PARAMETER, -EXTENSION_SHADOWED_BY_MEMBER open class Example { @@ -29,14 +28,14 @@ fun test() { var a = Example() val b = Example() - consumeString(a()) - consumeString(a[1]) + consumeString(a()) + consumeString(a[1]) - val (x, y) = Example() - consumeString(x) - consumeString(y) + val (x, y) = Example() + consumeString(x) + consumeString(y) - consumeExample2(++a) + consumeExample2(++a) consumeString(a plus b) } diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/kt11300.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/kt11300.kt index f50f94e395c..1c3ba2925e5 100644 --- a/compiler/testData/diagnostics/tests/operatorsOverloading/kt11300.kt +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/kt11300.kt @@ -1,3 +1,5 @@ +// !WITH_NEW_INFERENCE + class A { operator fun get(x: Int): Int = x fun set(x: Int, y: Int) {} // no `operator` modifier @@ -5,7 +7,7 @@ class A { fun main() { val a = A() - a[1]++ - a[1] += 3 + a[1]++ + a[1] += 3 a[1] = a[1] + 3 } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/ambiguityForInvoke.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/ambiguityForInvoke.kt index 655ac209284..df4f3e17450 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/errors/ambiguityForInvoke.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/ambiguityForInvoke.kt @@ -1,10 +1,11 @@ +// !WITH_NEW_INFERENCE // !DIAGNOSTICS: -UNUSED_PARAMETER fun Int.invoke(i: Int, a: Any) {} fun Int.invoke(a: Any, i: Int) {} fun foo(i: Int) { - i(1, 1) + i(1, 1) - 5(1, 2) + 5(1, 2) }