[NI] Fix checks for infix/operator conventions

This commit is contained in:
Mikhail Zarechenskiy
2019-09-17 17:22:35 +03:00
parent f45a49b122
commit a83225218f
8 changed files with 22 additions and 25 deletions
@@ -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)
}
}
@@ -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,
@@ -12,7 +12,7 @@ class MyClass2 {}
fun test(mc1: MyClass, mc2: MyClass2) {
val (<!OPERATOR_MODIFIER_REQUIRED!>a<!>, b) = <!COMPONENT_FUNCTION_MISSING, COMPONENT_FUNCTION_MISSING!>mc1<!>
val (c) = <!COMPONENT_FUNCTION_AMBIGUITY!>mc2<!>
val (c) = <!NI;COMPONENT_FUNCTION_MISSING, OI;COMPONENT_FUNCTION_AMBIGUITY!>mc2<!>
//a,b,c are error types
use(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>a<!>, <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>b<!>, <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>c<!>)
@@ -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(<!NI;TYPE_MISMATCH!>a <!NI;OPERATOR_MODIFIER_REQUIRED!>-<!> b<!>)
consumeInt(a - b)
consumeString(a plus b)
consumeInt(a minus b)
@@ -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 <!NI;OPERATOR_MODIFIER_REQUIRED!>-<!> b
a - b
a * b
a <!OPERATOR_MODIFIER_REQUIRED!>/<!> b
@@ -31,7 +30,7 @@ fun a() {
with (Example()) {
consumeInt(this + a)
consumeString(<!NI;TYPE_MISMATCH!>this <!NI;OPERATOR_MODIFIER_REQUIRED!>-<!> b<!>)
consumeString(this - b)
consumeInt(this * a)
consumeInt(this <!OPERATOR_MODIFIER_REQUIRED!>/<!> b)
@@ -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(<!NI;TYPE_MISMATCH!><!NI;OPERATOR_MODIFIER_REQUIRED!>a<!>()<!>)
consumeString(<!NI;OPERATOR_MODIFIER_REQUIRED, NI;TYPE_MISMATCH!>a[1]<!>)
consumeString(a())
consumeString(a[1])
val (<!NI;OPERATOR_MODIFIER_REQUIRED!>x<!>, <!NI;OPERATOR_MODIFIER_REQUIRED!>y<!>) = Example()
consumeString(<!NI;TYPE_MISMATCH!>x<!>)
consumeString(<!NI;TYPE_MISMATCH!>y<!>)
val (x, y) = Example()
consumeString(x)
consumeString(y)
consumeExample2(<!NI;TYPE_MISMATCH!><!NI;OPERATOR_MODIFIER_REQUIRED!>++<!>a<!>)
consumeExample2(++a)
consumeString(a plus b)
}
@@ -1,3 +1,5 @@
// !WITH_NEW_INFERENCE
class A {
operator fun get(x: Int): Int = x
fun set(<!UNUSED_PARAMETER!>x<!>: Int, <!UNUSED_PARAMETER!>y<!>: Int) {} // no `operator` modifier
@@ -5,7 +7,7 @@ class A {
fun main() {
val a = A()
<!OPERATOR_MODIFIER_REQUIRED!>a[1]<!>++
<!OPERATOR_MODIFIER_REQUIRED!>a[1]<!> += 3
<!OPERATOR_MODIFIER_REQUIRED!>a<!NI;NO_SET_METHOD!>[1]<!><!>++
<!OPERATOR_MODIFIER_REQUIRED!>a<!NI;NO_SET_METHOD!>[1]<!><!> += 3
<!OPERATOR_MODIFIER_REQUIRED!>a[1]<!> = a[1] + 3
}
@@ -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) {
<!OVERLOAD_RESOLUTION_AMBIGUITY!>i<!>(1, 1)
<!NI;NONE_APPLICABLE, OI;OVERLOAD_RESOLUTION_AMBIGUITY!>i<!>(1, 1)
<!OVERLOAD_RESOLUTION_AMBIGUITY!>5<!>(1, 2)
<!NI;NONE_APPLICABLE, OI;OVERLOAD_RESOLUTION_AMBIGUITY!>5<!>(1, 2)
}