FIR resolve: check number of parameters when handling Java accessors

This commit is contained in:
Mikhail Glukhikh
2019-05-24 11:08:35 +03:00
parent eaf7e46da3
commit d0404b2c2a
12 changed files with 77 additions and 24 deletions
@@ -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<ConeFunctionSymbol>()
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 {
@@ -3,7 +3,7 @@ FILE fqName:<root> fileName:/Derived.kt
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Derived
CONSTRUCTOR visibility:public <> () returnType:<root>.Derived [primary]
BLOCK_BODY
ERROR_CALL 'Cannot find delegated constructor call' type=<root>.Derived
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.Base'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.Base]'
ANONYMOUS_INITIALIZER isStatic=false
BLOCK_BODY
+1 -1
View File
@@ -98,7 +98,7 @@ FILE fqName:<root> fileName:/kt16904.kt
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test2
CONSTRUCTOR visibility:public <> () returnType:<root>.Test2 [primary]
BLOCK_BODY
ERROR_CALL 'Cannot find delegated constructor call' type=<root>.Test2
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test2 modality:FINAL visibility:public superTypes:[<root>.J]'
ANONYMOUS_INITIALIZER isStatic=false
BLOCK_BODY
@@ -15,7 +15,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=java.lang.Runnable
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test2' type=kotlin.Function0<kotlin.Unit> origin=null
then: ERROR_CALL 'Unresolved reference: <Unresolved name: run1>#' type=IrErrorType
then: ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/J.run1]>#' type=IrErrorType
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test2' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:test3 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
@@ -24,7 +24,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=java.lang.Runnable
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
then: ERROR_CALL 'Unresolved reference: <Unresolved name: run2>#' type=IrErrorType
then: ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/J.run2]>#' type=IrErrorType
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:test4 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>, b:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
@@ -35,7 +35,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=java.lang.Runnable
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
then: ERROR_CALL 'Unresolved reference: <Unresolved name: run2>#' type=IrErrorType
then: ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/J.run2]>#' type=IrErrorType
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
GET_VAR 'b: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
@@ -45,7 +45,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=java.lang.Runnable
GET_VAR 'a: kotlin.Any declared in <root>.test5' type=kotlin.Any origin=null
then: ERROR_CALL 'Unresolved reference: <Unresolved name: run1>#' type=IrErrorType
then: ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/J.run1]>#' type=IrErrorType
GET_VAR 'a: kotlin.Any declared in <root>.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:<root> fileName:/samConversionsWithSmartCasts.kt
then: BLOCK type=IrErrorType origin=null
TYPE_OP type=kotlin.Function0<kotlin.Unit> origin=CAST typeOperand=kotlin.Function0<kotlin.Unit>
GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any origin=null
ERROR_CALL 'Unresolved reference: <Unresolved name: run1>#' type=IrErrorType
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/J.run1]>#' type=IrErrorType
GET_VAR 'a: kotlin.Any declared in <root>.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<kotlin.Unit> origin=CAST typeOperand=kotlin.Function0<kotlin.Unit>
GET_VAR 'a: kotlin.Any declared in <root>.test6' type=kotlin.Any origin=null
ERROR_CALL 'Unresolved reference: <Unresolved name: run1>#' type=IrErrorType
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/J.run1]>#' type=IrErrorType
GET_VAR 'a: kotlin.Any declared in <root>.test6' type=kotlin.Any origin=null
FUN name:test7 visibility:public modality:FINAL <> (a:kotlin.Function1<kotlin.Int, kotlin.Int>) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Function1<kotlin.Int, kotlin.Int>
BLOCK_BODY
TYPE_OP type=kotlin.Function0<kotlin.Unit> origin=CAST typeOperand=kotlin.Function0<kotlin.Unit>
GET_VAR 'a: kotlin.Function1<kotlin.Int, kotlin.Int> declared in <root>.test7' type=kotlin.Function1<kotlin.Int, kotlin.Int> origin=null
ERROR_CALL 'Unresolved reference: <Unresolved name: run1>#' type=IrErrorType
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/J.run1]>#' type=IrErrorType
GET_VAR 'a: kotlin.Function1<kotlin.Int, kotlin.Int> declared in <root>.test7' type=kotlin.Function1<kotlin.Int, kotlin.Int> origin=null
FUN name:test8 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
BLOCK_BODY
ERROR_CALL 'Unresolved reference: <Unresolved name: run1>#' type=IrErrorType
CALL 'public open fun id (x: T of <uninitialized parent>?): T of <uninitialized parent>? declared in <root>.J' type=IrErrorType origin=null
CALL 'public open fun run1 (r: java.lang.Runnable?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J' type=<root>.J origin=null
r: CALL 'public open fun id (x: T of <uninitialized parent>?): T of <uninitialized parent>? declared in <root>.J' type=IrErrorType origin=null
x: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test8' type=kotlin.Function0<kotlin.Unit> origin=null
FUN name:test9 visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
ERROR_CALL 'Unresolved reference: <Unresolved name: run1>#' type=IrErrorType
ERROR_CALL 'Unresolved reference: <Unresolved name: test9>#' type=IrErrorType
CALL 'public open fun run1 (r: java.lang.Runnable?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J' type=<root>.J origin=null
r: ERROR_CALL 'Unresolved reference: <Unresolved name: test9>#' type=IrErrorType
@@ -3,7 +3,7 @@ FILE fqName:<root> fileName:/Derived.kt
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Derived
CONSTRUCTOR visibility:public <> () returnType:<root>.Derived [primary]
BLOCK_BODY
ERROR_CALL 'Cannot find delegated constructor call' type=<root>.Derived
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.Base'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.Base]'
FUN name:setValue visibility:public modality:FINAL <> ($this:<root>.Derived, v:kotlin.Any) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
+1 -1
View File
@@ -3,7 +3,7 @@ FILE fqName:<root> fileName:/javaInnerClass.kt
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test1
CONSTRUCTOR visibility:public <> () returnType:<root>.Test1 [primary]
BLOCK_BODY
ERROR_CALL 'Cannot find delegated constructor call' type=<root>.Test1
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test1 modality:FINAL visibility:public superTypes:[<root>.J]'
PROPERTY name:test visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:test type:IrErrorType visibility:public [final]
@@ -1,11 +1,10 @@
FILE fqName:<root> 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: <Unresolved name: foo>#' type=IrErrorType
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:IrErrorType
ERROR_CALL 'Unresolved reference: R|/J.foo|' type=kotlin.String?
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> 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 <get-test> (): IrErrorType declared in <root>'
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 <get-test> (): kotlin.String? declared in <root>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String? visibility:public [final,static] ' type=kotlin.String? origin=null
@@ -0,0 +1,6 @@
public open class JavaClass : R|kotlin/Any| {
public open operator fun getText(): R|ft<kotlin/String, kotlin/String?>|!
public open operator fun getText(param: R|ft<kotlin/String, kotlin/String?>|!): R|ft<kotlin/String, kotlin/String?>|!
}
@@ -0,0 +1,9 @@
public class JavaClass {
public String getText() {
return "Text";
}
public String getText(String param) {
return "Text with " + param;
}
}
@@ -0,0 +1,8 @@
fun test() {
val jc = JavaClass()
val result = jc.text
}
fun otherTest(jc: JavaClass) {
val result = jc.text
}
@@ -0,0 +1,8 @@
FILE: Test.kt
public final fun test(): R|kotlin/Unit| {
lval jc: <ERROR TYPE REF: Unresolved name: JavaClass> = <Unresolved name: JavaClass>#()
lval result: <ERROR TYPE REF: Unresolved name: text> = R|<local>/jc|.<Unresolved name: text>#
}
public final fun otherTest(jc: R|JavaClass|): R|kotlin/Unit| {
lval result: R|ft<kotlin/String, kotlin/String?>|! = R|<local>/jc|.R|/JavaClass.text|
}
@@ -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/");