Skip to content

Commit

Permalink
[FIR] Remove incorrect fast-path from @PublishedAPI computation for b…
Browse files Browse the repository at this point in the history
…inary declarations

Published API effective visibility depends not only on `@PublishedAPI`
annotation on the declaration, but also on this annotation on the parent
declaration, so it's illegal to just skip all not annotated declarations

^KT-74040 Fixed
  • Loading branch information
demiurg906 authored and Space Team committed Jan 15, 2025
1 parent 435080b commit 5f5af38
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ FIR source kind: KtRealSourceElementKind

FIR element rendered:
@R|kotlin/PublishedApi|() internal final [ResolvedTo(BODY_RESOLVE)] [LazyPublishedApiEffectiveVisibilityKey=public] class Foo : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=Foo] constructor(): R|Foo|
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=Foo, LazyPublishedApiEffectiveVisibilityKey=public] constructor(): R|Foo|

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fun computePublishedApiEffectiveVisibility(
)
}

fun computePublishedApiEffectiveVisibility(
private fun computePublishedApiEffectiveVisibility(
hasPublishedApiAnnotation: Boolean,
visibility: Visibility,
selfEffectiveVisibility: EffectiveVisibility,
Expand Down Expand Up @@ -112,8 +112,6 @@ fun FirMemberDeclaration.setLazyPublishedVisibility(annotations: List<FirAnnotat
}

fun FirMemberDeclaration.setLazyPublishedVisibility(hasPublishedApi: Boolean, parentProperty: FirProperty?, session: FirSession) {
if (!hasPublishedApi) return

lazyPublishedApiEffectiveVisibility = lazy {
val containingClassLookupTag = (when {
parentProperty != null -> parentProperty.symbol.callableId.classId
Expand All @@ -125,9 +123,9 @@ fun FirMemberDeclaration.setLazyPublishedVisibility(hasPublishedApi: Boolean, pa
val status = status as FirResolvedDeclarationStatus
val parentSymbol = containingClassLookupTag?.toSymbol(session)
computePublishedApiEffectiveVisibility(
hasPublishedApiAnnotation = true,
hasPublishedApiAnnotation = hasPublishedApi,
visibility = status.visibility,
selfEffectiveVisibility = status.effectiveVisibility,
selfEffectiveVisibility = status.visibility.toEffectiveVisibility(parentSymbol, forClass = this is FirClass),
containingClassLookupTag = containingClassLookupTag,
parentEffectiveVisibility = parentProperty?.effectiveVisibility ?: parentSymbol?.effectiveVisibility
?: EffectiveVisibility.Public,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false] cla
@R|kotlin/PublishedApi|() internal [ContainingClassKey=Internal, LazyPublishedApiEffectiveVisibilityKey=internal] constructor(foo: R|kotlin/String|): R|test/Internal|

@R|kotlin/PublishedApi|() internal final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false, LazyPublishedApiEffectiveVisibilityKey=internal] class Nested : R|kotlin/Any| {
public [ContainingClassKey=Nested] constructor(): R|test/Internal.Nested|
public [ContainingClassKey=Nested, LazyPublishedApiEffectiveVisibilityKey=internal] constructor(): R|test/Internal.Nested|

}

Expand All @@ -58,7 +58,7 @@ public final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false] class
@R|kotlin/PublishedApi|() internal [ContainingClassKey=Public, LazyPublishedApiEffectiveVisibilityKey=public] constructor(foo: R|kotlin/String|): R|test/Public|

@R|kotlin/PublishedApi|() internal final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false, LazyPublishedApiEffectiveVisibilityKey=public] class Nested : R|kotlin/Any| {
public [ContainingClassKey=Nested] constructor(): R|test/Public.Nested|
public [ContainingClassKey=Nested, LazyPublishedApiEffectiveVisibilityKey=public] constructor(): R|test/Public.Nested|

}

Expand All @@ -67,8 +67,8 @@ public final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false] class
@R|kotlin/PublishedApi|() internal final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false, LazyPublishedApiEffectiveVisibilityKey=public] class Published : R|kotlin/Any| {
@R|kotlin/PublishedApi|() internal final [LazyPublishedApiEffectiveVisibilityKey=public] fun method(): R|kotlin/Unit|

public final val foo: R|kotlin/String|
public [ContainingClassKey=Published] get(): R|kotlin/String|
public final [LazyPublishedApiEffectiveVisibilityKey=public] val foo: R|kotlin/String|
public [ContainingClassKey=Published, LazyPublishedApiEffectiveVisibilityKey=public] get(): R|kotlin/String|

@PROPERTY:R|kotlin/PublishedApi|() internal final [LazyPublishedApiEffectiveVisibilityKey=public] val prop: R|kotlin/Int|
internal [ContainingClassKey=Published, LazyPublishedApiEffectiveVisibilityKey=public] get(): R|kotlin/Int|
Expand All @@ -85,7 +85,7 @@ public final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false] class
@R|kotlin/PublishedApi|() internal [ContainingClassKey=Published, LazyPublishedApiEffectiveVisibilityKey=public] constructor(foo: R|kotlin/String|): R|test/Published|

@R|kotlin/PublishedApi|() internal final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false, LazyPublishedApiEffectiveVisibilityKey=public] class Nested : R|kotlin/Any| {
public [ContainingClassKey=Nested] constructor(): R|test/Published.Nested|
public [ContainingClassKey=Nested, LazyPublishedApiEffectiveVisibilityKey=public] constructor(): R|test/Published.Nested|

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false] cla
@R|kotlin/PublishedApi|() internal [ContainingClassKey=Internal, LazyPublishedApiEffectiveVisibilityKey=internal] constructor(): R|test/Internal|

@R|kotlin/PublishedApi|() internal final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false, LazyPublishedApiEffectiveVisibilityKey=internal] class Nested : R|kotlin/Any| {
public [ContainingClassKey=Nested] constructor(): R|test/Internal.Nested|
public [ContainingClassKey=Nested, LazyPublishedApiEffectiveVisibilityKey=internal] constructor(): R|test/Internal.Nested|

}

