fix KT-7042 Providing return type for property setter is not reported as error
#KT-7042 Fixed
This commit is contained in:
@@ -340,6 +340,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<PsiElement> PRIVATE_SETTER_ON_NON_PRIVATE_LATE_INIT_VAR = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> ACCESSOR_VISIBILITY_FOR_ABSTRACT_PROPERTY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory2<KtTypeReference, KotlinType, KotlinType> WRONG_GETTER_RETURN_TYPE = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory0<KtTypeReference> WRONG_SETTER_RETURN_TYPE = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtModifierListOwner>
|
||||
ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = DiagnosticFactory0.create(ERROR, ABSTRACT_MODIFIER);
|
||||
|
||||
+1
@@ -323,6 +323,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(USELESS_NULLABLE_CHECK, "Non-null type is checked for instance of nullable type");
|
||||
MAP.put(WRONG_SETTER_PARAMETER_TYPE, "Setter parameter type must be equal to the type of the property, i.e. ''{0}''", RENDER_TYPE, RENDER_TYPE);
|
||||
MAP.put(WRONG_GETTER_RETURN_TYPE, "Getter return type must be equal to the type of the property, i.e. ''{0}''", RENDER_TYPE, RENDER_TYPE);
|
||||
MAP.put(WRONG_SETTER_RETURN_TYPE, "Setter return type must be Unit");
|
||||
MAP.put(NO_COMPANION_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a companion object", NAME);
|
||||
MAP.put(TYPE_PARAMETER_IS_NOT_AN_EXPRESSION, "Type parameter ''{0}'' is not an expression", NAME);
|
||||
MAP.put(TYPE_PARAMETER_ON_LHS_OF_DOT, "Type parameter ''{0}'' cannot have or inherit a companion object, so it cannot be on the left hand side of dot", NAME);
|
||||
|
||||
@@ -1010,6 +1010,14 @@ public class DescriptorResolver {
|
||||
setter.hasBody(), false, setter.hasModifier(EXTERNAL_KEYWORD),
|
||||
CallableMemberDescriptor.Kind.DECLARATION, null, KotlinSourceElementKt
|
||||
.toSourceElement(setter));
|
||||
KtTypeReference returnTypeReference = setter.getReturnTypeReference();
|
||||
if (returnTypeReference != null) {
|
||||
KotlinType returnType = typeResolver.resolveType(scope, returnTypeReference, trace, true);
|
||||
if (!KotlinBuiltIns.isUnit(returnType)) {
|
||||
trace.report(WRONG_SETTER_RETURN_TYPE.on(returnTypeReference));
|
||||
}
|
||||
}
|
||||
|
||||
if (parameter != null) {
|
||||
|
||||
// This check is redundant: the parser does not allow a default value, but we'll keep it just in case
|
||||
|
||||
Reference in New Issue
Block a user