FIR2IR: don't generate 'none' type arguments for Java field references

#KT-60254 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-08-18 17:38:40 +02:00
committed by Space Team
parent 9846ec23df
commit b06188180e
8 changed files with 4 additions and 21 deletions
@@ -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,
@@ -46,8 +46,6 @@ FILE fqName:foo fileName:/main.kt
<T0>: java.lang.reflect.Field
arg0: CALL 'public final fun <get-javaField> (): 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 <get-a> (): @[FlexibleNullability] foo.A? declared in bar.Base' setter='protected/*protected and package*/ open fun <set-a> (<set-?>: @[FlexibleNullability] foo.A?): kotlin.Unit declared in bar.Base' type=kotlin.reflect.KMutableProperty1<foo.Derived, @[FlexibleNullability] foo.A?> origin=null
<1>: <none>
<2>: <none>
p0: GET_VAR '<this>: foo.Derived declared in foo.Derived.foo' type=foo.Derived origin=null
p1: CONSTRUCTOR_CALL 'public constructor <init> (s: kotlin.String) declared in foo.A' type=foo.A origin=null
s: CONST String type=kotlin.String value="OK"
@@ -262,7 +262,6 @@ FILE fqName:<root> fileName:/propertyReferences.kt
FIELD PROPERTY_BACKING_FIELD name:test_J_CONST type:kotlin.reflect.KProperty0<kotlin.Int> 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<kotlin.Int> origin=null
<1>: <none>
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test_J_CONST> visibility:public modality:FINAL <> () returnType:kotlin.reflect.KProperty0<kotlin.Int>
correspondingProperty: PROPERTY name:test_J_CONST visibility:public modality:FINAL [val]
BLOCK_BODY
@@ -272,7 +271,6 @@ FILE fqName:<root> fileName:/propertyReferences.kt
FIELD PROPERTY_BACKING_FIELD name:test_J_nonConst type:kotlin.reflect.KMutableProperty0<kotlin.Int> 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<kotlin.Int> origin=null
<1>: <none>
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test_J_nonConst> visibility:public modality:FINAL <> () returnType:kotlin.reflect.KMutableProperty0<kotlin.Int>
correspondingProperty: PROPERTY name:test_J_nonConst visibility:public modality:FINAL [val]
BLOCK_BODY
@@ -115,11 +115,11 @@ val test_constVal: KProperty0<Int>
get
val test_J_CONST: KProperty0<Int>
field = J::CONST/*</* null */>()*/
field = J::CONST
get
val test_J_nonConst: KMutableProperty0<Int>
field = J::nonConst/*</* null */>()*/
field = J::nonConst
get
val test_varWithPrivateSet: KProperty1<C, Int>
@@ -20,7 +20,6 @@ FILE fqName:<root> 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 <get-j> (): @[FlexibleNullability] kotlin.String? declared in p.Base' setter='protected/*protected and package*/ open fun <set-j> (<set-?>: @[FlexibleNullability] kotlin.String?): kotlin.Unit declared in p.Base' type=kotlin.reflect.KMutableProperty0<@[FlexibleNullability] kotlin.String?> origin=null
<1>: <none>
$this: GET_VAR '<this>: <root>.Derived declared in <root>.Derived' type=<root>.Derived origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-ref> visibility:public modality:FINAL <> ($this:<root>.Derived) returnType:kotlin.reflect.KMutableProperty0<@[FlexibleNullability] kotlin.String?>
correspondingProperty: PROPERTY name:ref visibility:public modality:FINAL [val]
@@ -1,9 +0,0 @@
FILE fqName:<root> fileName:/SameJavaFieldReferences.kt
FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
VAR name:ref1 type:kotlin.reflect.KProperty0<kotlin.String> [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<kotlin.String> origin=null
<1>: <none>
VAR name:ref2 type:kotlin.reflect.KProperty0<kotlin.String> [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<kotlin.String> origin=null
<1>: <none>
@@ -1,4 +0,0 @@
fun foo() {
val ref1: KProperty0<String> = SomeJavaClass::someJavaField/*</* null */>()*/
val ref2: KProperty0<String> = SomeJavaClass::someJavaField/*</* null */>()*/
}
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// FIR_IDENTICAL
// FILE: SomeJavaClass.java
public class SomeJavaClass {