mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-09 00:21:47 +00:00
[JVM IR] Fix JvmOverloads+Parameterless Main
Resolves the interaction of @JvmOverloads annotations and
parameterless main methods.
In the following code, both mechanisms generate methods that
ultimately produce the signature `public static void main(String[] args)`
of which there can be only one (true in general of any signature).
```
fun main() { }
@JvmOverloads
fun main(Array<String> args, x: Int = 42) { }
```
This PR simply shuffles the lowerings around, letting parameterless
main methods detect the presence of the default overload produced by
the annotation.
Additionally, this PR improves the testing of parameterless main
methods by actual bytecode patterns, and not simple check for
successful compilation (as @sfs and I discovered, there are issues in
flagging an error on duplicate signatures on the IR backend).
This commit is contained in:
committed by
Alexander Udalov
parent
b4185c9d47
commit
4973baae4e
@@ -5,4 +5,6 @@ fun main() {
|
||||
@JvmName("main")
|
||||
fun foo(args: Array<String>) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 0 INVOKESTATIC DontGenerateOnJvmNameMainKt\.main ()V
|
||||
11
compiler/testData/codegen/bytecodeText/parameterlessMain/dontGenerateOnJvmOverloads.kt
vendored
Normal file
11
compiler/testData/codegen/bytecodeText/parameterlessMain/dontGenerateOnJvmOverloads.kt
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
// IGNORE_BACKEND: JVM
|
||||
fun main() {
|
||||
println("FAIL")
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun Array<String>.main(x: Int = 4, y: String = "Test") {
|
||||
println("OK")
|
||||
}
|
||||
|
||||
// 0 INVOKESTATIC DontGenerateOnJvmOverloadsKt\.main ()V
|
||||
@@ -4,4 +4,6 @@ fun main() {
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 0 INVOKESTATIC DontGenerateOnMainKt\.main ()V
|
||||
@@ -4,4 +4,6 @@ fun main() {
|
||||
|
||||
fun Array<String>.main() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 0 INVOKESTATIC DontGenerateOnMainExtensionKt\.main ()V
|
||||
@@ -4,4 +4,6 @@ fun main() {
|
||||
|
||||
fun main(args: Array<String>?) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 0 INVOKESTATIC DontGenerateOnNullableArrayKt\.main ()V
|
||||
9
compiler/testData/codegen/bytecodeText/parameterlessMain/dontGenerateOnVarargsString.kt
vendored
Normal file
9
compiler/testData/codegen/bytecodeText/parameterlessMain/dontGenerateOnVarargsString.kt
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
fun main() {
|
||||
|
||||
}
|
||||
|
||||
fun main(vararg args: String) {
|
||||
|
||||
}
|
||||
|
||||
// 0 INVOKESTATIC DontGenerateOnVarargsStringKt\.main ()V
|
||||
Reference in New Issue
Block a user