-
Notifications
You must be signed in to change notification settings - Fork 295
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
Consider using sealed hierarchies in the KSP API to allow exhaustive whens #1351
Comments
Here you can see how this could be implemented in KSP: lukellmann/ksp@97774aa...910985a (see commit messages for details) If this change is desired, I can open a pull request. In addition, some |
This is a good suggestion. One reason I can think of as to why this is not happening before was actually that prior to Kotlin 1.5, sealed classes has to be in the same file 🤦 . That said, I will still need some time to think about other potential implications of making it sealed inheritance, but if nothing major comes to my mind, I am favoring this suggestion. |
One obvious implication is that you will no longer be able to extend those types outside of KSP. However, I don't know why you would have to. |
It would also mean that code can then use exhaustive |
Did you have time for this yet? If so, what are your thoughts? Should I open a PR? |
Hi I will be on vacation soon so probably not the best time for handling this. Would you mind wait for 3 more weeks? |
That's fine for me. |
So, what's the state of this? |
Hi thanks for the reminder, I've just come back. Overall I think this looks to be a good direction to move forward. Like you mentioned there are a couple of good candidates to be adopted as sealed classes, when you said you want to open PR, which classes you have in your mind for this? I think it is better to start with smaller scopes to simplify the effort (i.e. leave out |
I was thinking of
The effort to also seal |
Hi, after some discussion internally, we would like to proceed with this proposal, but as this still introduces some risks of breaking change (e.g. |
Alright, thanks for looking into it! |
Is there any update on this? Is a new major release planned? Would including this change make sense? |
It's currently planned for 1.9.20 release. |
Nice. Let me know if there needs to be work done on #1380 so that it can be included. |
I've updated #1380 to resolve merge conflicts. |
Could you elaborate how the logic of else clauses would change? I don't really understand what you mean here. |
Here is a real-world example that could benefit from sealed hierarchies in the KSP API:
If
KSDeclaration
was asealed interface
, there would be no need to provide anelse
. In the hypothetical scenario that a new subtype ofKSDeclaration
was introduced, a compile error would arise because thewhen
wouldn't cover all possible cases anymore (which is desirable if one wants to be exhaustive and handle all cases correctly).jvmBinaryName
could also be implemented using a visitor and can even also result in compiler errors (because of new non-overridden methods fromKSVisitor
) when newKSNode
s are introduced, however the implementation is more complex and requires more code:I think the following types would benefit from being
sealed
:KSNode
,KSAnnotated
,KSDeclarationContainer
,KSReferenceElement
,KSModifierListOwner
,KSPropertyAccessor
,KSDeclaration
(the one that would benefit the example above) and alsocom.google.devtools.ksp.processing.PlatformInfo
.The text was updated successfully, but these errors were encountered: