No default values for constructor parameters of impl class


#1

I have converted 1 of my projects to multi-platform. This went pretty well as most of the code could be moved to the common module without any changes. The major issues were the many IntelliJ IDEA plug-in bugs so that I had to rely on command line compilation to check my changes, and that the reported errors were not always clear.

The original code contains a class with a default value for 1 of its constructor parameters. This is not supported for impl class. I can easily work around it by adding an explicit secondary constructor. What I was wondering was what the reasoning behind disallowing default parameters for constructor parameters of an impl class is?


#2

Do you mean cases like the following?

header class Foo
impl class Foo(val value: String = "value")

The reasons for this being an error are purely technical. Currently we require header and impl declarations to have almost exactly the same signature. But in this case, we could in fact determine that the impl class constructor “satisfies” the API declared by the header class constructor. Feel free to report an issue in the tracker. Thanks!


#3

Yes, this is exactly what I mean. I have created https://youtrack.jetbrains.com/issue/KT-18784