Skip to content

Commit 5f5af38

Browse files
demiurg906Space Team
authored and
Space Team
committed
[FIR] Remove incorrect fast-path from @PublishedAPI computation for binary 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
1 parent 435080b commit 5f5af38

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

Diff for: analysis/low-level-api-fir/testData/getOrBuildFirBinary/publishedApi/publishedApiClass.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ FIR source kind: KtRealSourceElementKind
77

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

1212
}

Diff for: compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/transformers/publishedApiEffectiveVisibility.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fun computePublishedApiEffectiveVisibility(
6767
)
6868
}
6969

70-
fun computePublishedApiEffectiveVisibility(
70+
private fun computePublishedApiEffectiveVisibility(
7171
hasPublishedApiAnnotation: Boolean,
7272
visibility: Visibility,
7373
selfEffectiveVisibility: EffectiveVisibility,
@@ -112,8 +112,6 @@ fun FirMemberDeclaration.setLazyPublishedVisibility(annotations: List<FirAnnotat
112112
}
113113

114114
fun FirMemberDeclaration.setLazyPublishedVisibility(hasPublishedApi: Boolean, parentProperty: FirProperty?, session: FirSession) {
115-
if (!hasPublishedApi) return
116-
117115
lazyPublishedApiEffectiveVisibility = lazy {
118116
val containingClassLookupTag = (when {
119117
parentProperty != null -> parentProperty.symbol.callableId.classId
@@ -125,9 +123,9 @@ fun FirMemberDeclaration.setLazyPublishedVisibility(hasPublishedApi: Boolean, pa
125123
val status = status as FirResolvedDeclarationStatus
126124
val parentSymbol = containingClassLookupTag?.toSymbol(session)
127125
computePublishedApiEffectiveVisibility(
128-
hasPublishedApiAnnotation = true,
126+
hasPublishedApiAnnotation = hasPublishedApi,
129127
visibility = status.visibility,
130-
selfEffectiveVisibility = status.effectiveVisibility,
128+
selfEffectiveVisibility = status.visibility.toEffectiveVisibility(parentSymbol, forClass = this is FirClass),
131129
containingClassLookupTag = containingClassLookupTag,
132130
parentEffectiveVisibility = parentProperty?.effectiveVisibility ?: parentSymbol?.effectiveVisibility
133131
?: EffectiveVisibility.Public,

Diff for: compiler/testData/loadJava/compiledKotlin/visibility/PublishedApi.fir.k1.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false] cla
3131
@R|kotlin/PublishedApi|() internal [ContainingClassKey=Internal, LazyPublishedApiEffectiveVisibilityKey=internal] constructor(foo: R|kotlin/String|): R|test/Internal|
3232

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

3636
}
3737

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

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

6363
}
6464

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

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

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

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

9090
}
9191

Diff for: compiler/testData/loadJava/compiledKotlin/visibility/PublishedApi.fir.k2.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal final [HasNoEnumEntriesKey=true, IsNewPlaceForBodyGeneration=false] cla
3131
@R|kotlin/PublishedApi|() internal [ContainingClassKey=Internal, LazyPublishedApiEffectiveVisibilityKey=internal] constructor(): R|test/Internal|
3232

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

3636
}
3737

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

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

6363
}
6464

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

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

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

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

9090
}
9191

0 commit comments

Comments
 (0)