K1: report warning for inline virtual member in enum #KT-53148 Fixed
Related to KT-34372
This commit is contained in:
+6
@@ -17310,6 +17310,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/inline/vararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("virtualMemberInEnum.kt")
|
||||
public void testVirtualMemberInEnum() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inline/virtualMemberInEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("when.kt")
|
||||
public void testWhen() throws Exception {
|
||||
|
||||
+6
@@ -17310,6 +17310,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/inline/vararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("virtualMemberInEnum.kt")
|
||||
public void testVirtualMemberInEnum() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inline/virtualMemberInEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("when.kt")
|
||||
public void testWhen() throws Exception {
|
||||
|
||||
+6
@@ -17310,6 +17310,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/inline/vararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("virtualMemberInEnum.kt")
|
||||
public void testVirtualMemberInEnum() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inline/virtualMemberInEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("when.kt")
|
||||
public void testWhen() throws Exception {
|
||||
|
||||
@@ -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);
|
||||
|
||||
+1
@@ -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");
|
||||
|
||||
+4
-2
@@ -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))
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
enum class Some {
|
||||
A {
|
||||
<!OVERRIDE_BY_INLINE!>override fun foo(s: () -> String): String<!> {
|
||||
return s() + s()
|
||||
}
|
||||
};
|
||||
|
||||
//SHOULD BE ERROR REPORTED
|
||||
open <!DECLARATION_CANT_BE_INLINED!>inline<!> fun foo(s: () -> String): String {
|
||||
return s()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
enum class Some {
|
||||
A {
|
||||
override fun foo(s: () -> String): String {
|
||||
return s() + s()
|
||||
}
|
||||
};
|
||||
|
||||
//SHOULD BE ERROR REPORTED
|
||||
open <!DECLARATION_CANT_BE_INLINED_WARNING!>inline<!> fun foo(s: () -> String): String {
|
||||
return s()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package
|
||||
|
||||
public final enum class Some : kotlin.Enum<Some> {
|
||||
enum entry A
|
||||
|
||||
private constructor Some()
|
||||
@kotlin.internal.IntrinsicConstEvaluation public final override /*1*/ /*fake_override*/ val name: kotlin.String
|
||||
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
|
||||
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
|
||||
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: Some): kotlin.Int
|
||||
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit
|
||||
public open inline fun foo(/*0*/ s: () -> kotlin.String): kotlin.String
|
||||
public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class<Some!>!
|
||||
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): Some
|
||||
public final /*synthesized*/ fun values(): kotlin.Array<Some>
|
||||
}
|
||||
Generated
+6
@@ -17316,6 +17316,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/inline/vararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("virtualMemberInEnum.kt")
|
||||
public void testVirtualMemberInEnum() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inline/virtualMemberInEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("when.kt")
|
||||
public void testWhen() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user