[Assign plugin] Add a compiler plugin for overloading assign ('=') operator

This commit is contained in:
Anže Sodja
2022-09-01 07:51:38 +02:00
committed by Dmitriy Novozhilov
parent 6052962f50
commit 09d6dfc8bf
62 changed files with 2822 additions and 6 deletions
@@ -0,0 +1,19 @@
/incorrectUsage.kt:18:5: error: val cannot be reassigned
task.input = 42
^
/incorrectUsage.kt:18:16: error: no applicable 'assign' function found for '=' overload
task.input = 42
^
/incorrectUsage.kt:18:18: error: the integer literal does not conform to the expected type StringProperty
task.input = 42
^
/incorrectUsage.kt:24:9: error: val cannot be reassigned
input = 42
^
/incorrectUsage.kt:24:15: error: no applicable 'assign' function found for '=' overload
input = 42
^
/incorrectUsage.kt:24:17: error: the integer literal does not conform to the expected type StringProperty
input = 42
^
@@ -0,0 +1,26 @@
annotation class ValueContainer
@ValueContainer
data class StringProperty(var v: String) {
fun assign(v: String) {
this.v = v
}
fun assign(v: StringProperty) {
this.v = v.get()
}
fun get(): String = v
}
data class Task(val input: StringProperty)
fun `should report error if type doesn't match`() {
val task = Task(StringProperty("Fail"))
task.<!NONE_APPLICABLE!>input<!> <!NO_APPLICABLE_ASSIGN_METHOD!>=<!> 42
}
fun `should report error if type doesn't match with apply`() {
val task = Task(StringProperty("Fail"))
task.apply {
<!NONE_APPLICABLE!>input<!> <!NO_APPLICABLE_ASSIGN_METHOD!>=<!> 42
}
}
@@ -0,0 +1,27 @@
annotation class ValueContainer
@ValueContainer
data class StringProperty(var v: String) {
fun assign(v: String) {
this.v = v
}
fun assign(v: StringProperty) {
this.v = v.get()
}
fun get(): String = v
}
data class Task(val input: StringProperty)
fun `should report error if type doesn't match`() {
val task = Task(StringProperty("Fail"))
<!VAL_REASSIGNMENT!>task.input<!> <!NO_APPLICABLE_ASSIGN_METHOD!>=<!> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
}
fun `should report error if type doesn't match with apply`() {
val task = Task(StringProperty("Fail"))
task.apply {
<!VAL_REASSIGNMENT!>input<!> <!NO_APPLICABLE_ASSIGN_METHOD!>=<!> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
}
}
@@ -0,0 +1,35 @@
package
public fun `should report error if type doesn't match`(): kotlin.Unit
public fun `should report error if type doesn't match with apply`(): kotlin.Unit
@ValueContainer public final data class StringProperty {
public constructor StringProperty(/*0*/ v: kotlin.String)
public final var v: kotlin.String
public final fun assign(/*0*/ v: StringProperty): kotlin.Unit
public final fun assign(/*0*/ v: kotlin.String): kotlin.Unit
public final operator /*synthesized*/ fun component1(): kotlin.String
public final /*synthesized*/ fun copy(/*0*/ v: kotlin.String = ...): StringProperty
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun get(): kotlin.String
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final data class Task {
public constructor Task(/*0*/ input: StringProperty)
public final val input: StringProperty
public final operator /*synthesized*/ fun component1(): StringProperty
public final /*synthesized*/ fun copy(/*0*/ input: StringProperty = ...): Task
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final annotation class ValueContainer : kotlin.Annotation {
public constructor ValueContainer()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,22 @@
/localVariables.kt:18:5: error: val cannot be reassigned
property = "Fail"
^
/localVariables.kt:18:16: error: type mismatch: inferred type is String but StringProperty was expected
property = "Fail"
^
/localVariables.kt:23:5: error: val cannot be reassigned
property = StringProperty("Fail")
^
/localVariables.kt:28:16: error: type mismatch: inferred type is String but StringProperty was expected
property = "Fail"
^
/localVariables.kt:38:9: error: val cannot be reassigned
property = "Fail"
^
/localVariables.kt:38:20: error: type mismatch: inferred type is String but StringProperty was expected
property = "Fail"
^
/localVariables.kt:42:9: error: val cannot be reassigned
property = StringProperty("Fail")
^
@@ -0,0 +1,44 @@
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
annotation class ValueContainer
@ValueContainer
data class StringProperty(var v: String) {
fun assign(v: String) {
this.v = v
}
fun assign(v: StringProperty) {
this.v = v.get()
}
fun get(): String = v
}
fun `should not work with local val for different type`() {
val property = StringProperty("OK")
<!VAL_REASSIGNMENT!>property<!> = <!ASSIGNMENT_TYPE_MISMATCH!>"Fail"<!>
}
fun `should not work with local val for same type`() {
val property = StringProperty("OK")
<!VAL_REASSIGNMENT!>property<!> = StringProperty("Fail")
}
fun `should not work with local var for different type`() {
var property = StringProperty("OK")
property = <!ASSIGNMENT_TYPE_MISMATCH!>"Fail"<!>
}
fun `should work with local var for same type`() {
var property = StringProperty("OK")
property = StringProperty("Fail")
}
fun `should not work with method parameters`() {
fun m1(property: StringProperty): Unit {
<!VAL_REASSIGNMENT!>property<!> = <!ASSIGNMENT_TYPE_MISMATCH!>"Fail"<!>
}
fun m2(property: StringProperty): Unit {
<!VAL_REASSIGNMENT!>property<!> = StringProperty("Fail")
}
}
@@ -0,0 +1,44 @@
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
annotation class ValueContainer
@ValueContainer
data class StringProperty(var v: String) {
fun assign(v: String) {
this.v = v
}
fun assign(v: StringProperty) {
this.v = v.get()
}
fun get(): String = v
}
fun `should not work with local val for different type`() {
val property = StringProperty("OK")
<!VAL_REASSIGNMENT!>property<!> = <!TYPE_MISMATCH!>"Fail"<!>
}
fun `should not work with local val for same type`() {
val property = StringProperty("OK")
<!VAL_REASSIGNMENT!>property<!> = StringProperty("Fail")
}
fun `should not work with local var for different type`() {
var property = StringProperty("OK")
property = <!TYPE_MISMATCH!>"Fail"<!>
}
fun `should work with local var for same type`() {
var property = StringProperty("OK")
property = StringProperty("Fail")
}
fun `should not work with method parameters`() {
fun m1(property: StringProperty): Unit {
<!VAL_REASSIGNMENT!>property<!> = <!TYPE_MISMATCH!>"Fail"<!>
}
fun m2(property: StringProperty): Unit {
<!VAL_REASSIGNMENT!>property<!> = StringProperty("Fail")
}
}
@@ -0,0 +1,27 @@
package
public fun `should not work with local val for different type`(): kotlin.Unit
public fun `should not work with local val for same type`(): kotlin.Unit
public fun `should not work with local var for different type`(): kotlin.Unit
public fun `should not work with method parameters`(): kotlin.Unit
public fun `should work with local var for same type`(): kotlin.Unit
@ValueContainer public final data class StringProperty {
public constructor StringProperty(/*0*/ v: kotlin.String)
public final var v: kotlin.String
public final fun assign(/*0*/ v: StringProperty): kotlin.Unit
public final fun assign(/*0*/ v: kotlin.String): kotlin.Unit
public final operator /*synthesized*/ fun component1(): kotlin.String
public final /*synthesized*/ fun copy(/*0*/ v: kotlin.String = ...): StringProperty
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun get(): kotlin.String
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final annotation class ValueContainer : kotlin.Annotation {
public constructor ValueContainer()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,28 @@
/methodDeclaration.kt:5:28: error: function 'assign' used for '=' overload should return 'Unit'
fun assign(v: String): String {
^
/methodDeclaration.kt:9:36: error: function 'assign' used for '=' overload should return 'Unit'
fun assign(v: StringProperty): String {
^
/methodDeclaration.kt:16:36: error: function 'assign' used for '=' overload should return 'Unit'
fun StringProperty.assign(v: Int): String {
^
/methodDeclaration.kt:25:5: error: val cannot be reassigned
task.input = "42"
^
/methodDeclaration.kt:25:16: error: function 'assign' used for '=' overload should return 'Unit'
task.input = "42"
^
/methodDeclaration.kt:26:5: error: val cannot be reassigned
task.input = 42
^
/methodDeclaration.kt:26:16: error: function 'assign' used for '=' overload should return 'Unit'
task.input = 42
^
/methodDeclaration.kt:35:5: error: val cannot be reassigned
task.input = 42
^
/methodDeclaration.kt:35:18: error: the integer literal does not conform to the expected type IntProperty
task.input = 42
^
@@ -0,0 +1,36 @@
annotation class ValueContainer
@ValueContainer
data class StringProperty(var v: String) {
fun assign(v: String): <!DECLARATION_ERROR_ASSIGN_METHOD_SHOULD_RETURN_UNIT!>String<!> {
this.v = v
return ""
}
fun assign(v: StringProperty): <!DECLARATION_ERROR_ASSIGN_METHOD_SHOULD_RETURN_UNIT!>String<!> {
this.v = v.get()
return ""
}
fun get(): String = v
}
fun StringProperty.assign(v: Int): <!DECLARATION_ERROR_ASSIGN_METHOD_SHOULD_RETURN_UNIT!>String<!> {
this.v = "OK"
return ""
}
data class Task(val input: StringProperty)
fun `should report an error for assign method return type on assignment for annotated class`() {
val task = Task(StringProperty("Fail"))
task.input <!CALL_ERROR_ASSIGN_METHOD_SHOULD_RETURN_UNIT!>=<!> "42"
task.input <!CALL_ERROR_ASSIGN_METHOD_SHOULD_RETURN_UNIT!>=<!> 42
}
fun `should not report an error for assign return type for unannotated class`() {
data class IntProperty(var v: Int)
fun IntProperty.assign(v: Int): String = "OK"
data class IntTask(val input: IntProperty)
val task = IntTask(IntProperty(42))
task.input = <!ASSIGNMENT_TYPE_MISMATCH!>42<!>
}
@@ -0,0 +1,36 @@
annotation class ValueContainer
@ValueContainer
data class StringProperty(var v: String) {
fun assign(v: String): <!DECLARATION_ERROR_ASSIGN_METHOD_SHOULD_RETURN_UNIT!>String<!> {
this.v = v
return ""
}
fun assign(v: StringProperty): <!DECLARATION_ERROR_ASSIGN_METHOD_SHOULD_RETURN_UNIT!>String<!> {
this.v = v.get()
return ""
}
fun get(): String = v
}
fun StringProperty.assign(v: Int): <!DECLARATION_ERROR_ASSIGN_METHOD_SHOULD_RETURN_UNIT!>String<!> {
this.v = "OK"
return ""
}
data class Task(val input: StringProperty)
fun `should report an error for assign method return type on assignment for annotated class`() {
val task = Task(StringProperty("Fail"))
<!VAL_REASSIGNMENT!>task.input<!> <!CALL_ERROR_ASSIGN_METHOD_SHOULD_RETURN_UNIT!>=<!> "42"
<!VAL_REASSIGNMENT!>task.input<!> <!CALL_ERROR_ASSIGN_METHOD_SHOULD_RETURN_UNIT!>=<!> 42
}
fun `should not report an error for assign return type for unannotated class`() {
data class IntProperty(var v: Int)
fun IntProperty.assign(v: Int): String = "OK"
data class IntTask(val input: IntProperty)
val task = IntTask(IntProperty(42))
<!VAL_REASSIGNMENT!>task.input<!> = <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
}
@@ -0,0 +1,36 @@
package
public fun `should not report an error for assign return type for unannotated class`(): kotlin.Unit
public fun `should report an error for assign method return type on assignment for annotated class`(): kotlin.Unit
public fun StringProperty.assign(/*0*/ v: kotlin.Int): kotlin.String
@ValueContainer public final data class StringProperty {
public constructor StringProperty(/*0*/ v: kotlin.String)
public final var v: kotlin.String
public final fun assign(/*0*/ v: StringProperty): kotlin.String
public final fun assign(/*0*/ v: kotlin.String): kotlin.String
public final operator /*synthesized*/ fun component1(): kotlin.String
public final /*synthesized*/ fun copy(/*0*/ v: kotlin.String = ...): StringProperty
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun get(): kotlin.String
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final data class Task {
public constructor Task(/*0*/ input: StringProperty)
public final val input: StringProperty
public final operator /*synthesized*/ fun component1(): StringProperty
public final /*synthesized*/ fun copy(/*0*/ input: StringProperty = ...): Task
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final annotation class ValueContainer : kotlin.Annotation {
public constructor ValueContainer()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,31 @@
/noAnnotation.kt:17:5: error: val cannot be reassigned
task.input = "OK"
^
/noAnnotation.kt:17:18: error: type mismatch: inferred type is String but StringProperty was expected
task.input = "OK"
^
/noAnnotation.kt:18:5: error: val cannot be reassigned
task.input = StringProperty("OK")
^
/noAnnotation.kt:20:9: error: val cannot be reassigned
input = "OK"
^
/noAnnotation.kt:20:17: error: type mismatch: inferred type is String but StringProperty was expected
input = "OK"
^
/noAnnotation.kt:23:9: error: val cannot be reassigned
input = StringProperty("OK")
^
/noAnnotation.kt:25:5: error: val cannot be reassigned
task.input = 42
^
/noAnnotation.kt:25:18: error: the integer literal does not conform to the expected type StringProperty
task.input = 42
^
/noAnnotation.kt:27:9: error: val cannot be reassigned
input = 42
^
/noAnnotation.kt:27:17: error: the integer literal does not conform to the expected type StringProperty
input = 42
^
@@ -0,0 +1,29 @@
data class StringProperty(var v: String) {
fun assign(v: String) {
this.v = v
}
fun assign(v: StringProperty) {
this.v = v.get()
}
fun get(): String = v
}
fun StringProperty.assign(v: Int) = this.assign("OK")
data class Task(val input: StringProperty)
fun `should not work with assignment when there is no annotation on a type`() {
val task = Task(StringProperty("Fail"))
task.input = <!ASSIGNMENT_TYPE_MISMATCH!>"OK"<!>
task.input = StringProperty("OK")
task.apply {
input = <!ASSIGNMENT_TYPE_MISMATCH!>"OK"<!>
}
task.apply {
input = StringProperty("OK")
}
task.input = <!ASSIGNMENT_TYPE_MISMATCH!>42<!>
task.apply {
input = <!ASSIGNMENT_TYPE_MISMATCH!>42<!>
}
}
@@ -0,0 +1,29 @@
data class StringProperty(var v: String) {
fun assign(v: String) {
this.v = v
}
fun assign(v: StringProperty) {
this.v = v.get()
}
fun get(): String = v
}
fun StringProperty.assign(v: Int) = this.assign("OK")
data class Task(val input: StringProperty)
fun `should not work with assignment when there is no annotation on a type`() {
val task = Task(StringProperty("Fail"))
<!VAL_REASSIGNMENT!>task.input<!> = <!TYPE_MISMATCH!>"OK"<!>
<!VAL_REASSIGNMENT!>task.input<!> = StringProperty("OK")
task.apply {
<!VAL_REASSIGNMENT!>input<!> = <!TYPE_MISMATCH!>"OK"<!>
}
task.apply {
<!VAL_REASSIGNMENT!>input<!> = StringProperty("OK")
}
<!VAL_REASSIGNMENT!>task.input<!> = <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
task.apply {
<!VAL_REASSIGNMENT!>input<!> = <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
}
}
@@ -0,0 +1,28 @@
package
public fun `should not work with assignment when there is no annotation on a type`(): kotlin.Unit
public fun StringProperty.assign(/*0*/ v: kotlin.Int): kotlin.Unit
public final data class StringProperty {
public constructor StringProperty(/*0*/ v: kotlin.String)
public final var v: kotlin.String
public final fun assign(/*0*/ v: StringProperty): kotlin.Unit
public final fun assign(/*0*/ v: kotlin.String): kotlin.Unit
public final operator /*synthesized*/ fun component1(): kotlin.String
public final /*synthesized*/ fun copy(/*0*/ v: kotlin.String = ...): StringProperty
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun get(): kotlin.String
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final data class Task {
public constructor Task(/*0*/ input: StringProperty)
public final val input: StringProperty
public final operator /*synthesized*/ fun component1(): StringProperty
public final /*synthesized*/ fun copy(/*0*/ input: StringProperty = ...): Task
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
@@ -0,0 +1,89 @@
/otherOperators.kt:21:16: error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public operator fun String?.plus(other: Any?): String defined in kotlin
task.input += StringProperty("Fail")
^
/otherOperators.kt:22:21: error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public operator fun String?.plus(other: Any?): String defined in kotlin
nullTask?.input += StringProperty("Fail")
^
/otherOperators.kt:25:16: error: unresolved reference: <=
task.input <= StringProperty("Fail")
^
/otherOperators.kt:26:21: error: unresolved reference: <=
nullTask?.input <= StringProperty("Fail")
^
/otherOperators.kt:29:16: error: unresolved reference: >=
task.input >= StringProperty("Fail")
^
/otherOperators.kt:30:21: error: unresolved reference: >=
nullTask?.input >= StringProperty("Fail")
^
/otherOperators.kt:33:15: error: unresolved reference: task.input[0]
task.input[0] = StringProperty("Fail")
^
/otherOperators.kt:33:15: error: no set method providing array access
task.input[0] = StringProperty("Fail")
^
/otherOperators.kt:34:20: error: unresolved reference: nullTask?.input[0]
nullTask?.input[0] = StringProperty("Fail")
^
/otherOperators.kt:34:20: error: no set method providing array access
nullTask?.input[0] = StringProperty("Fail")
^
/otherOperators.kt:37:15: error: unresolved reference: task.input[0, 0]
task.input[0, 0] = StringProperty("Fail")
^
/otherOperators.kt:37:15: error: no set method providing array access
task.input[0, 0] = StringProperty("Fail")
^
/otherOperators.kt:38:20: error: unresolved reference: nullTask?.input[0, 0]
nullTask?.input[0, 0] = StringProperty("Fail")
^
/otherOperators.kt:38:20: error: no set method providing array access
nullTask?.input[0, 0] = StringProperty("Fail")
^
/otherOperators.kt:41:15: error: unresolved reference: task.input[0, 0, 0]
task.input[0, 0, 0] = StringProperty("Fail")
^
/otherOperators.kt:41:15: error: no set method providing array access
task.input[0, 0, 0] = StringProperty("Fail")
^
/otherOperators.kt:42:20: error: unresolved reference: nullTask?.input[0, 0, 0]
nullTask?.input[0, 0, 0] = StringProperty("Fail")
^
/otherOperators.kt:42:20: error: no set method providing array access
nullTask?.input[0, 0, 0] = StringProperty("Fail")
^
/otherOperators.kt:45:5: error: 'operator' modifier is required on 'get' in 'StringProperty'
task.input[0] += StringProperty("Fail")
^
/otherOperators.kt:45:15: error: no set method providing array access
task.input[0] += StringProperty("Fail")
^
/otherOperators.kt:45:16: error: too many arguments for public final fun get(): String defined in StringProperty
task.input[0] += StringProperty("Fail")
^
/otherOperators.kt:46:5: error: 'operator' modifier is required on 'get' in 'StringProperty'
nullTask?.input[0] += StringProperty("Fail")
^
/otherOperators.kt:46:5: error: only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type StringProperty?
nullTask?.input[0] += StringProperty("Fail")
^
/otherOperators.kt:46:20: error: no set method providing array access
nullTask?.input[0] += StringProperty("Fail")
^
/otherOperators.kt:46:21: error: too many arguments for public final fun get(): String defined in StringProperty
nullTask?.input[0] += StringProperty("Fail")
^
/otherOperators.kt:50:9: error: unresolved reference: task[0]
task[0] = StringProperty("Fail")
^
/otherOperators.kt:50:9: error: no set method providing array access
task[0] = StringProperty("Fail")
^
/otherOperators.kt:53:10: error: variable expected
task.get(0) = StringProperty("Fail")
^
/otherOperators.kt:54:15: error: variable expected
nullTask?.get(0) = StringProperty("Fail")
^
@@ -0,0 +1,55 @@
annotation class ValueContainer
@ValueContainer
data class StringProperty(var v: String) {
fun assign(v: String) {
this.v = v
}
fun assign(v: StringProperty) {
this.v = v.get()
}
fun get(): String = v
}
data class Task(val input: StringProperty)
fun `should not effect error reporting for other operators`() {
val task = Task(StringProperty("Fail"))
val nullTask: Task? = null
// a.b += c
task.input <!UNRESOLVED_REFERENCE!>+=<!> StringProperty("Fail")
nullTask?.input <!UNRESOLVED_REFERENCE!>+=<!> StringProperty("Fail")
// a.b <= c
task.input <!UNRESOLVED_REFERENCE!><=<!> StringProperty("Fail")
nullTask?.input <!UNRESOLVED_REFERENCE!><=<!> StringProperty("Fail")
// a.b >= c
task.input <!UNRESOLVED_REFERENCE!>>=<!> StringProperty("Fail")
nullTask?.input <!UNRESOLVED_REFERENCE!>>=<!> StringProperty("Fail")
// a.b[c] = d
task.input<!NO_SET_METHOD!>[0]<!> = StringProperty("Fail")
nullTask?.input<!NO_SET_METHOD!>[0]<!> = StringProperty("Fail")
// a.b[c, d] = e
task.input<!NO_SET_METHOD!>[0, 0]<!> = StringProperty("Fail")
nullTask?.input<!NO_SET_METHOD!>[0, 0]<!> = StringProperty("Fail")
// a.b[c,..,d] = e
task.input<!NO_SET_METHOD!>[0, 0, 0]<!> = StringProperty("Fail")
nullTask?.input<!NO_SET_METHOD!>[0, 0, 0]<!> = StringProperty("Fail")
// a?.b[c] += d
task.input[<!TOO_MANY_ARGUMENTS!>0<!>] <!UNRESOLVED_REFERENCE!>+=<!> StringProperty("Fail")
nullTask?.input[<!TOO_MANY_ARGUMENTS!>0<!>] <!UNRESOLVED_REFERENCE!>+=<!> StringProperty("Fail")
// a[i] = b should not be translated to a.get(i).assign(b)
operator fun Task.get(i: Int) = this.input
task<!NO_SET_METHOD!>[0]<!> = StringProperty("Fail")
// a.get(i) = b should not be translated to a.get(i).assign(b)
task.<!FUNCTION_CALL_EXPECTED!>get<!>(0) = StringProperty("Fail")
nullTask?.<!FUNCTION_CALL_EXPECTED!>get<!>(0) = StringProperty("Fail")
}
@@ -0,0 +1,55 @@
annotation class ValueContainer
@ValueContainer
data class StringProperty(var v: String) {
fun assign(v: String) {
this.v = v
}
fun assign(v: StringProperty) {
this.v = v.get()
}
fun get(): String = v
}
data class Task(val input: StringProperty)
fun `should not effect error reporting for other operators`() {
val task = Task(StringProperty("Fail"))
val nullTask: Task? = null
// a.b += c
task.input <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>+=<!> StringProperty("Fail")
nullTask?.input <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>+=<!> StringProperty("Fail")
// a.b <= c
task.input <!UNRESOLVED_REFERENCE!><=<!> StringProperty("Fail")
nullTask?.input <!UNRESOLVED_REFERENCE!><=<!> StringProperty("Fail")
// a.b >= c
task.input <!UNRESOLVED_REFERENCE!>>=<!> StringProperty("Fail")
nullTask?.input <!UNRESOLVED_REFERENCE!>>=<!> StringProperty("Fail")
// a.b[c] = d
task.input<!NO_SET_METHOD!><!UNRESOLVED_REFERENCE!>[<!>0<!UNRESOLVED_REFERENCE!>]<!><!> = StringProperty("Fail")
nullTask?.input<!NO_SET_METHOD!><!UNRESOLVED_REFERENCE!>[<!>0<!UNRESOLVED_REFERENCE!>]<!><!> = StringProperty("Fail")
// a.b[c, d] = e
task.input<!NO_SET_METHOD!><!UNRESOLVED_REFERENCE!>[<!>0, 0<!UNRESOLVED_REFERENCE!>]<!><!> = StringProperty("Fail")
nullTask?.input<!NO_SET_METHOD!><!UNRESOLVED_REFERENCE!>[<!>0, 0<!UNRESOLVED_REFERENCE!>]<!><!> = StringProperty("Fail")
// a.b[c,..,d] = e
task.input<!NO_SET_METHOD!><!UNRESOLVED_REFERENCE!>[<!>0, 0, 0<!UNRESOLVED_REFERENCE!>]<!><!> = StringProperty("Fail")
nullTask?.input<!NO_SET_METHOD!><!UNRESOLVED_REFERENCE!>[<!>0, 0, 0<!UNRESOLVED_REFERENCE!>]<!><!> = StringProperty("Fail")
// a?.b[c] += d
<!OPERATOR_MODIFIER_REQUIRED!>task.input<!NO_SET_METHOD!>[<!TOO_MANY_ARGUMENTS!>0<!>]<!><!> += StringProperty("Fail")
<!OPERATOR_MODIFIER_REQUIRED, UNSAFE_CALL!>nullTask?.input<!NO_SET_METHOD!>[<!TOO_MANY_ARGUMENTS!>0<!>]<!><!> += StringProperty("Fail")
// a[i] = b should not be translated to a.get(i).assign(b)
operator fun Task.get(i: Int) = this.input
task<!NO_SET_METHOD!><!UNRESOLVED_REFERENCE!>[<!>0<!UNRESOLVED_REFERENCE!>]<!><!> = StringProperty("Fail")
// a.get(i) = b should not be translated to a.get(i).assign(b)
task.<!VARIABLE_EXPECTED!>get(0)<!> = StringProperty("Fail")
nullTask?.<!VARIABLE_EXPECTED!>get(0)<!> = StringProperty("Fail")
}
@@ -0,0 +1,33 @@
package
public fun `should not effect error reporting for other operators`(): kotlin.Unit
@ValueContainer public final data class StringProperty {
public constructor StringProperty(/*0*/ v: kotlin.String)
public final var v: kotlin.String
public final fun assign(/*0*/ v: StringProperty): kotlin.Unit
public final fun assign(/*0*/ v: kotlin.String): kotlin.Unit
public final operator /*synthesized*/ fun component1(): kotlin.String
public final /*synthesized*/ fun copy(/*0*/ v: kotlin.String = ...): StringProperty
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun get(): kotlin.String
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final data class Task {
public constructor Task(/*0*/ input: StringProperty)
public final val input: StringProperty
public final operator /*synthesized*/ fun component1(): StringProperty
public final /*synthesized*/ fun copy(/*0*/ input: StringProperty = ...): Task
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final annotation class ValueContainer : kotlin.Annotation {
public constructor ValueContainer()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,17 @@
/plusAssignPrecedence.kt:96:19: error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public operator fun String?.plus(other: Any?): String defined in kotlin
task.valInput += "K"
^
/plusAssignPrecedence.kt:97:19: error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public operator fun String?.plus(other: Any?): String defined in kotlin
task.varInput += "K"
^
/plusAssignPrecedence.kt:99:5: error: val cannot be reassigned
task.valInputWithPlus += "K"
^
/plusAssignPrecedence.kt:101:40: error: assignment operators ambiguity:
public final operator fun plus(v: String): StringPropertyWithPlusAndPlusAssign defined in StringPropertyWithPlusAndPlusAssign
public final operator fun plusAssign(v: String): Unit defined in StringPropertyWithPlusAndPlusAssign
task.varInputWithPlusAndPlusAssign += "K"
^
@@ -0,0 +1,104 @@
annotation class ValueContainer
abstract class AbstractStringProperty(protected var v: String) {
fun get(): String {
return v
}
}
@ValueContainer
class StringProperty(v: String) : AbstractStringProperty(v) {
fun assign(v: String) {
this.v = v
}
fun assign(v: StringProperty) {
this.v = v.get()
}
}
@ValueContainer
class StringPropertyWithPlus(v: String) : AbstractStringProperty(v) {
fun assign(v: String) {
this.v = v
}
fun assign(o: StringPropertyWithPlus) {
this.v = o.get()
}
operator fun plus(v: String) =
StringPropertyWithPlus(this.v + v)
}
@ValueContainer
class StringPropertyWithPlusAssign(v: String) : AbstractStringProperty(v) {
fun assign(v: String) {
this.v = v
}
fun assign(o: StringPropertyWithPlusAssign) {
this.v = o.get()
}
operator fun plusAssign(v: String) {
this.v += v
}
}
@ValueContainer
class StringPropertyWithPlusAndPlusAssign(v: String) : AbstractStringProperty(v) {
fun assign(v: String) {
this.v = v
}
fun assign(o: StringPropertyWithPlusAndPlusAssign) {
this.v = o.get()
}
operator fun plus(v: String) =
StringPropertyWithPlusAndPlusAssign(this.v + v)
operator fun plusAssign(v: String) {
this.v += v
}
}
data class Task(
val valInput: StringProperty,
var varInput: StringProperty,
val valInputWithPlus: StringPropertyWithPlus,
var varInputWithPlus: StringPropertyWithPlus,
val valInputWithPlusAssign: StringPropertyWithPlusAssign,
var varInputWithPlusAssign: StringPropertyWithPlusAssign,
val valInputWithPlusAndPlusAssign: StringPropertyWithPlusAndPlusAssign,
var varInputWithPlusAndPlusAssign: StringPropertyWithPlusAndPlusAssign,
)
fun box(): String {
val task = Task(
StringProperty("O"),
StringProperty("O"),
StringPropertyWithPlus("O"),
StringPropertyWithPlus("O"),
StringPropertyWithPlusAssign("O"),
StringPropertyWithPlusAssign("O"),
StringPropertyWithPlusAndPlusAssign("O"),
StringPropertyWithPlusAndPlusAssign("O")
)
task.valInput <!UNRESOLVED_REFERENCE!>+=<!> "K"
task.varInput <!UNRESOLVED_REFERENCE!>+=<!> "K"
task.<!VAL_REASSIGNMENT!>valInputWithPlus<!> += "K"
task.varInputWithPlusAndPlusAssign <!ASSIGN_OPERATOR_AMBIGUITY!>+=<!> "K"
return "OK"
}
@@ -0,0 +1,104 @@
annotation class ValueContainer
abstract class AbstractStringProperty(protected var v: String) {
fun get(): String {
return v
}
}
@ValueContainer
class StringProperty(v: String) : AbstractStringProperty(v) {
fun assign(v: String) {
this.v = v
}
fun assign(v: StringProperty) {
this.v = v.get()
}
}
@ValueContainer
class StringPropertyWithPlus(v: String) : AbstractStringProperty(v) {
fun assign(v: String) {
this.v = v
}
fun assign(o: StringPropertyWithPlus) {
this.v = o.get()
}
operator fun plus(v: String) =
StringPropertyWithPlus(this.v + v)
}
@ValueContainer
class StringPropertyWithPlusAssign(v: String) : AbstractStringProperty(v) {
fun assign(v: String) {
this.v = v
}
fun assign(o: StringPropertyWithPlusAssign) {
this.v = o.get()
}
operator fun plusAssign(v: String) {
this.v += v
}
}
@ValueContainer
class StringPropertyWithPlusAndPlusAssign(v: String) : AbstractStringProperty(v) {
fun assign(v: String) {
this.v = v
}
fun assign(o: StringPropertyWithPlusAndPlusAssign) {
this.v = o.get()
}
operator fun plus(v: String) =
StringPropertyWithPlusAndPlusAssign(this.v + v)
operator fun plusAssign(v: String) {
this.v += v
}
}
data class Task(
val valInput: StringProperty,
var varInput: StringProperty,
val valInputWithPlus: StringPropertyWithPlus,
var varInputWithPlus: StringPropertyWithPlus,
val valInputWithPlusAssign: StringPropertyWithPlusAssign,
var varInputWithPlusAssign: StringPropertyWithPlusAssign,
val valInputWithPlusAndPlusAssign: StringPropertyWithPlusAndPlusAssign,
var varInputWithPlusAndPlusAssign: StringPropertyWithPlusAndPlusAssign,
)
fun box(): String {
val task = Task(
StringProperty("O"),
StringProperty("O"),
StringPropertyWithPlus("O"),
StringPropertyWithPlus("O"),
StringPropertyWithPlusAssign("O"),
StringPropertyWithPlusAssign("O"),
StringPropertyWithPlusAndPlusAssign("O"),
StringPropertyWithPlusAndPlusAssign("O")
)
task.valInput <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>+=<!> "K"
task.varInput <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>+=<!> "K"
<!VAL_REASSIGNMENT!>task.valInputWithPlus<!> += "K"
task.varInputWithPlusAndPlusAssign <!ASSIGN_OPERATOR_AMBIGUITY!>+=<!> "K"
return "OK"
}
@@ -0,0 +1,92 @@
package
public fun box(): kotlin.String
public abstract class AbstractStringProperty {
public constructor AbstractStringProperty(/*0*/ v: kotlin.String)
protected final var v: kotlin.String
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun get(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@ValueContainer public final class StringProperty : AbstractStringProperty {
public constructor StringProperty(/*0*/ v: kotlin.String)
protected final override /*1*/ /*fake_override*/ var v: kotlin.String
public final fun assign(/*0*/ v: StringProperty): kotlin.Unit
public final fun assign(/*0*/ v: kotlin.String): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final override /*1*/ /*fake_override*/ fun get(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@ValueContainer public final class StringPropertyWithPlus : AbstractStringProperty {
public constructor StringPropertyWithPlus(/*0*/ v: kotlin.String)
protected final override /*1*/ /*fake_override*/ var v: kotlin.String
public final fun assign(/*0*/ o: StringPropertyWithPlus): kotlin.Unit
public final fun assign(/*0*/ v: kotlin.String): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final override /*1*/ /*fake_override*/ fun get(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final operator fun plus(/*0*/ v: kotlin.String): StringPropertyWithPlus
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@ValueContainer public final class StringPropertyWithPlusAndPlusAssign : AbstractStringProperty {
public constructor StringPropertyWithPlusAndPlusAssign(/*0*/ v: kotlin.String)
protected final override /*1*/ /*fake_override*/ var v: kotlin.String
public final fun assign(/*0*/ o: StringPropertyWithPlusAndPlusAssign): kotlin.Unit
public final fun assign(/*0*/ v: kotlin.String): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final override /*1*/ /*fake_override*/ fun get(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final operator fun plus(/*0*/ v: kotlin.String): StringPropertyWithPlusAndPlusAssign
public final operator fun plusAssign(/*0*/ v: kotlin.String): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@ValueContainer public final class StringPropertyWithPlusAssign : AbstractStringProperty {
public constructor StringPropertyWithPlusAssign(/*0*/ v: kotlin.String)
protected final override /*1*/ /*fake_override*/ var v: kotlin.String
public final fun assign(/*0*/ o: StringPropertyWithPlusAssign): kotlin.Unit
public final fun assign(/*0*/ v: kotlin.String): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final override /*1*/ /*fake_override*/ fun get(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final operator fun plusAssign(/*0*/ v: kotlin.String): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final data class Task {
public constructor Task(/*0*/ valInput: StringProperty, /*1*/ varInput: StringProperty, /*2*/ valInputWithPlus: StringPropertyWithPlus, /*3*/ varInputWithPlus: StringPropertyWithPlus, /*4*/ valInputWithPlusAssign: StringPropertyWithPlusAssign, /*5*/ varInputWithPlusAssign: StringPropertyWithPlusAssign, /*6*/ valInputWithPlusAndPlusAssign: StringPropertyWithPlusAndPlusAssign, /*7*/ varInputWithPlusAndPlusAssign: StringPropertyWithPlusAndPlusAssign)
public final val valInput: StringProperty
public final val valInputWithPlus: StringPropertyWithPlus
public final val valInputWithPlusAndPlusAssign: StringPropertyWithPlusAndPlusAssign
public final val valInputWithPlusAssign: StringPropertyWithPlusAssign
public final var varInput: StringProperty
public final var varInputWithPlus: StringPropertyWithPlus
public final var varInputWithPlusAndPlusAssign: StringPropertyWithPlusAndPlusAssign
public final var varInputWithPlusAssign: StringPropertyWithPlusAssign
public final operator /*synthesized*/ fun component1(): StringProperty
public final operator /*synthesized*/ fun component2(): StringProperty
public final operator /*synthesized*/ fun component3(): StringPropertyWithPlus
public final operator /*synthesized*/ fun component4(): StringPropertyWithPlus
public final operator /*synthesized*/ fun component5(): StringPropertyWithPlusAssign
public final operator /*synthesized*/ fun component6(): StringPropertyWithPlusAssign
public final operator /*synthesized*/ fun component7(): StringPropertyWithPlusAndPlusAssign
public final operator /*synthesized*/ fun component8(): StringPropertyWithPlusAndPlusAssign
public final /*synthesized*/ fun copy(/*0*/ valInput: StringProperty = ..., /*1*/ varInput: StringProperty = ..., /*2*/ valInputWithPlus: StringPropertyWithPlus = ..., /*3*/ varInputWithPlus: StringPropertyWithPlus = ..., /*4*/ valInputWithPlusAssign: StringPropertyWithPlusAssign = ..., /*5*/ varInputWithPlusAssign: StringPropertyWithPlusAssign = ..., /*6*/ valInputWithPlusAndPlusAssign: StringPropertyWithPlusAndPlusAssign = ..., /*7*/ varInputWithPlusAndPlusAssign: StringPropertyWithPlusAndPlusAssign = ...): Task
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final annotation class ValueContainer : kotlin.Annotation {
public constructor ValueContainer()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}