FIR: Do not create incorrect synthetic property

This commit is contained in:
Denis.Zharkov
2021-10-26 11:42:00 +03:00
parent 52c2908bb7
commit 0bdea4f20a
7 changed files with 48 additions and 9 deletions
@@ -29880,6 +29880,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/nonAsciiSecondChar.kt");
}
@Test
@TestMetadata("nonValidFirstChar.kt")
public void testNonValidFirstChar() throws Exception {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/nonValidFirstChar.kt");
}
@Test
@TestMetadata("OnlyAscii.kt")
public void testOnlyAscii() throws Exception {
@@ -29880,6 +29880,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/nonAsciiSecondChar.kt");
}
@Test
@TestMetadata("nonValidFirstChar.kt")
public void testNonValidFirstChar() throws Exception {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/nonValidFirstChar.kt");
}
@Test
@TestMetadata("OnlyAscii.kt")
public void testOnlyAscii() throws Exception {
@@ -29880,6 +29880,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/nonAsciiSecondChar.kt");
}
@Test
@TestMetadata("nonValidFirstChar.kt")
public void testNonValidFirstChar() throws Exception {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/nonValidFirstChar.kt");
}
@Test
@TestMetadata("OnlyAscii.kt")
public void testOnlyAscii() throws Exception {
@@ -146,17 +146,11 @@ class JavaSyntheticPropertiesScope(
name: Name,
ownerClass: ClassDescriptor
): SyntheticPropertyHolder {
if (name.isSpecial) return SyntheticPropertyHolder.EMPTY
val identifier = name.identifier
if (identifier.isEmpty()) return SyntheticPropertyHolder.EMPTY
val firstChar = identifier[0]
if (!firstChar.isJavaIdentifierStart() || firstChar in 'A'..'Z') return SyntheticPropertyHolder.EMPTY
val possibleGetMethodNames = possibleGetMethodNames(name)
if (possibleGetMethodNames.isEmpty()) return SyntheticPropertyHolder.EMPTY
val memberScope = ownerClass.unsubstitutedMemberScope
val possibleGetMethodNames = possibleGetMethodNames(name)
val getMethod = possibleGetMethodNames
.flatMap { memberScope.getContributedFunctions(it, NoLookupLocation.FROM_SYNTHETIC_SCOPE) }
.singleOrNull {
@@ -0,0 +1,14 @@
// FIR_IDENTICAL
// SKIP_TXT
// FILE: A.java
public class A {
public String get1() {
return "";
}
}
// FILE: main.kt
fun foo(a: A) {
a.<!UNRESOLVED_REFERENCE!>`1`<!>
a.get1()
}
@@ -29976,6 +29976,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/nonAsciiSecondChar.kt");
}
@Test
@TestMetadata("nonValidFirstChar.kt")
public void testNonValidFirstChar() throws Exception {
runTest("compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/nonValidFirstChar.kt");
}
@Test
@TestMetadata("OnlyAscii.kt")
public void testOnlyAscii() throws Exception {
@@ -65,8 +65,15 @@ fun getPropertyNamesCandidatesByAccessorName(name: Name): List<Name> {
}
fun possibleGetMethodNames(propertyName: Name): List<Name> {
val result = ArrayList<Name>(3)
if (propertyName.isSpecial) return emptyList()
val identifier = propertyName.identifier
if (identifier.isEmpty()) return emptyList()
val firstChar = identifier[0]
if (!firstChar.isJavaIdentifierStart() || firstChar in 'A'..'Z') return emptyList()
val result = ArrayList<Name>(3)
if (JvmAbi.startsWithIsPrefix(identifier)) {
result.add(propertyName)