diff --git a/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.kt b/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.kt new file mode 100644 index 00000000000..8d6f9c02b78 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.kt @@ -0,0 +1,70 @@ +/* + * There is some complex rules for conversions from java method `get...` to property + * (see `JavaSyntheticPropertiesScope`), but they are not supported in FIR + * It's possible to support them in `JavaClassUseSiteMemberScope` + * But problem is that we also have `FirSyntheticPropertiesScope` that creates + * synthetic properties for everithig + * + * Because of that such code is also resolves incorrect: + * + * class A { + * fun getX(): Int = 1 + * } + * + * fun test(a: A) { + * a.x // resolves to `getX` + * } + */ + +// FILE: A.java + +public class A { + public String getVMParameters() { + return null; + } +} + +// FILE: B.java + +public class B { + public Integer getVmParameters() { + return null; + } +} + +// FILE: C.java + +public class C { + public String getVMParameters() { + return null; + } + + public Integer getVmParameters() { + return null; + } +} + +// FILE: main.kt + +fun test_1(x: A) { + val str1 = x.vmParameters // OK + val str2 = x.vMParameters // should be error +} + +fun test_2(x: B) { + val int = x.vmParameters // OK + val error = x.vMParameters // should be error +} + +fun test_3(x: C) { + val error = x.vmParameters // should be error + val int = x.vMParameters // should be error +} + +class Foo { + fun getX(): Int = 1 +} + +fun test_4(foo: Foo) { + foo.x // should be error +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.txt b/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.txt new file mode 100644 index 00000000000..c0b9f7f41a0 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.txt @@ -0,0 +1,26 @@ +FILE: main.kt + public final fun test_1(x: R|A|): R|kotlin/Unit| { + lval str1: = R|/x|.# + lval str2: R|ft!| = R|/x|.R|/A.vMParameters| + } + public final fun test_2(x: R|B|): R|kotlin/Unit| { + lval int: R|ft!| = R|/x|.R|/B.vmParameters| + lval error: = R|/x|.# + } + public final fun test_3(x: R|C|): R|kotlin/Unit| { + lval error: R|ft!| = R|/x|.R|/C.vmParameters| + lval int: R|ft!| = R|/x|.R|/C.vMParameters| + } + public final class Foo : R|kotlin/Any| { + public constructor(): R|Foo| { + super() + } + + public final fun getX(): R|kotlin/Int| { + ^getX Int(1) + } + + } + public final fun test_4(foo: R|Foo|): R|kotlin/Unit| { + R|/foo|.R|/Foo.x| + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 358bee88e7a..fff22064ba2 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -778,6 +778,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/resolve/testData/resolve/problems"), Pattern.compile("^([^.]+)\\.kt$"), true); } + @TestMetadata("javaAccessorConversion.kt") + public void testJavaAccessorConversion() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/problems/javaAccessorConversion.kt"); + } + @TestMetadata("nestedClassContructor.kt") public void testNestedClassContructor() throws Exception { runTest("compiler/fir/resolve/testData/resolve/problems/nestedClassContructor.kt");