Check presence of dispatch receiver parameter in modifier checks
Also fix typo in "inapplicable infix" diagnostic message
This commit is contained in:
@@ -14,11 +14,11 @@ class OkTest {
|
|||||||
<!INAPPLICABLE_INFIX_MODIFIER(must have a single value parameter)!>infix<!> fun String.e1(o: String, o2: String? = null) = o
|
<!INAPPLICABLE_INFIX_MODIFIER(must have a single value parameter)!>infix<!> fun String.e1(o: String, o2: String? = null) = o
|
||||||
<!INAPPLICABLE_INFIX_MODIFIER(must have a single value parameter)!>infix<!> fun String.e2(o: String = "", o2: String? = null) = o
|
<!INAPPLICABLE_INFIX_MODIFIER(must have a single value parameter)!>infix<!> fun String.e2(o: String = "", o2: String? = null) = o
|
||||||
|
|
||||||
<!INAPPLICABLE_INFIX_MODIFIER(must be a member of an extension function)!>infix<!> fun e3() {}
|
<!INAPPLICABLE_INFIX_MODIFIER(must be a member or an extension function)!>infix<!> fun e3() {}
|
||||||
<!INAPPLICABLE_INFIX_MODIFIER(must be a member of an extension function)!>infix<!> fun e4(s: String) {}
|
<!INAPPLICABLE_INFIX_MODIFIER(must be a member or an extension function)!>infix<!> fun e4(s: String) {}
|
||||||
<!INAPPLICABLE_INFIX_MODIFIER(must have a single value parameter)!>infix<!> fun String.e5() {}
|
<!INAPPLICABLE_INFIX_MODIFIER(must have a single value parameter)!>infix<!> fun String.e5() {}
|
||||||
<!INAPPLICABLE_INFIX_MODIFIER(must have a single value parameter)!>infix<!> fun String.e6(a: Int, b: Int) {}
|
<!INAPPLICABLE_INFIX_MODIFIER(must have a single value parameter)!>infix<!> fun String.e6(a: Int, b: Int) {}
|
||||||
<!INAPPLICABLE_INFIX_MODIFIER(must be a member of an extension function)!>infix<!> fun e7(a: Int, b: Int) {}
|
<!INAPPLICABLE_INFIX_MODIFIER(must be a member or an extension function)!>infix<!> fun e7(a: Int, b: Int) {}
|
||||||
|
|
||||||
class Example {
|
class Example {
|
||||||
<!INAPPLICABLE_INFIX_MODIFIER(must have a single value parameter)!>infix<!> fun e8(s: String, a: Int = 0) {}
|
<!INAPPLICABLE_INFIX_MODIFIER(must have a single value parameter)!>infix<!> fun e8(s: String, a: Int = 0) {}
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ public/*package*/ open class Java {
|
|||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
|
||||||
// Static members
|
// Static members
|
||||||
public open operator fun get(/*0*/ o: kotlin.collections.(Mutable)List<kotlin.Int!>!): kotlin.collections.(Mutable)List<kotlin.Int!>!
|
public open fun get(/*0*/ o: kotlin.collections.(Mutable)List<kotlin.Int!>!): kotlin.collections.(Mutable)List<kotlin.Int!>!
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.typeUtil.*
|
import org.jetbrains.kotlin.types.typeUtil.*
|
||||||
@@ -70,10 +69,11 @@ interface Check {
|
|||||||
sealed class MemberKindCheck(override val description: String) : Check {
|
sealed class MemberKindCheck(override val description: String) : Check {
|
||||||
object MemberOrExtension : MemberKindCheck("must be a member or an extension function") {
|
object MemberOrExtension : MemberKindCheck("must be a member or an extension function") {
|
||||||
override fun check(functionDescriptor: FunctionDescriptor) =
|
override fun check(functionDescriptor: FunctionDescriptor) =
|
||||||
functionDescriptor.isExtension || functionDescriptor.containingDeclaration is ClassDescriptor
|
functionDescriptor.dispatchReceiverParameter != null || functionDescriptor.extensionReceiverParameter != null
|
||||||
}
|
}
|
||||||
object Member : MemberKindCheck("must be a member function") {
|
object Member : MemberKindCheck("must be a member function") {
|
||||||
override fun check(functionDescriptor: FunctionDescriptor) = functionDescriptor.containingDeclaration is ClassDescriptor
|
override fun check(functionDescriptor: FunctionDescriptor) =
|
||||||
|
functionDescriptor.dispatchReceiverParameter != null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,13 +92,6 @@ sealed class ValueParameterCountCheck(override val description: String) : Check
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private object HasDispatchOrExtensionReceiverParameter : Check {
|
|
||||||
override val description = "must be a member of an extension function"
|
|
||||||
override fun check(functionDescriptor: FunctionDescriptor): Boolean {
|
|
||||||
return functionDescriptor.dispatchReceiverParameter != null || functionDescriptor.extensionReceiverParameter != null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private object NoDefaultAndVarargsCheck : Check {
|
private object NoDefaultAndVarargsCheck : Check {
|
||||||
override val description = "should not have varargs or parameters with default values"
|
override val description = "should not have varargs or parameters with default values"
|
||||||
override fun check(functionDescriptor: FunctionDescriptor) =
|
override fun check(functionDescriptor: FunctionDescriptor) =
|
||||||
@@ -238,7 +231,7 @@ object OperatorChecks : AbstractModifierChecks() {
|
|||||||
|
|
||||||
object InfixChecks : AbstractModifierChecks() {
|
object InfixChecks : AbstractModifierChecks() {
|
||||||
override val checks = listOf(
|
override val checks = listOf(
|
||||||
Checks(HasDispatchOrExtensionReceiverParameter, SingleValueParameter, NoDefaultAndVarargsCheck))
|
Checks(MemberKindCheck.MemberOrExtension, SingleValueParameter, NoDefaultAndVarargsCheck))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FunctionDescriptor.isValidOperator() = isOperator && OperatorChecks.check(this).isSuccess
|
fun FunctionDescriptor.isValidOperator() = isOperator && OperatorChecks.check(this).isSuccess
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// IS_APPLICABLE: false
|
// IS_APPLICABLE: false
|
||||||
// ERROR: 'infix' modifier is inapplicable on this function: must be a member of an extension function
|
// ERROR: 'infix' modifier is inapplicable on this function: must be a member or an extension function
|
||||||
infix fun id(s: String) = s
|
infix fun id(s: String) = s
|
||||||
val x = <caret>id("0").get(0)
|
val x = <caret>id("0").get(0)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// IS_APPLICABLE: false
|
// IS_APPLICABLE: false
|
||||||
// ERROR: 'infix' modifier is inapplicable on this function: must be a member of an extension function
|
// ERROR: 'infix' modifier is inapplicable on this function: must be a member or an extension function
|
||||||
package ppp
|
package ppp
|
||||||
|
|
||||||
infix fun foo(p: String){}
|
infix fun foo(p: String){}
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
ppp.<caret>foo("")
|
ppp.<caret>foo("")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// IS_APPLICABLE: false
|
// IS_APPLICABLE: false
|
||||||
// ERROR: 'infix' modifier is inapplicable on this function: must be a member of an extension function
|
// ERROR: 'infix' modifier is inapplicable on this function: must be a member or an extension function
|
||||||
|
|
||||||
package demo
|
package demo
|
||||||
|
|
||||||
@@ -8,4 +8,4 @@ infix fun foo(str: String) = kotlin.io.println(str)
|
|||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
<caret>demo.foo("")
|
<caret>demo.foo("")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// "Replace with 'newFun(p, this)'" "true"
|
// "Replace with 'newFun(p, this)'" "true"
|
||||||
// ERROR: 'infix' modifier is inapplicable on this function: must be a member of an extension function
|
// ERROR: 'infix' modifier is inapplicable on this function: must be a member or an extension function
|
||||||
|
|
||||||
@Deprecated("", ReplaceWith("newFun(p, this)"))
|
@Deprecated("", ReplaceWith("newFun(p, this)"))
|
||||||
infix fun String.oldFun(p: Int) {
|
infix fun String.oldFun(p: Int) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// "Replace with 'newFun(p, this)'" "true"
|
// "Replace with 'newFun(p, this)'" "true"
|
||||||
// ERROR: 'infix' modifier is inapplicable on this function: must be a member of an extension function
|
// ERROR: 'infix' modifier is inapplicable on this function: must be a member or an extension function
|
||||||
|
|
||||||
@Deprecated("", ReplaceWith("newFun(p, this)"))
|
@Deprecated("", ReplaceWith("newFun(p, this)"))
|
||||||
infix fun String.oldFun(p: Int) {
|
infix fun String.oldFun(p: Int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user