Why can't a public `inline` function call a privat...
# getting-started
Why can't a public
function call a private
function? I get why we can't call non-inline private functions (because when we inline the public function, all its body must be accessible at the call site), but that doesn't apply to other inline functions, so long as the whole inline chain ends up calling only public stuff, right? So why is this forbidden?
Copy code
inline fun doStuffInline() {
    myPrivateInline() // ERROR: Public-API inline function cannot access non-public-API 'private inline fun myPrivateInline(): Unit defined in root package in file File.kt'

private inline fun myPrivateInline() {
    println("Anyone can call this print statement")
so long as the whole inline chain ends up calling only public stuff, right
Because of that ^ This would be hard to track, unobvious how to report, and make private inline functions very fragile to changes. Suppose you have a deep chain of inlines, all of them call only public API. Now you change something in the deepest inline function so that it starts calling non-public API, and in a different part of the program, a different inline function call becomes reported as an error.
By this reason, Kotlin requires to be explicit in intent that a non-public (inline or not) function can be called from public inline functions by marking it
@PublishedApi internal
. This also places the same restrictions on marked inline functions as on public inline functions.
Makes sense, thanks