-
Notifications
You must be signed in to change notification settings - Fork 645
Unclear error about necessary serialization in case of scoping with interfaces #2174
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
Comments
The dependency on static type ( Regarding error message — indeed, it is unchanged from the ages when we had only sealed classes, so it can definitely be improved |
Came here for the same thing, thanks for improving the error message! Could there also be more build-time checking on sealed hierarchies? The doc currently says:
If I do something like this: @Serializable
sealed interface Animal
class Cat(val meow: String): Animal
class Dog(val barf: String): Animal I only get the error at runtime. Could this be caught at compile time instead? |
I think that doc needs updating. In fact, it is fine if not all sublcasses are serializable — e.g. you may have some subclass that contains private information, and you don't want to serialize it. It is possible with abstract classes (by simply not registering it), but if will be impossible for sealed classes if we force this rule. |
Trying to wrap my head around this. I think the doc is OK then? It says "All subclasses of a sealed class must be explicitly marked as @.Serializable" so that requirement is valid for sealed classes right? |
But the framework works fine even if this requirement is not met. It simply ignores non-serializable classes and throws error on them. The exact same thing happens if the base class is abstract and subclass is not registered in the module. |
I see. Thanks for clearing that up 🙏 |
Yes, we had considered it while implementing support for sealed classes but decided not to force it — the only way to opt-out of this would be, as you say, not to use sealed class/inteface. However, there's possibility that it has to be sealed for different, serialization-unrelated reasons. |
Gotcha. Thanks for the insights! |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
The problem is that the error happens at runtime and the error message isn't clear
To Reproduce
Here the plugin will throw an error:
Next, making
interface Parent
as a sealed one doesn't help, the error is the same, marking interface asSerializable
also doesn't work but it helps if you mark the interface assealed
and then putSerializable
annotation on it:Note that if you remove cast
as Parent
, then everything also works fine:Expected behavior
Ideally, it'd be nice to have an error at compile time and in IDE. If it's not possible, then it'd be better to specify an error for interfaces as right now it's slightly misleading. Note that this is minimised example, my real case was more complicated and it was unclear for me what is the problem
Environment
The text was updated successfully, but these errors were encountered: