diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteScope.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteScope.kt index 567336fa311..9fc059655d7 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteScope.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteScope.kt @@ -32,7 +32,7 @@ import org.jetbrains.kotlin.name.Name class JavaClassUseSiteScope( klass: FirRegularClass, session: FirSession, - internal val superTypesScope: FirScope, + private val superTypesScope: FirScope, private val declaredMemberScope: FirScope ) : FirAbstractProviderBasedScope(session, lookupInFir = true) { internal val symbol = klass.symbol @@ -169,10 +169,27 @@ class JavaClassUseSiteScope( private fun processAccessorFunctionsByName( propertyName: Name, accessorName: Name, + isGetter: Boolean, processor: (ConePropertySymbol) -> ProcessorAction ): ProcessorAction { val overrideCandidates = mutableSetOf() if (!declaredMemberScope.processFunctionsByName(accessorName) { functionSymbol -> + if (functionSymbol is FirFunctionSymbol) { + val fir = functionSymbol.fir + if (fir is FirNamedFunction) { + if (fir.isStatic) { + return@processFunctionsByName ProcessorAction.NEXT + } + when (isGetter) { + true -> if (fir.valueParameters.isNotEmpty()) { + return@processFunctionsByName ProcessorAction.NEXT + } + false -> if (fir.valueParameters.size != 1) { + return@processFunctionsByName ProcessorAction.NEXT + } + } + } + } overrideCandidates += functionSymbol val accessorSymbol = FirAccessorSymbol( accessorId = functionSymbol.callableId, @@ -207,7 +224,7 @@ class JavaClassUseSiteScope( ) return ProcessorAction.STOP val getterName = Name.identifier(getterPrefix + name.asString().capitalize()) - return processAccessorFunctionsByName(name, getterName, processor) + return processAccessorFunctionsByName(name, getterName, isGetter = true, processor = processor) } companion object { diff --git a/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.fir.txt b/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.fir.txt index 141a6588102..2a49176f42a 100644 --- a/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.fir.txt +++ b/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.fir.txt @@ -3,7 +3,7 @@ FILE fqName: fileName:/Derived.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Derived CONSTRUCTOR visibility:public <> () returnType:.Derived [primary] BLOCK_BODY - ERROR_CALL 'Cannot find delegated constructor call' type=.Derived + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in .Base' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[.Base]' ANONYMOUS_INITIALIZER isStatic=false BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/kt16904.fir.txt b/compiler/testData/ir/irText/expressions/kt16904.fir.txt index ca54d632b18..0f72412e9e1 100644 --- a/compiler/testData/ir/irText/expressions/kt16904.fir.txt +++ b/compiler/testData/ir/irText/expressions/kt16904.fir.txt @@ -98,7 +98,7 @@ FILE fqName: fileName:/kt16904.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Test2 CONSTRUCTOR visibility:public <> () returnType:.Test2 [primary] BLOCK_BODY - ERROR_CALL 'Cannot find delegated constructor call' type=.Test2 + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in .J' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test2 modality:FINAL visibility:public superTypes:[.J]' ANONYMOUS_INITIALIZER isStatic=false BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.txt b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.txt index 1ba0c2cdde2..f00bb8a846d 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.txt @@ -15,7 +15,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt BRANCH if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=java.lang.Runnable GET_VAR 'a: kotlin.Function0 declared in .test2' type=kotlin.Function0 origin=null - then: ERROR_CALL 'Unresolved reference: #' type=IrErrorType + then: ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'a: kotlin.Function0 declared in .test2' type=kotlin.Function0 origin=null FUN name:test3 visibility:public modality:FINAL <> (a:kotlin.Function0) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Function0 @@ -24,7 +24,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt BRANCH if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=java.lang.Runnable GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null - then: ERROR_CALL 'Unresolved reference: #' type=IrErrorType + then: ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null FUN name:test4 visibility:public modality:FINAL <> (a:kotlin.Function0, b:kotlin.Function0) returnType:kotlin.Unit @@ -35,7 +35,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt BRANCH if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=java.lang.Runnable GET_VAR 'a: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null - then: ERROR_CALL 'Unresolved reference: #' type=IrErrorType + then: ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'a: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null GET_VAR 'b: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit @@ -45,7 +45,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt BRANCH if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=java.lang.Runnable GET_VAR 'a: kotlin.Any declared in .test5' type=kotlin.Any origin=null - then: ERROR_CALL 'Unresolved reference: #' type=IrErrorType + then: ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'a: kotlin.Any declared in .test5' type=kotlin.Any origin=null FUN name:test5x visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Any @@ -57,30 +57,31 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt then: BLOCK type=IrErrorType origin=null TYPE_OP type=kotlin.Function0 origin=CAST typeOperand=kotlin.Function0 GET_VAR 'a: kotlin.Any declared in .test5x' type=kotlin.Any origin=null - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'a: kotlin.Any declared in .test5x' type=kotlin.Any origin=null FUN name:test6 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Any BLOCK_BODY TYPE_OP type=kotlin.Function0 origin=CAST typeOperand=kotlin.Function0 GET_VAR 'a: kotlin.Any declared in .test6' type=kotlin.Any origin=null - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'a: kotlin.Any declared in .test6' type=kotlin.Any origin=null FUN name:test7 visibility:public modality:FINAL <> (a:kotlin.Function1) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Function1 BLOCK_BODY TYPE_OP type=kotlin.Function0 origin=CAST typeOperand=kotlin.Function0 GET_VAR 'a: kotlin.Function1 declared in .test7' type=kotlin.Function1 origin=null - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'a: kotlin.Function1 declared in .test7' type=kotlin.Function1 origin=null FUN name:test8 visibility:public modality:FINAL <> (a:kotlin.Function0) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Function0 BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - CALL 'public open fun id (x: T of ?): T of ? declared in .J' type=IrErrorType origin=null + CALL 'public open fun run1 (r: java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null + $this: CONSTRUCTOR_CALL 'public constructor () declared in .J' type=.J origin=null + r: CALL 'public open fun id (x: T of ?): T of ? declared in .J' type=IrErrorType origin=null x: GET_VAR 'a: kotlin.Function0 declared in .test8' type=kotlin.Function0 origin=null FUN name:test9 visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - + CALL 'public open fun run1 (r: java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null + $this: CONSTRUCTOR_CALL 'public constructor () declared in .J' type=.J origin=null + r: ERROR_CALL 'Unresolved reference: #' type=IrErrorType diff --git a/compiler/testData/ir/irText/expressions/setFieldWithImplicitCast.fir.txt b/compiler/testData/ir/irText/expressions/setFieldWithImplicitCast.fir.txt index 04f9900228a..f8b70b28047 100644 --- a/compiler/testData/ir/irText/expressions/setFieldWithImplicitCast.fir.txt +++ b/compiler/testData/ir/irText/expressions/setFieldWithImplicitCast.fir.txt @@ -3,7 +3,7 @@ FILE fqName: fileName:/Derived.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Derived CONSTRUCTOR visibility:public <> () returnType:.Derived [primary] BLOCK_BODY - ERROR_CALL 'Cannot find delegated constructor call' type=.Derived + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in .Base' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[.Base]' FUN name:setValue visibility:public modality:FINAL <> ($this:.Derived, v:kotlin.Any) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.Derived diff --git a/compiler/testData/ir/irText/stubs/javaInnerClass.fir.txt b/compiler/testData/ir/irText/stubs/javaInnerClass.fir.txt index ac6042ffc91..38d8bbfe460 100644 --- a/compiler/testData/ir/irText/stubs/javaInnerClass.fir.txt +++ b/compiler/testData/ir/irText/stubs/javaInnerClass.fir.txt @@ -3,7 +3,7 @@ FILE fqName: fileName:/javaInnerClass.kt $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Test1 CONSTRUCTOR visibility:public <> () returnType:.Test1 [primary] BLOCK_BODY - ERROR_CALL 'Cannot find delegated constructor call' type=.Test1 + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in .J' INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test1 modality:FINAL visibility:public superTypes:[.J]' PROPERTY name:test visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:test type:IrErrorType visibility:public [final] diff --git a/compiler/testData/ir/irText/stubs/javaSyntheticProperty.fir.txt b/compiler/testData/ir/irText/stubs/javaSyntheticProperty.fir.txt index 25ba98d28d0..3988df6c6b6 100644 --- a/compiler/testData/ir/irText/stubs/javaSyntheticProperty.fir.txt +++ b/compiler/testData/ir/irText/stubs/javaSyntheticProperty.fir.txt @@ -1,11 +1,10 @@ FILE fqName: fileName:/javaSyntheticProperty.kt PROPERTY name:test visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:test type:IrErrorType visibility:public [final,static] + FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String? visibility:public [final,static] EXPRESSION_BODY - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType + ERROR_CALL 'Unresolved reference: R|/J.foo|' type=kotlin.String? + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.String? correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val] BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType declared in ' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:IrErrorType visibility:public [final,static] ' type=IrErrorType origin=null - + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String? declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String? visibility:public [final,static] ' type=kotlin.String? origin=null diff --git a/idea/testData/fir/multiModule/javaGetPrefixConflict/extraDump.java.txt b/idea/testData/fir/multiModule/javaGetPrefixConflict/extraDump.java.txt new file mode 100644 index 00000000000..9a8f201d2da --- /dev/null +++ b/idea/testData/fir/multiModule/javaGetPrefixConflict/extraDump.java.txt @@ -0,0 +1,6 @@ +public open class JavaClass : R|kotlin/Any| { + public open operator fun getText(): R|ft|! + + public open operator fun getText(param: R|ft|!): R|ft|! + +} diff --git a/idea/testData/fir/multiModule/javaGetPrefixConflict/jvm/JavaClass.java b/idea/testData/fir/multiModule/javaGetPrefixConflict/jvm/JavaClass.java new file mode 100644 index 00000000000..1b96a540891 --- /dev/null +++ b/idea/testData/fir/multiModule/javaGetPrefixConflict/jvm/JavaClass.java @@ -0,0 +1,9 @@ +public class JavaClass { + public String getText() { + return "Text"; + } + + public String getText(String param) { + return "Text with " + param; + } +} \ No newline at end of file diff --git a/idea/testData/fir/multiModule/javaGetPrefixConflict/jvm/Test.kt b/idea/testData/fir/multiModule/javaGetPrefixConflict/jvm/Test.kt new file mode 100644 index 00000000000..c5a1de538c6 --- /dev/null +++ b/idea/testData/fir/multiModule/javaGetPrefixConflict/jvm/Test.kt @@ -0,0 +1,8 @@ +fun test() { + val jc = JavaClass() + val result = jc.text +} + +fun otherTest(jc: JavaClass) { + val result = jc.text +} \ No newline at end of file diff --git a/idea/testData/fir/multiModule/javaGetPrefixConflict/jvm/Test.txt b/idea/testData/fir/multiModule/javaGetPrefixConflict/jvm/Test.txt new file mode 100644 index 00000000000..2ee624b14c0 --- /dev/null +++ b/idea/testData/fir/multiModule/javaGetPrefixConflict/jvm/Test.txt @@ -0,0 +1,8 @@ +FILE: Test.kt + public final fun test(): R|kotlin/Unit| { + lval jc: = #() + lval result: = R|/jc|.# + } + public final fun otherTest(jc: R|JavaClass|): R|kotlin/Unit| { + lval result: R|ft|! = R|/jc|.R|/JavaClass.text| + } diff --git a/idea/tests/org/jetbrains/kotlin/idea/fir/FirMultiModuleResolveTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/fir/FirMultiModuleResolveTestGenerated.java index b0b21341066..a704dfc56a1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/fir/FirMultiModuleResolveTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/fir/FirMultiModuleResolveTestGenerated.java @@ -64,6 +64,11 @@ public class FirMultiModuleResolveTestGenerated extends AbstractFirMultiModuleRe runTest("idea/testData/fir/multiModule/fullWithJavaPredefinedSignature/"); } + @TestMetadata("javaGetPrefixConflict") + public void testJavaGetPrefixConflict() throws Exception { + runTest("idea/testData/fir/multiModule/javaGetPrefixConflict/"); + } + @TestMetadata("javaInheritsKotlinExtension") public void testJavaInheritsKotlinExtension() throws Exception { runTest("idea/testData/fir/multiModule/javaInheritsKotlinExtension/");