Expand All @@ -58,7 +58,7 @@ public final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false] class
@R|kotlin/PublishedApi|() internal [ContainingClassKey=Public, LazyPublishedApiEffectiveVisibilityKey=public] constructor(): R|test/Public|

@R|kotlin/PublishedApi|() internal final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false, LazyPublishedApiEffectiveVisibilityKey=public] class Nested : R|kotlin/Any| {
public [ContainingClassKey=Nested] constructor(): R|test/Public.Nested|
public [ContainingClassKey=Nested, LazyPublishedApiEffectiveVisibilityKey=public] constructor(): R|test/Public.Nested|

}

Expand All @@ -67,8 +67,8 @@ public final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false] class
@R|kotlin/PublishedApi|() internal final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false, LazyPublishedApiEffectiveVisibilityKey=public] class Published : R|kotlin/Any| {
@R|kotlin/PublishedApi|() internal final [LazyPublishedApiEffectiveVisibilityKey=public] fun method(): R|kotlin/Unit|

public final val foo: R|kotlin/String|
public [ContainingClassKey=Published] get(): R|kotlin/String|
public final [LazyPublishedApiEffectiveVisibilityKey=public] val foo: R|kotlin/String|
public [ContainingClassKey=Published, LazyPublishedApiEffectiveVisibilityKey=public] get(): R|kotlin/String|

@PROPERTY:R|kotlin/PublishedApi|() internal final [LazyPublishedApiEffectiveVisibilityKey=public] val prop: R|kotlin/Int|
internal [ContainingClassKey=Published, LazyPublishedApiEffectiveVisibilityKey=public] get(): R|kotlin/Int|
Expand All @@ -85,7 +85,7 @@ public final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false] class
@R|kotlin/PublishedApi|() internal [ContainingClassKey=Published, LazyPublishedApiEffectiveVisibilityKey=public] constructor(): R|test/Published|

@R|kotlin/PublishedApi|() internal final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false, LazyPublishedApiEffectiveVisibilityKey=public] class Nested : R|kotlin/Any| {
public [ContainingClassKey=Nested] constructor(): R|test/Published.Nested|
public [ContainingClassKey=Nested, LazyPublishedApiEffectiveVisibilityKey=public] constructor(): R|test/Published.Nested|

}

Expand Down

0 comments on commit 5f5af38

Please sign in to comment.