From b06188180eca01ab3f8ac1d4f53ace0bf202dafc Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 18 Aug 2023 17:38:40 +0200 Subject: [PATCH] FIR2IR: don't generate 'none' type arguments for Java field references #KT-60254 Fixed --- .../fir/backend/generators/CallAndReferenceGenerator.kt | 2 +- .../box/fir/callableReferenceToJavaField.fir.ir.txt | 2 -- .../ir/irText/expressions/propertyReferences.fir.ir.txt | 2 -- .../ir/irText/expressions/propertyReferences.fir.kt.txt | 4 ++-- .../irText/expressions/protectedJavaFieldRef.fir.ir.txt | 1 - .../firProblems/SameJavaFieldReferences.fir.ir.txt | 9 --------- .../firProblems/SameJavaFieldReferences.fir.kt.txt | 4 ---- .../ir/irText/firProblems/SameJavaFieldReferences.kt | 1 + 8 files changed, 4 insertions(+), 21 deletions(-) delete mode 100644 compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.fir.ir.txt delete mode 100644 compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.fir.kt.txt diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt index 319aa615bac..b0087f63cba 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt @@ -144,7 +144,7 @@ class CallAndReferenceGenerator( IrPropertyReferenceImpl( startOffset, endOffset, type, propertySymbol, - typeArgumentsCount = (type as? IrSimpleType)?.arguments?.size ?: 0, + typeArgumentsCount = 0, field = symbol, getter = if (referencedField.isStatic) null else propertySymbol.owner.getter?.symbol, setter = if (referencedField.isStatic) null else propertySymbol.owner.setter?.symbol, diff --git a/compiler/testData/codegen/box/fir/callableReferenceToJavaField.fir.ir.txt b/compiler/testData/codegen/box/fir/callableReferenceToJavaField.fir.ir.txt index 62c76ffa321..49f81a43073 100644 --- a/compiler/testData/codegen/box/fir/callableReferenceToJavaField.fir.ir.txt +++ b/compiler/testData/codegen/box/fir/callableReferenceToJavaField.fir.ir.txt @@ -46,8 +46,6 @@ FILE fqName:foo fileName:/main.kt : java.lang.reflect.Field arg0: CALL 'public final fun (): java.lang.reflect.Field? declared in kotlin.reflect.jvm' type=java.lang.reflect.Field? origin=GET_PROPERTY $receiver: PROPERTY_REFERENCE 'protected/*protected and package*/ open a: @[FlexibleNullability] foo.A?' field='FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[FlexibleNullability] foo.A? visibility:protected/*protected and package*/' getter='protected/*protected and package*/ open fun (): @[FlexibleNullability] foo.A? declared in bar.Base' setter='protected/*protected and package*/ open fun (: @[FlexibleNullability] foo.A?): kotlin.Unit declared in bar.Base' type=kotlin.reflect.KMutableProperty1 origin=null - <1>: - <2>: p0: GET_VAR ': foo.Derived declared in foo.Derived.foo' type=foo.Derived origin=null p1: CONSTRUCTOR_CALL 'public constructor (s: kotlin.String) declared in foo.A' type=foo.A origin=null s: CONST String type=kotlin.String value="OK" diff --git a/compiler/testData/ir/irText/expressions/propertyReferences.fir.ir.txt b/compiler/testData/ir/irText/expressions/propertyReferences.fir.ir.txt index 0a7672d056e..bbdd10d8713 100644 --- a/compiler/testData/ir/irText/expressions/propertyReferences.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/propertyReferences.fir.ir.txt @@ -262,7 +262,6 @@ FILE fqName: fileName:/propertyReferences.kt FIELD PROPERTY_BACKING_FIELD name:test_J_CONST type:kotlin.reflect.KProperty0 visibility:private [final,static] EXPRESSION_BODY PROPERTY_REFERENCE 'public final CONST: kotlin.Int' field='FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:CONST type:kotlin.Int visibility:public [final,static]' getter=null setter=null type=kotlin.reflect.KProperty0 origin=null - <1>: FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.reflect.KProperty0 correspondingProperty: PROPERTY name:test_J_CONST visibility:public modality:FINAL [val] BLOCK_BODY @@ -272,7 +271,6 @@ FILE fqName: fileName:/propertyReferences.kt FIELD PROPERTY_BACKING_FIELD name:test_J_nonConst type:kotlin.reflect.KMutableProperty0 visibility:private [final,static] EXPRESSION_BODY PROPERTY_REFERENCE 'public open nonConst: kotlin.Int' field='FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:nonConst type:kotlin.Int visibility:public [static]' getter=null setter=null type=kotlin.reflect.KMutableProperty0 origin=null - <1>: FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.reflect.KMutableProperty0 correspondingProperty: PROPERTY name:test_J_nonConst visibility:public modality:FINAL [val] BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/propertyReferences.fir.kt.txt b/compiler/testData/ir/irText/expressions/propertyReferences.fir.kt.txt index 45cad43651f..c7ccf5243df 100644 --- a/compiler/testData/ir/irText/expressions/propertyReferences.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/propertyReferences.fir.kt.txt @@ -115,11 +115,11 @@ val test_constVal: KProperty0 get val test_J_CONST: KProperty0 - field = J::CONST/*()*/ + field = J::CONST get val test_J_nonConst: KMutableProperty0 - field = J::nonConst/*()*/ + field = J::nonConst get val test_varWithPrivateSet: KProperty1 diff --git a/compiler/testData/ir/irText/expressions/protectedJavaFieldRef.fir.ir.txt b/compiler/testData/ir/irText/expressions/protectedJavaFieldRef.fir.ir.txt index 675647941ba..76b91c96496 100644 --- a/compiler/testData/ir/irText/expressions/protectedJavaFieldRef.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/protectedJavaFieldRef.fir.ir.txt @@ -20,7 +20,6 @@ FILE fqName: fileName:/protectedJavaFieldRef.kt FIELD PROPERTY_BACKING_FIELD name:ref type:kotlin.reflect.KMutableProperty0<@[FlexibleNullability] kotlin.String?> visibility:private [final] EXPRESSION_BODY PROPERTY_REFERENCE 'protected/*protected and package*/ open j: @[FlexibleNullability] kotlin.String?' field='FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:j type:@[FlexibleNullability] kotlin.String? visibility:protected/*protected and package*/' getter='protected/*protected and package*/ open fun (): @[FlexibleNullability] kotlin.String? declared in p.Base' setter='protected/*protected and package*/ open fun (: @[FlexibleNullability] kotlin.String?): kotlin.Unit declared in p.Base' type=kotlin.reflect.KMutableProperty0<@[FlexibleNullability] kotlin.String?> origin=null - <1>: $this: GET_VAR ': .Derived declared in .Derived' type=.Derived origin=null FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Derived) returnType:kotlin.reflect.KMutableProperty0<@[FlexibleNullability] kotlin.String?> correspondingProperty: PROPERTY name:ref visibility:public modality:FINAL [val] diff --git a/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.fir.ir.txt b/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.fir.ir.txt deleted file mode 100644 index 8840edd1152..00000000000 --- a/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.fir.ir.txt +++ /dev/null @@ -1,9 +0,0 @@ -FILE fqName: fileName:/SameJavaFieldReferences.kt - FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit - BLOCK_BODY - VAR name:ref1 type:kotlin.reflect.KProperty0 [val] - PROPERTY_REFERENCE 'public final someJavaField: kotlin.String' field='FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:someJavaField type:kotlin.String visibility:public [final,static]' getter=null setter=null type=kotlin.reflect.KProperty0 origin=null - <1>: - VAR name:ref2 type:kotlin.reflect.KProperty0 [val] - PROPERTY_REFERENCE 'public final someJavaField: kotlin.String' field='FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:someJavaField type:kotlin.String visibility:public [final,static]' getter=null setter=null type=kotlin.reflect.KProperty0 origin=null - <1>: diff --git a/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.fir.kt.txt b/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.fir.kt.txt deleted file mode 100644 index 59a58991cce..00000000000 --- a/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.fir.kt.txt +++ /dev/null @@ -1,4 +0,0 @@ -fun foo() { - val ref1: KProperty0 = SomeJavaClass::someJavaField/*()*/ - val ref2: KProperty0 = SomeJavaClass::someJavaField/*()*/ -} diff --git a/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.kt b/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.kt index e95d005edf5..f952311e002 100644 --- a/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.kt +++ b/compiler/testData/ir/irText/firProblems/SameJavaFieldReferences.kt @@ -1,4 +1,5 @@ // TARGET_BACKEND: JVM +// FIR_IDENTICAL // FILE: SomeJavaClass.java public class SomeJavaClass {