Do not hide synthetic properties except isEmpty from Java

In order to hide synthetic property isEmpty from JDK 15, there was
 added additional logic in 5cc12b49fc but
 it also lead to the fact that now it's impossible to call synthetic
 property `declaringClass` on `Enum` as it's in the same list as method
 isEmpty(). Note that it's questionable behavior, probably we should
 also hide `declaringClass` as well but for now we turn it back to
 preserve compatibility

 #KT-42467 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-10-14 23:05:50 +03:00
parent 4227e2dc40
commit eacc94a89d
6 changed files with 35 additions and 2 deletions
@@ -11045,6 +11045,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/enum/constructorWithReordering.kt");
}
@TestMetadata("declaringClassOnEnumObject.kt")
public void testDeclaringClassOnEnumObject() throws Exception {
runTest("compiler/testData/codegen/box/enum/declaringClassOnEnumObject.kt");
}
@TestMetadata("deepInnerClassInEnumEntryClass.kt")
public void testDeepInnerClassInEnumEntryClass() throws Exception {
runTest("compiler/testData/codegen/box/enum/deepInnerClassInEnumEntryClass.kt");
@@ -162,7 +162,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
return descriptor.valueParameters.isEmpty()
&& descriptor.typeParameters.isEmpty()
&& descriptor.visibility.isVisibleOutside()
&& !descriptor.isHiddenForResolutionEverywhereBesideSupercalls
&& !(descriptor.isHiddenForResolutionEverywhereBesideSupercalls && descriptor.name.asString() == "isEmpty") // CharSequence.isEmpty() from JDK15
}
private fun isGoodSetMethod(descriptor: FunctionDescriptor, getMethod: FunctionDescriptor): Boolean {
@@ -179,7 +179,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
return parameter.varargElementType == null
&& descriptor.typeParameters.isEmpty()
&& descriptor.visibility.isVisibleOutside()
&& !descriptor.isHiddenForResolutionEverywhereBesideSupercalls
&& !(descriptor.isHiddenForResolutionEverywhereBesideSupercalls && descriptor.name.asString() == "isEmpty") // CharSequence.isEmpty() from JDK15
}
private fun FunctionDescriptor.findOverridden(condition: (FunctionDescriptor) -> Boolean): FunctionDescriptor? {
@@ -0,0 +1,13 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
enum class KEnum { A }
fun test(e: KEnum): String {
return e.declaringClass.toString()
}
fun box(): String {
val result = test(KEnum.A)
return if (result == "class KEnum") "OK" else "fail: $result"
}
@@ -12440,6 +12440,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/enum/constructorWithReordering.kt");
}
@TestMetadata("declaringClassOnEnumObject.kt")
public void testDeclaringClassOnEnumObject() throws Exception {
runTest("compiler/testData/codegen/box/enum/declaringClassOnEnumObject.kt");
}
@TestMetadata("deepInnerClassInEnumEntryClass.kt")
public void testDeepInnerClassInEnumEntryClass() throws Exception {
runTest("compiler/testData/codegen/box/enum/deepInnerClassInEnumEntryClass.kt");
@@ -12440,6 +12440,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/enum/constructorWithReordering.kt");
}
@TestMetadata("declaringClassOnEnumObject.kt")
public void testDeclaringClassOnEnumObject() throws Exception {
runTest("compiler/testData/codegen/box/enum/declaringClassOnEnumObject.kt");
}
@TestMetadata("deepInnerClassInEnumEntryClass.kt")
public void testDeepInnerClassInEnumEntryClass() throws Exception {
runTest("compiler/testData/codegen/box/enum/deepInnerClassInEnumEntryClass.kt");
@@ -11045,6 +11045,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/enum/constructorWithReordering.kt");
}
@TestMetadata("declaringClassOnEnumObject.kt")
public void testDeclaringClassOnEnumObject() throws Exception {
runTest("compiler/testData/codegen/box/enum/declaringClassOnEnumObject.kt");
}
@TestMetadata("deepInnerClassInEnumEntryClass.kt")
public void testDeepInnerClassInEnumEntryClass() throws Exception {
runTest("compiler/testData/codegen/box/enum/deepInnerClassInEnumEntryClass.kt");