diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 334e7f5f200..96c753b4faf 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index e7846695e3e..d783fc562aa 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 348a901b5d8..07a6b6be157 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -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 { diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt index 1ab7001f845..1e6f310bbcd 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt @@ -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 { diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/nonValidFirstChar.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/nonValidFirstChar.kt new file mode 100644 index 00000000000..0b16c80bd27 --- /dev/null +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/javaProperties/nonValidFirstChar.kt @@ -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.`1` + a.get1() +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 5a9e4507ef5..bc3f16ec7f8 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -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 { diff --git a/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/propertiesConventionUtil.kt b/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/propertiesConventionUtil.kt index 6d9b595634d..69e6ece6622 100644 --- a/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/propertiesConventionUtil.kt +++ b/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/propertiesConventionUtil.kt @@ -65,8 +65,15 @@ fun getPropertyNamesCandidatesByAccessorName(name: Name): List { } fun possibleGetMethodNames(propertyName: Name): List { - val result = ArrayList(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(3) if (JvmAbi.startsWithIsPrefix(identifier)) { result.add(propertyName)