M13: New Layout of Top-Level Declarations

Hey.

In the blog post about the M13 release:

>By default, each Kotlin source file (e.g. myFile.kt) produces a class file with the same name, capitalized and suffixed with “Kt”: MyFileKt;

So I thought with this change I can have multiple main() functions within a single package.

src/main/kotlin/Foo.kt:
fun main(args: Array<String>) {
  println(“foo”)
}

src/main/kotlin/Bar.kt:
fun main(args: Array<String>) {
  println(“bar”)
}

Unfortunately IDEA complains with the error message:


Platform declaration clash: The following declarations have the same JVM signature…

My current workaround is to change the package name without moving the source file, which is very chaotic. Is there another way to have multiple main function within a single package with Kotlin?

(kotlin plugin: 0.14.37, kotlin compiler: 0.13.1513)

It works with @JvmStatic:

src/main/kotlin/Foo.kt:
object FooKt {
  @JvmStatic
  fun main(args: Array<String>) {
  println(“foo”)
  }
}

src/main/kotlin/Bar.kt:
object BarKt {
  @JvmStatic
  fun main(args: Array<String>) {
  println(“bar”)
  }
}

This error will go away soon, after the users migrate from the old package facades to the new scheme

So, you will change an internal flag in the Kotlin compiler that allows that in a future M13 release?

No, we will stop generating old facades, and the clash will go away

Ah, that's perfect, Andrey. I didn't looked into the generated class files.

Very great work.