From 3eeab6826110b3e997dd675f2cb56c78a076b581 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 8 Dec 2015 18:57:38 +0300 Subject: [PATCH] Signature checks fixed for plus() and minus() --- .../tests/DeprecatedUnaryOperatorConventions.kt | 10 +++++----- compiler/testData/diagnostics/tests/OperatorChecks.kt | 8 ++++++-- compiler/testData/diagnostics/tests/OperatorChecks.txt | 8 ++++++-- .../src/org/jetbrains/kotlin/util/OperatorChecker.kt | 6 ++---- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/compiler/testData/diagnostics/tests/DeprecatedUnaryOperatorConventions.kt b/compiler/testData/diagnostics/tests/DeprecatedUnaryOperatorConventions.kt index a3dba473a4a..26cf5014740 100644 --- a/compiler/testData/diagnostics/tests/DeprecatedUnaryOperatorConventions.kt +++ b/compiler/testData/diagnostics/tests/DeprecatedUnaryOperatorConventions.kt @@ -1,15 +1,15 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER class Example { - operator fun plus(): String = "" + operator fun plus(): String = "" operator fun unaryPlus(): Int = 0 } class ExampleDeprecated { - operator fun plus(): String = "" + operator fun plus(): String = "" } -operator fun String.plus(): String = this +operator fun String.plus(): String = this operator fun String.unaryPlus(): Int = 0 fun test() { @@ -22,8 +22,8 @@ fun requireInt(n: Int) {} fun requireString(s: String) {} class Example2 { - operator fun plus() = this - operator fun minus() = this + operator fun plus() = this + operator fun minus() = this fun test() { +this diff --git a/compiler/testData/diagnostics/tests/OperatorChecks.kt b/compiler/testData/diagnostics/tests/OperatorChecks.kt index 302dc888ef6..3e7b299ec59 100644 --- a/compiler/testData/diagnostics/tests/OperatorChecks.kt +++ b/compiler/testData/diagnostics/tests/OperatorChecks.kt @@ -5,6 +5,8 @@ interface Example { operator fun div(o: Example): Example operator fun plus(o: Example, s: String = ""): Example operator fun minus(vararg o: Example): Example + operator fun plus(): Example + operator fun minus(): Example operator fun unaryPlus(): Example operator fun unaryMinus(): Example @@ -94,10 +96,12 @@ interface Example3 { -operator fun Example.plus(o: Example): Example {} +operator fun Example.plus(o: Any): Example {} operator fun Example.div(o: Example): Example {} operator fun Example.plus(o: Example, s: String = ""): Example {} operator fun Example.minus(vararg o: Example): Example {} +operator fun Example.plus(): Example {} +operator fun Example.minus(): Example {} operator fun Example.unaryPlus(): Example {} operator fun Example.unaryMinus(): Example {} @@ -155,7 +159,7 @@ infix fun Example.i1(n: Int) {} -operator fun plus(o: Example): Example {} +operator fun plus(o: String): Example {} operator fun div(o: Example): Example {} operator fun plus(o: Example, s: String = ""): Example {} operator fun minus(vararg o: Example): Example {} diff --git a/compiler/testData/diagnostics/tests/OperatorChecks.txt b/compiler/testData/diagnostics/tests/OperatorChecks.txt index eef03063dda..c76f8b4da7e 100644 --- a/compiler/testData/diagnostics/tests/OperatorChecks.txt +++ b/compiler/testData/diagnostics/tests/OperatorChecks.txt @@ -27,8 +27,8 @@ public operator fun minusAssign(/*0*/ n: kotlin.Int): kotlin.String public operator fun modAssign(/*0*/ vararg n: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit public operator fun next(): kotlin.String public operator fun next(/*0*/ n: kotlin.Int): kotlin.String -public operator fun plus(/*0*/ o: Example): Example public operator fun plus(/*0*/ o: Example, /*1*/ s: kotlin.String = ...): Example +public operator fun plus(/*0*/ o: kotlin.String): Example public operator fun plusAssign(/*0*/ n: kotlin.Int): kotlin.Unit public operator fun rangeTo(/*0*/ vararg o: kotlin.String /*kotlin.Array*/): kotlin.Unit public operator fun rangeTo(/*0*/ o: kotlin.Int): kotlin.Unit @@ -62,13 +62,15 @@ public operator fun Example.inc(): Example public operator fun Example.invoke(): kotlin.Unit public operator fun Example.iterator(): kotlin.String public operator fun Example.iterator(/*0*/ n: kotlin.Int): kotlin.String +public operator fun Example.minus(): Example public operator fun Example.minus(/*0*/ vararg o: Example /*kotlin.Array*/): Example public operator fun Example.minusAssign(/*0*/ n: kotlin.Int): kotlin.String public operator fun Example.modAssign(/*0*/ vararg n: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit public operator fun Example.next(): kotlin.String public operator fun Example.next(/*0*/ n: kotlin.Int): kotlin.String -public operator fun Example.plus(/*0*/ o: Example): Example +public operator fun Example.plus(): Example public operator fun Example.plus(/*0*/ o: Example, /*1*/ s: kotlin.String = ...): Example +public operator fun Example.plus(/*0*/ o: kotlin.Any): Example public operator fun Example.plusAssign(/*0*/ n: kotlin.Int): kotlin.Unit public operator fun Example.rangeTo(/*0*/ vararg o: kotlin.String /*kotlin.Array*/): kotlin.Unit public operator fun Example.rangeTo(/*0*/ o: kotlin.Int): kotlin.Unit @@ -119,11 +121,13 @@ public interface Example { public abstract operator fun invoke(): kotlin.Unit public abstract operator fun iterator(): kotlin.String public abstract operator fun iterator(/*0*/ n: kotlin.Int): kotlin.String + public abstract operator fun minus(): Example public abstract operator fun minus(/*0*/ vararg o: Example /*kotlin.Array*/): Example public abstract operator fun minusAssign(/*0*/ n: kotlin.Int): kotlin.String public abstract operator fun modAssign(/*0*/ vararg n: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit public abstract operator fun next(): kotlin.String public abstract operator fun next(/*0*/ n: kotlin.Int): kotlin.String + public abstract operator fun plus(): Example public abstract operator fun plus(/*0*/ o: Example): Example public abstract operator fun plus(/*0*/ o: Example, /*1*/ s: kotlin.String = ...): Example public abstract operator fun plusAssign(/*0*/ n: kotlin.Int): kotlin.Unit diff --git a/core/descriptors/src/org/jetbrains/kotlin/util/OperatorChecker.kt b/core/descriptors/src/org/jetbrains/kotlin/util/OperatorChecker.kt index aa1070e8604..e7054895f76 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/util/OperatorChecker.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/util/OperatorChecker.kt @@ -41,10 +41,8 @@ import org.jetbrains.kotlin.util.OperatorNameConventions.HAS_NEXT import org.jetbrains.kotlin.util.OperatorNameConventions.INC import org.jetbrains.kotlin.util.OperatorNameConventions.INVOKE import org.jetbrains.kotlin.util.OperatorNameConventions.ITERATOR -import org.jetbrains.kotlin.util.OperatorNameConventions.MINUS import org.jetbrains.kotlin.util.OperatorNameConventions.NEXT import org.jetbrains.kotlin.util.OperatorNameConventions.NOT -import org.jetbrains.kotlin.util.OperatorNameConventions.PLUS import org.jetbrains.kotlin.util.OperatorNameConventions.RANGE_TO import org.jetbrains.kotlin.util.OperatorNameConventions.SET import org.jetbrains.kotlin.util.OperatorNameConventions.SET_VALUE @@ -83,9 +81,9 @@ object OperatorChecks { } COMPARE_TO == name -> returnsInt && singleValueParameter && noDefaultsAndVarargs - BINARY_OPERATION_NAMES.any { it == name } && functionDescriptor.valueParameters.size == 1 -> + BINARY_OPERATION_NAMES.any { it == name } -> singleValueParameter && noDefaultsAndVarargs - (PLUS == name) || (MINUS == name) || (UNARY_PLUS == name) || (UNARY_MINUS == name) || (NOT == name) -> + (UNARY_PLUS == name) || (UNARY_MINUS == name) || (NOT == name) -> noValueParameters (INC == name) || (DEC == name) -> { val receiver = dispatchReceiverParameter ?: extensionReceiverParameter