Hello. I am not sure if it is a bug or a feature, but I decided to write about it here first. I am working on a cross platform application and I have a couple of classes that are platform specific. Some of them are: View
and ListView
. ListView
is a subtype of View
. The issue that I encountered is when I write “actual” implementation of ListView
I have to specify that It is a subtype of View
and not of some type that is a subtype of View
. It is a little bit wordy… Here is the thing that I want to achieve. I want to set PlatformView as a base type of ListView. PlatformView is a subtype of View itself. So, I don’t understand why it does not allow me to do this. On some platforms ListView inherit directly from View and on some from PlatformView.
expect abstract class View()
expect class ListView: View
// Some platform implementation
actual abstract class View() {
// Implementation
}
class PlatformView: View() {
// Platform specific stuff
}
// Produces the error, it does not allow PlatformView, it requires View
actual class ListView actual constructor(): PlatformView() {
// Implementation
}
I think that it is a bug, because if I add ListViewBase indirection everything works
expect abstract class View()
expect class ListViewBase: View
expect class ListView(): ListViewBase
// Some platform implementation
actual abstract class View actual constructor() {
// Basic implementation
}
class PlatformView: View() {
// Platform specific stuff
}
actual typealias ListViewBase = PlatformView
// Produces the error, it does not allow PlatformView, it requires View
actual class ListView actual constructor(): ListViewBase() {
// Implementation
}