Skip to content

Commit

Permalink
[FIR2IR] Add static fields to the list of declarations of lazy IR jav…
Browse files Browse the repository at this point in the history
…a class

^KT-69735 Fixed
  • Loading branch information
demiurg906 authored and qodana-bot committed Sep 24, 2024
1 parent 8f121bc commit 1499254
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.dispatchReceiverClassLookupTagOrNull
import org.jetbrains.kotlin.fir.isDelegated
import org.jetbrains.kotlin.fir.lazy.Fir2IrLazyPropertyForPureField
import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.scopes.processAllFunctions
import org.jetbrains.kotlin.fir.scopes.processAllProperties
Expand Down Expand Up @@ -49,6 +50,11 @@ class Fir2IrFakeOverrideStrategy(
) : FakeOverrideBuilderStrategy.BindToPrivateSymbols(friendModules, delegatedMemberGenerationStrategy) {
private val fieldOnlyProperties: MutableList<IrPropertyWithLateBinding> = mutableListOf()

override fun fakeOverrideMember(superType: IrType, member: IrOverridableMember, clazz: IrClass): IrOverridableMember? {
if (member is Fir2IrLazyPropertyForPureField && member.backingField?.isStatic == true) return null
return super.fakeOverrideMember(superType, member, clazz)
}

override fun linkPropertyFakeOverride(property: IrPropertyWithLateBinding, manglerCompatibleMode: Boolean) {
super.linkPropertyFakeOverride(property, manglerCompatibleMode)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class Fir2IrLazyClass(
when {
!shouldBuildStub(symbol.fir) -> {}
symbol is FirFieldSymbol -> {
if (!symbol.isStatic) {
if (shouldBuildIrField(symbol)) {
// Lazy declarations are created together with their symbol, so it's safe to take the owner here
@OptIn(UnsafeDuringIrConstructionAPI::class)
result += declarationStorage.getIrSymbolForField(
Expand Down Expand Up @@ -250,6 +250,12 @@ class Fir2IrLazyClass(
}
}

private fun shouldBuildIrField(fieldSymbol: FirFieldSymbol): Boolean {
if (!fieldSymbol.isStatic) return true
// we need to create IR for static fields only if they are not fake-overrides
return fir.isJava && !fieldSymbol.fir.isFakeOverride(fir)
}

override var metadata: MetadataSource?
get() = null
set(_) = error("We should never need to store metadata of external declarations.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.ir.util.hasAnnotation
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.utils.addToStdlib.runIf

/**
* This class is a customization point for IrFakeOverrideBuilder.
Expand Down Expand Up @@ -64,11 +65,10 @@ abstract class FakeOverrideBuilderStrategy(
* Creates a fake override for [member] from [superType] to be added to the class [clazz] or returns null,
* if no fake override should be created for this member
*/
fun fakeOverrideMember(superType: IrType, member: IrOverridableMember, clazz: IrClass): IrOverridableMember? {
return if (isVisibleForOverrideInClass(member, clazz))
open fun fakeOverrideMember(superType: IrType, member: IrOverridableMember, clazz: IrClass): IrOverridableMember? {
return runIf(isVisibleForOverrideInClass(member, clazz)) {
buildFakeOverrideMember(superType, member, clazz, unimplementedOverridesStrategy)
else
null
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ CLASS IR_EXTERNAL_JAVA_DECLARATION_STUB CLASS name:J modality:OPEN visibility:pu
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:f type:kotlin.Int visibility:public
PROPERTY IR_EXTERNAL_JAVA_DECLARATION_STUB name:f2 visibility:public modality:FINAL [var]
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:f2 type:kotlin.Int visibility:public
PROPERTY IR_EXTERNAL_JAVA_DECLARATION_STUB name:s visibility:public modality:FINAL [var]
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:s type:kotlin.Int visibility:public [static]
PROPERTY IR_EXTERNAL_JAVA_DECLARATION_STUB name:s2 visibility:public modality:FINAL [var]
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:s2 type:kotlin.Int visibility:public [static]
CONSTRUCTOR IR_EXTERNAL_JAVA_DECLARATION_STUB visibility:public <> () returnType:<root>.J [primary]
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ CLASS IR_EXTERNAL_JAVA_DECLARATION_STUB CLASS name:J1 modality:OPEN visibility:p
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:f type:@[FlexibleNullability] T of <root>.J1? visibility:public
PROPERTY IR_EXTERNAL_JAVA_DECLARATION_STUB name:f2 visibility:public modality:FINAL [var]
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:f2 type:@[FlexibleNullability] T of <root>.J1? visibility:public
PROPERTY IR_EXTERNAL_JAVA_DECLARATION_STUB name:s visibility:public modality:FINAL [var]
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:s type:@[FlexibleNullability] T of <root>.J1? visibility:public [static]
PROPERTY IR_EXTERNAL_JAVA_DECLARATION_STUB name:s2 visibility:public modality:FINAL [var]
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:s2 type:@[FlexibleNullability] T of <root>.J1? visibility:public [static]
CONSTRUCTOR IR_EXTERNAL_JAVA_DECLARATION_STUB visibility:public <> () returnType:<root>.J1<T of <root>.J1> [primary]
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ CLASS IR_EXTERNAL_JAVA_DECLARATION_STUB CLASS name:X modality:OPEN visibility:pu
overridden:
public final f: kotlin.Int [var] declared in <root>.J
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:f type:kotlin.Int visibility:public
PROPERTY IR_EXTERNAL_JAVA_DECLARATION_STUB name:s2 visibility:public modality:FINAL [var]
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:s2 type:kotlin.Int visibility:public [static]
CONSTRUCTOR IR_EXTERNAL_JAVA_DECLARATION_STUB visibility:public <> () returnType:<root>.X [primary]
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ CLASS IR_EXTERNAL_JAVA_DECLARATION_STUB CLASS name:X1 modality:OPEN visibility:p
overridden:
public final f: @[FlexibleNullability] T of <root>.J1? [var] declared in <root>.J1
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:f type:@[FlexibleNullability] kotlin.String? visibility:public
PROPERTY IR_EXTERNAL_JAVA_DECLARATION_STUB name:s2 visibility:public modality:FINAL [var]
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:s2 type:@[FlexibleNullability] kotlin.String? visibility:public [static]
CONSTRUCTOR IR_EXTERNAL_JAVA_DECLARATION_STUB visibility:public/*package*/ <> () returnType:<root>.X1<T of <root>.X1> [primary]
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
Expand Down

0 comments on commit 1499254

Please sign in to comment.