Joffrey
07/16/2023, 3:22 PMinline
function call a private inline
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?
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")
}
https://pl.kotl.in/7bPhHMUJ-ilya.gorbunov
07/16/2023, 11:28 PMso long as the whole inline chain ends up calling only public stuff, rightBecause 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.
ilya.gorbunov
07/16/2023, 11:33 PM@PublishedApi internal
. This also places the same restrictions on marked inline functions as on public inline functions.Joffrey
07/17/2023, 7:41 AM