Return type of local delegated property setter should be Unit

#KT-17950 Fixed
This commit is contained in:
Dmitry Petrov
2017-05-19 12:16:20 +03:00
parent ba06ad3e53
commit bd5b984da9
3 changed files with 26 additions and 25 deletions
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.descriptors.impl
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.types.KotlinType
sealed class LocalVariableAccessorDescriptor(
@@ -38,7 +39,10 @@ sealed class LocalVariableAccessorDescriptor(
init {
val valueParameters =
if (isGetter) emptyList() else listOf(createValueParameter(Name.identifier("value"), correspondingVariable.type))
initialize(null, null, emptyList(), valueParameters, correspondingVariable.type, Modality.FINAL, Visibilities.LOCAL)
val returnType =
if (isGetter) correspondingVariable.type else correspondingVariable.builtIns.unitType
@Suppress("LeakingThis")
initialize(null, null, emptyList(), valueParameters, returnType, Modality.FINAL, Visibilities.LOCAL)
}
private fun createValueParameter(name: Name, type: KotlinType): ValueParameterDescriptorImpl {
@@ -35,33 +35,31 @@ FILE /localDelegatedProperties.kt
<V>: Int
$receiver: GET_VAR '`x$delegate`: HashMap<String, Int> /* = HashMap<String, Int> */' type=kotlin.collections.HashMap<kotlin.String, kotlin.Int> /* = java.util.HashMap<kotlin.String, kotlin.Int> */ origin=null
thisRef: CONST Null type=kotlin.Nothing? value='null'
property: LOCAL_DELEGATED_PROPERTY_REFERENCE 'x: Int' delegate='`x$delegate`: HashMap<String, Int> /* = HashMap<String, Int> */' getter='<get-x>(): Int' setter='<set-x>(Int): Int' type=kotlin.reflect.KMutableProperty0<kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
FUN DELEGATED_PROPERTY_ACCESSOR local final fun <set-x>(value: kotlin.Int): kotlin.Int
property: LOCAL_DELEGATED_PROPERTY_REFERENCE 'x: Int' delegate='`x$delegate`: HashMap<String, Int> /* = HashMap<String, Int> */' getter='<get-x>(): Int' setter='<set-x>(Int): Unit' type=kotlin.reflect.KMutableProperty0<kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
FUN DELEGATED_PROPERTY_ACCESSOR local final fun <set-x>(value: kotlin.Int): kotlin.Unit
VALUE_PARAMETER value-parameter value: kotlin.Int
BLOCK_BODY
RETURN type=kotlin.Nothing from='<set-x>(Int): Int'
TYPE_OP type=kotlin.Int origin=IMPLICIT_CAST typeOperand=kotlin.Int
CALL 'setValue(Any?, KProperty<*>, Int) on MutableMap<in String, in Int>: Unit' type=kotlin.Unit origin=null
<V>: Int
$receiver: GET_VAR '`x$delegate`: HashMap<String, Int> /* = HashMap<String, Int> */' type=kotlin.collections.HashMap<kotlin.String, kotlin.Int> /* = java.util.HashMap<kotlin.String, kotlin.Int> */ origin=null
thisRef: CONST Null type=kotlin.Nothing? value='null'
property: LOCAL_DELEGATED_PROPERTY_REFERENCE 'x: Int' delegate='`x$delegate`: HashMap<String, Int> /* = HashMap<String, Int> */' getter='<get-x>(): Int' setter='<set-x>(Int): Int' type=kotlin.reflect.KMutableProperty0<kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null
RETURN type=kotlin.Nothing from='<set-x>(Int): Unit'
CALL 'setValue(Any?, KProperty<*>, Int) on MutableMap<in String, in Int>: Unit' type=kotlin.Unit origin=null
<V>: Int
$receiver: GET_VAR '`x$delegate`: HashMap<String, Int> /* = HashMap<String, Int> */' type=kotlin.collections.HashMap<kotlin.String, kotlin.Int> /* = java.util.HashMap<kotlin.String, kotlin.Int> */ origin=null
thisRef: CONST Null type=kotlin.Nothing? value='null'
property: LOCAL_DELEGATED_PROPERTY_REFERENCE 'x: Int' delegate='`x$delegate`: HashMap<String, Int> /* = HashMap<String, Int> */' getter='<get-x>(): Int' setter='<set-x>(Int): Unit' type=kotlin.reflect.KMutableProperty0<kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CALL '<set-x>(Int): Int' type=kotlin.Int origin=EQ
CALL '<set-x>(Int): Unit' type=kotlin.Int origin=EQ
value: CONST Int type=kotlin.Int value='0'
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
BLOCK type=kotlin.Int origin=POSTFIX_INCR
VAR IR_TEMPORARY_VARIABLE val tmp0: kotlin.Int
CALL '<get-x>(): Int' type=kotlin.Int origin=POSTFIX_INCR
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CALL '<set-x>(Int): Int' type=kotlin.Int origin=POSTFIX_INCR
CALL '<set-x>(Int): Unit' type=kotlin.Int origin=POSTFIX_INCR
value: CALL 'inc(): Int' type=kotlin.Int origin=POSTFIX_INCR
$this: GET_VAR 'tmp0: Int' type=kotlin.Int origin=null
GET_VAR 'tmp0: Int' type=kotlin.Int origin=null
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CALL '<set-x>(Int): Int' type=kotlin.Int origin=PLUSEQ
CALL '<set-x>(Int): Unit' type=kotlin.Int origin=PLUSEQ
value: CALL 'plus(Int): Int' type=kotlin.Int origin=PLUSEQ
$this: CALL '<get-x>(): Int' type=kotlin.Int origin=PLUSEQ
other: CONST Int type=kotlin.Int value='1'
@@ -97,21 +97,20 @@ FILE /localDelegatedPropertyWithSuspendOperators.kt
CALL 'provideDelegate(Any?, Any): A' type=A origin=null
$this: CALL 'constructor A()' type=A origin=null
host: CONST Null type=kotlin.Nothing? value='null'
p: LOCAL_DELEGATED_PROPERTY_REFERENCE 'testVar: Int' delegate='`testVar$delegate`: A' getter='<get-testVar>(): Int' setter='<set-testVar>(Int): Int' type=kotlin.reflect.KMutableProperty0<kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
p: LOCAL_DELEGATED_PROPERTY_REFERENCE 'testVar: Int' delegate='`testVar$delegate`: A' getter='<get-testVar>(): Int' setter='<set-testVar>(Int): Unit' type=kotlin.reflect.KMutableProperty0<kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
FUN DELEGATED_PROPERTY_ACCESSOR local final suspend fun <get-testVar>(): kotlin.Int
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-testVar>(): Int'
CALL 'getValue(Any?, KProperty<*>): Int' type=kotlin.Int origin=null
$this: GET_VAR '`testVar$delegate`: A' type=A origin=null
thisRef: CONST Null type=kotlin.Nothing? value='null'
property: LOCAL_DELEGATED_PROPERTY_REFERENCE 'testVar: Int' delegate='`testVar$delegate`: A' getter='<get-testVar>(): Int' setter='<set-testVar>(Int): Int' type=kotlin.reflect.KMutableProperty0<kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
FUN DELEGATED_PROPERTY_ACCESSOR local final suspend fun <set-testVar>(value: kotlin.Int): kotlin.Int
property: LOCAL_DELEGATED_PROPERTY_REFERENCE 'testVar: Int' delegate='`testVar$delegate`: A' getter='<get-testVar>(): Int' setter='<set-testVar>(Int): Unit' type=kotlin.reflect.KMutableProperty0<kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
FUN DELEGATED_PROPERTY_ACCESSOR local final suspend fun <set-testVar>(value: kotlin.Int): kotlin.Unit
VALUE_PARAMETER value-parameter value: kotlin.Int
BLOCK_BODY
RETURN type=kotlin.Nothing from='<set-testVar>(Int): Int'
TYPE_OP type=kotlin.Int origin=IMPLICIT_CAST typeOperand=kotlin.Int
CALL 'setValue(Any?, KProperty<*>, Int): Unit' type=kotlin.Unit origin=null
$this: GET_VAR '`testVar$delegate`: A' type=A origin=null
thisRef: CONST Null type=kotlin.Nothing? value='null'
property: LOCAL_DELEGATED_PROPERTY_REFERENCE 'testVar: Int' delegate='`testVar$delegate`: A' getter='<get-testVar>(): Int' setter='<set-testVar>(Int): Int' type=kotlin.reflect.KMutableProperty0<kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null
RETURN type=kotlin.Nothing from='<set-testVar>(Int): Unit'
CALL 'setValue(Any?, KProperty<*>, Int): Unit' type=kotlin.Unit origin=null
$this: GET_VAR '`testVar$delegate`: A' type=A origin=null
thisRef: CONST Null type=kotlin.Nothing? value='null'
property: LOCAL_DELEGATED_PROPERTY_REFERENCE 'testVar: Int' delegate='`testVar$delegate`: A' getter='<get-testVar>(): Int' setter='<set-testVar>(Int): Unit' type=kotlin.reflect.KMutableProperty0<kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null