Why it is not possible to expect only parts of a class in a multiplatform project?

Well, why?

1 Like

I strongly believe it is possible. When I remember correctly I used to do this in my project.

class Test {

    expect fun test(){  <-- "Modifier 'expect' is not applicable to 'member function'"

    }

}
1 Like

Try putting expect on the class declaration also: expect class Test. And the expected method must not have a body.

the other way around!

expect class Test {

    fun test(){  <-- "Expected declaration must not have a body"

    }

}
1 Like

Now I see what you are trying to do. You are trying to put non-expected declarations into an expected class. My first understanding was that you want to put additional functions into the actual class.

Yeah, what you are trying to do might not be possible. The best thing to do is extracting an interface with default functions in it.

2 Likes

Also

expect class Test {

    actual fun test(){  <-- "Expected declaration must not have a body"

    }

}

We have not yet designed the syntax for partial class actualization.
This issue may be relevant to watch for updates: https://youtrack.jetbrains.com/issue/KT-20427

4 Likes