So, I recently started experimenting with Kotlin, and I came across this:
If a top-level ad is marked as closed, it is closed for the package declared in ( see Visibility modifiers ). Since the packages really nest in Kotlin, that is, the package foo.bar is considered a member of foo, if something personal is in the package, it is visible to all subpackages.
Note that members of external packages are not imported by default, i.e. in the file in the package foo.bar, we cannot access foo members without importing them. From: Visibility and Package Placement
So, consider the following example:
File1.kt
package foo private fun bar() = println("This is bar!!!")
and File2.kt
package foo.baz import foo.bar fun main(args: Array<String>) = bar()
From what I understand, the function bar () should be visible in the package foo.baz and, therefore, can be called from main (). But when I try to compile above, I get the following error message:
Error: Kotlin: cannot access the bar: this is 'private' in 'foo'
Is this a bug or has the language specification been updated and there is no documentation? Did I miss something?
Thanks in advance.
source share