Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-public markers aren't handled correctly for properties #36

Closed
zsmb13 opened this issue Jan 10, 2021 · 5 comments
Closed

Non-public markers aren't handled correctly for properties #36

zsmb13 opened this issue Jan 10, 2021 · 5 comments
Assignees
Labels
bug Something isn't working PR welcome

Comments

@zsmb13
Copy link

zsmb13 commented Jan 10, 2021

When declaring an opt-in annotation and adding that annotation to the nonPublicMarkers configuration, properties that have the annotation present are not correctly excluded from the api dump.

Example annotation:

@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
annotation class MyInternalApi

A function like this will not show up in the dump (correctly):

@MyInternalApi
fun internalFun() {}

However, this property will:

@MyInternalApi
var internalVar = 0

... in the form of a getter and a setter:

public static final fun getInternalVar ()I
public static final fun setInternalVar (I)V

A workaround that removes these from the API dump is annotating the getter and setter directly, like so:

var otherInternalVar = 0
    @MyInternalApi get
    @MyInternalApi set

However, annotating the getter like that doesn't trigger warnings at the call site of the property, so you really need three annotations on each property to satisfy both the plugin and inspections:

@MyInternalApi
var combinedInternalVar = 0
    @MyInternalApi get
    @MyInternalApi set

Project with examples and reproducing the issue can be found here.

@qwwdfsad qwwdfsad added the bug Something isn't working label Jan 21, 2021
@qwwdfsad
Copy link
Member

qwwdfsad commented Jan 21, 2021

Thanks for the report, this is indeed a bug in binary compatibility validator.
Semantically, @MyInternalApi should be applied to both getter and setter (and compiler behaves as it does), but in the implementation, we do not redundantly mark each getter and setter and thus BCV treats them like part of API.

PRs are welcome, for the reference we got a pretty similar issue with @PublishedApi and default parameters: #30

@martinbonnin
Copy link
Contributor

Another issue is that if @MyInternalApi is an "Opt-in" marker, it's not possible to add it on the getter. The kotlin compiler fails with:

Opt-in requirement marker annotation cannot be used on getter

That makes it harder to workaround the issue because "Opt-in" markers are typically the kind of annotation that are nice to hide.

@qwwdfsad
Copy link
Member

Unfortunately, we're overwhelmed with other work right now, so we can't provide ETA for the fix.
PRs will be timely reviewed though

@martinbonnin
Copy link
Contributor

Tentative PR there: #81. It pulls all the property/field annotations on getters/setters, which I think is what we want?
But I have very limited experience about the semantics of fields vs setters vs property annotations, so I might be missing something. All feedback welcome!

@qwwdfsad qwwdfsad self-assigned this May 17, 2022
@qwwdfsad
Copy link
Member

Merged into master, will be fixed in the next release

ilya-g added a commit to JetBrains/kotlin that referenced this issue Nov 14, 2022
There were two problems in BCV fixed:
- Kotlin/binary-compatibility-validator#36
- Kotlin/binary-compatibility-validator#58

Therefore some methods with default values and properties that
mistakenly wasn't included in the dump, now have appeared in it.
ilya-g added a commit to JetBrains/kotlin that referenced this issue Nov 17, 2022
There were two problems in BCV fixed:
- Kotlin/binary-compatibility-validator#36
- Kotlin/binary-compatibility-validator#58

Therefore some methods with default values and properties that
mistakenly wasn't included in the dump, now have appeared in it.
KotlinBuild pushed a commit to JetBrains/kotlin that referenced this issue Nov 18, 2022
There were two problems in BCV fixed:
- Kotlin/binary-compatibility-validator#36
- Kotlin/binary-compatibility-validator#58

Therefore some methods with default values and properties that
mistakenly wasn't included in the dump, now have appeared in it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR welcome
Projects
None yet
Development

No branches or pull requests

3 participants