[FE] Inline classes cannot have context receivers

This commit is contained in:
Anastasiya Shadrina
2021-03-16 19:21:05 +07:00
committed by TeamCityServer
parent d704862582
commit 1a0aab4a44
9 changed files with 64 additions and 0 deletions
@@ -385,6 +385,7 @@ public interface Errors {
DiagnosticFactory0<PsiElement> INNER_CLASS_INSIDE_VALUE_CLASS = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> VALUE_CLASS_CANNOT_BE_CLONEABLE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> INLINE_CLASS_DEPRECATED = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<KtContextReceiverList> INLINE_CLASS_CANNOT_HAVE_CONTEXT_RECEIVERS = DiagnosticFactory0.create(ERROR);
// Result class
@@ -761,6 +761,7 @@ public class DefaultErrorMessages {
MAP.put(INNER_CLASS_INSIDE_VALUE_CLASS, "Value class cannot have inner classes");
MAP.put(VALUE_CLASS_CANNOT_BE_CLONEABLE, "Value class cannot be Cloneable");
MAP.put(INLINE_CLASS_DEPRECATED, "'inline' modifier is deprecated. Use 'value' instead");
MAP.put(INLINE_CLASS_CANNOT_HAVE_CONTEXT_RECEIVERS, "Inline classes cannot have context receivers");
MAP.put(RESULT_CLASS_IN_RETURN_TYPE, "'kotlin.Result' cannot be used as a return type");
MAP.put(RESULT_CLASS_WITH_NULLABLE_OPERATOR, "Expression of type 'kotlin.Result' cannot be used as a left operand of ''{0}''", STRING);
@@ -58,6 +58,12 @@ object InlineClassDeclarationChecker : DeclarationChecker {
return
}
if (declaration.contextReceivers.isNotEmpty()) {
val contextReceiverList = declaration.getContextReceiverList()
requireNotNull(contextReceiverList) { "Declaration cannot have context receivers with no context receiver list" }
trace.report(Errors.INLINE_CLASS_CANNOT_HAVE_CONTEXT_RECEIVERS.on(contextReceiverList))
}
val modalityModifier = declaration.modalityModifier()
if (modalityModifier != null && descriptor.modality != Modality.FINAL) {
trace.report(Errors.VALUE_CLASS_NOT_FINAL.on(modalityModifier))