Skip to content

Commit

Permalink
Don't generate final modifier on static interface methods produced …
Browse files Browse the repository at this point in the history
…by @JvmStatic+@jvmoverloads from interface companion

 #KT-35716 Fixed
  • Loading branch information
Mikhael Bogdanov committed Nov 2, 2020
1 parent 7d0e965 commit 7ec2d03
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.psi.KtPureClassOrObject
import org.jetbrains.kotlin.psi.KtPureElement
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils.isInterface
import org.jetbrains.kotlin.resolve.calls.components.hasDefaultValue
import org.jetbrains.kotlin.resolve.isInlineClass
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
Expand Down Expand Up @@ -134,8 +135,9 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
remainingParameters.map { DescriptorToSourceUtils.descriptorToDeclaration(it) as? KtParameter }

val generateAsFinal =
functionDescriptor.modality == Modality.FINAL ||
state.languageVersionSettings.supportsFeature(LanguageFeature.GenerateJvmOverloadsAsFinal)
(functionDescriptor.modality == Modality.FINAL ||
state.languageVersionSettings.supportsFeature(LanguageFeature.GenerateJvmOverloadsAsFinal)) &&
!isInterface(functionDescriptor.containingDeclaration)
val flags =
baseMethodFlags or
(if (isStatic) Opcodes.ACC_STATIC else 0) or
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions compiler/testData/codegen/box/jvmStatic/kt35716.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// JVM_TARGET: 1.8
// TARGET_BACKEND: JVM

// WITH_RUNTIME
// FILE: Test.java

class Test {

public static String test1() {
return A.sayHello();
}
}

// FILE: simpleCompanionObject.kt

interface A {
companion object {
@JvmStatic
@JvmOverloads
fun sayHello(greeting: String = "OK"): String {
return greeting
}
}
}
fun box(): String {
if (Test.test1() != "OK") return "fail 1"

return "OK"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7ec2d03

Please sign in to comment.