K1: report warning for inline virtual member in enum #KT-53148 Fixed

Related to KT-34372
This commit is contained in:
Mikhail Glukhikh
2022-07-12 11:34:42 +02:00
committed by Space
parent f509a756fd
commit 475e40b3e4
10 changed files with 75 additions and 2 deletions
@@ -1274,6 +1274,7 @@ public interface Errors {
DiagnosticFactory2<KtElement, KtElement, DeclarationDescriptor> NULLABLE_INLINE_PARAMETER = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<KtElement, KtElement, DeclarationDescriptor> RECURSION_IN_INLINE = DiagnosticFactory2.create(ERROR);
DiagnosticFactory0<KtDeclaration> DECLARATION_CANT_BE_INLINED = DiagnosticFactory0.create(ERROR, INLINE_FUN_MODIFIER);
DiagnosticFactory0<KtDeclaration> DECLARATION_CANT_BE_INLINED_WARNING = DiagnosticFactory0.create(WARNING, INLINE_FUN_MODIFIER);
DiagnosticFactory0<KtDeclaration> OVERRIDE_BY_INLINE = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
DiagnosticFactory0<PsiElement> REIFIED_TYPE_PARAMETER_IN_OVERRIDE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<PsiElement, CallableDescriptor> INLINE_CALL_CYCLE = DiagnosticFactory1.create(ERROR, DEFAULT);
@@ -1085,6 +1085,7 @@ public class DefaultErrorMessages {
MAP.put(PRIVATE_CLASS_MEMBER_FROM_INLINE, "Non-private inline function cannot access members of private classes: ''{0}''", SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES);
MAP.put(NOT_YET_SUPPORTED_IN_INLINE, "{0} are not yet supported in inline functions", STRING);
MAP.put(DECLARATION_CANT_BE_INLINED, "'inline' modifier is not allowed on virtual members. Only private or final members can be inlined");
MAP.put(DECLARATION_CANT_BE_INLINED_WARNING, "'inline' modifier is not allowed on virtual enum members. Only private or final members can be inlined. This warning will become an error in K2");
MAP.put(OVERRIDE_BY_INLINE, "Override by an inline function");
MAP.put(REIFIED_TYPE_PARAMETER_IN_OVERRIDE, "Override by a function with reified type parameter");
MAP.put(NOTHING_TO_INLINE, "Expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types");
@@ -159,11 +159,13 @@ class InlineAnalyzerExtension(
}
}
//TODO: actually it should be isEffectivelyFinal(false), but looks like it requires committee decision: KT-34372)
if (callableDescriptor.isEffectivelyFinal(true)) {
if (callableDescriptor.isEffectivelyFinal(ignoreEnumClassFinality = true)) {
if (overridesAnything) {
trace.report(Errors.OVERRIDE_BY_INLINE.on(functionOrProperty))
}
if (!callableDescriptor.isEffectivelyFinal(ignoreEnumClassFinality = false)) {
trace.report(Errors.DECLARATION_CANT_BE_INLINED_WARNING.on(functionOrProperty))
}
return
}
trace.report(Errors.DECLARATION_CANT_BE_INLINED.on(functionOrProperty))