diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt index b2f2fa05d6c..0a799d56fac 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt @@ -40,6 +40,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getFirstArgumentExpression import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.jvm.JvmClassName +import org.jetbrains.kotlin.resolve.jvm.checkers.JvmDefaultChecker import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver @@ -59,8 +60,6 @@ import java.io.StringWriter import java.io.PrintWriter import java.util.* -private val JVM_DEFAULT_FQ_NAME = FqName("kotlin.annotations.JvmDefault") - fun generateIsCheck( v: InstructionAdapter, kotlinType: KotlinType, @@ -424,4 +423,4 @@ fun MethodNode.textifyMethodNode(): String { return "$sw" } -fun CallableMemberDescriptor.hasJvmDefaultAnnotation() = getDirectMember(this).annotations.hasAnnotation(JVM_DEFAULT_FQ_NAME) +fun CallableMemberDescriptor.hasJvmDefaultAnnotation() = getDirectMember(this).annotations.hasAnnotation(JvmDefaultChecker.JVM_DEFAULT_FQ_NAME) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmDefaultChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmDefaultChecker.kt new file mode 100644 index 00000000000..ebbcbfc2b1e --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmDefaultChecker.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.resolve.jvm.checkers + +import org.jetbrains.kotlin.config.JvmTarget +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.psi.KtDeclaration +import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils +import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker +import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext +import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm + +class JvmDefaultChecker(val jvmTarget: JvmTarget) : DeclarationChecker { + + companion object { + val JVM_DEFAULT_FQ_NAME = FqName("kotlin.jvm.JvmDefault") + + } + + override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) { + + descriptor.annotations.findAnnotation(JVM_DEFAULT_FQ_NAME)?.let { annotationDescriptor -> + val reportOn = DescriptorToSourceUtils.getSourceFromAnnotation(annotationDescriptor) ?: declaration + if (!DescriptorUtils.isInterface(descriptor.containingDeclaration)) { + context.trace.report(ErrorsJvm.JVM_DEFAULT_NOT_IN_INTERFACE.on(reportOn)) + } else if (jvmTarget == JvmTarget.JVM_1_6) { + context.trace.report(ErrorsJvm.JVM_DEFAULT_IN_JVM6_TARGET.on(reportOn)) + } + return@check + } + + if (!DescriptorUtils.isInterface(descriptor.containingDeclaration)) return + val memberDescriptor = descriptor as? CallableMemberDescriptor ?: return + if (descriptor is PropertyAccessorDescriptor) return + + if (memberDescriptor.overriddenDescriptors.any { it.annotations.hasAnnotation(JVM_DEFAULT_FQ_NAME) }) { + context.trace.report(ErrorsJvm.JVM_DEFAULT_REQUIRED_FOR_OVERRIDE.on(declaration)) + } + } +} \ No newline at end of file diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java index ec21bcfdf64..49be6635d1f 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java @@ -133,6 +133,10 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension { MAP.put(ASSIGNMENT_TO_ARRAY_LOOP_VARIABLE, "Assignment to a for-in-array loop range variable. Behavior may change in Kotlin 1.3. " + "See https://youtrack.jetbrains.com/issue/KT-21354 for more details"); + + MAP.put(JVM_DEFAULT_NOT_IN_INTERFACE,"'@JvmDefault' is only supported on interface members"); + MAP.put(JVM_DEFAULT_IN_JVM6_TARGET,"'@JvmDefault' is only supported since JVM target 1.8. Recompile with '-jvm-target 1.8'"); + MAP.put(JVM_DEFAULT_REQUIRED_FOR_OVERRIDE, "'@JvmDefault' is required for an override of a '@JvmDefault' member"); } @NotNull diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java index 1722df2a92b..2ac2037428b 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java @@ -114,6 +114,10 @@ public interface ErrorsJvm { DiagnosticFactory0 ASSIGNMENT_TO_ARRAY_LOOP_VARIABLE = DiagnosticFactory0.create(WARNING); + DiagnosticFactory0 JVM_DEFAULT_NOT_IN_INTERFACE = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 JVM_DEFAULT_IN_JVM6_TARGET = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 JVM_DEFAULT_REQUIRED_FOR_OVERRIDE = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); + enum NullabilityInformationSource { KOTLIN { @NotNull diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt index e23cbf4f665..a3d7a8668ac 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt @@ -91,6 +91,7 @@ object JvmPlatformConfigurator : PlatformConfigurator( container.useImpl() container.useImpl() container.useImpl() + container.useImpl() container.useImpl() container.useImpl() container.useImpl() diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.kt new file mode 100644 index 00000000000..45b5fd6dadb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.kt @@ -0,0 +1,60 @@ +// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE +// !API_VERSION: 1.3 +// !JVM_TARGET: 1.8 +interface A { + @kotlin.annotations.JvmDefault + fun test(p: T) { + } +} + +interface ANonDefault { + fun test(p: String) {} +} + +interface B : A { + + override fun test(p: T) + {} +} + +interface C : A, ANonDefault { + + override fun test(p: T) + {} + + override fun test(p: String) { + } +} + +interface C1 : C { + override fun test(p: String) { + + } +} + +interface C2 : C, ANonDefault { + override fun test(p: String) { + + } +} + +interface D : ANonDefault, A { + + override fun test(p: T) + {} + + override fun test(p: String) { + } +} + +interface D1 : D { + override fun test(p: String) { + + } +} + +interface D2 : ANonDefault, D { + override fun test(p: String) { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.txt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.txt new file mode 100644 index 00000000000..ab81181edaa --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.txt @@ -0,0 +1,66 @@ +package + +public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + @kotlin.annotations.JvmDefault public open fun test(/*0*/ p: T): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface ANonDefault { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open fun test(/*0*/ p: kotlin.String): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface B : A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ fun test(/*0*/ p: T): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface C : A, ANonDefault { + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ fun test(/*0*/ p: T): kotlin.Unit + public open override /*1*/ fun test(/*0*/ p: kotlin.String): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface C1 : C { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ fun test(/*0*/ p: kotlin.String): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface C2 : C, ANonDefault { + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*3*/ fun test(/*0*/ p: kotlin.String): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface D : ANonDefault, A { + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ fun test(/*0*/ p: T): kotlin.Unit + public open override /*1*/ fun test(/*0*/ p: kotlin.String): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface D1 : D { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ fun test(/*0*/ p: kotlin.String): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface D2 : ANonDefault, D { + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*3*/ fun test(/*0*/ p: kotlin.String): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.kt new file mode 100644 index 00000000000..ea5ac772fd6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE +// !API_VERSION: 1.3 +// !JVM_TARGET: 1.8 +abstract class A { + + @kotlin.annotations.JvmDefault + fun test() {} + + @kotlin.annotations.JvmDefault + abstract fun test2(s: String = "") + + @kotlin.annotations.JvmDefault + abstract fun test3() +} + +object B { + + @kotlin.annotations.JvmDefault + fun test() {} + + @kotlin.annotations.JvmDefault + fun test2(s: String = "") {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.txt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.txt new file mode 100644 index 00000000000..f310d510890 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.txt @@ -0,0 +1,20 @@ +package + +public abstract class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + @kotlin.annotations.JvmDefault public final fun test(): kotlin.Unit + @kotlin.annotations.JvmDefault public abstract fun test2(/*0*/ s: kotlin.String = ...): kotlin.Unit + @kotlin.annotations.JvmDefault public abstract fun test3(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public object B { + private constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + @kotlin.annotations.JvmDefault public final fun test(): kotlin.Unit + @kotlin.annotations.JvmDefault public final fun test2(/*0*/ s: kotlin.String = ...): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.kt new file mode 100644 index 00000000000..f6d4a3e6ebd --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE +// !API_VERSION: 1.3 +// !JVM_TARGET: 1.8 +interface B { + + @kotlin.annotations.JvmDefault + val prop1: String + @kotlin.annotations.JvmDefault get() = "" + + + var prop2: String + @kotlin.annotations.JvmDefault get() = "" + @kotlin.annotations.JvmDefault set(value) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.txt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.txt new file mode 100644 index 00000000000..cb8c415fc0a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.txt @@ -0,0 +1,9 @@ +package + +public interface B { + @kotlin.annotations.JvmDefault public open val prop1: kotlin.String + public open var prop2: kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.kt new file mode 100644 index 00000000000..c1d632b3459 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE +// !API_VERSION: 1.3 +// !JVM_TARGET: 1.8 +interface A { + @kotlin.annotations.JvmDefault + fun test() {} +} + +interface Abstract : A { + override fun test() +} + +interface ANonDefault { + fun test() {} +} + +interface B: A { + override fun test() {} +} + +interface C: ANonDefault, A { + override fun test() {} +} + +interface D: A, ANonDefault { + override fun test() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.txt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.txt new file mode 100644 index 00000000000..b684e59689a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.txt @@ -0,0 +1,43 @@ +package + +public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + @kotlin.annotations.JvmDefault public open fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface ANonDefault { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Abstract : A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public abstract override /*1*/ fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface B : A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface C : ANonDefault, A { + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ fun test(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface D : A, ANonDefault { + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ fun test(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverrideWithFeature.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverrideWithFeature.kt new file mode 100644 index 00000000000..9128f2f0230 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverrideWithFeature.kt @@ -0,0 +1,28 @@ +// !API_VERSION: 1.3 +// !JVM_TARGET: 1.8 +@kotlin.annotations.JvmDefaultFeature +interface A { + @kotlin.annotations.JvmDefault + fun test() { + } +} + +interface Abstract : A { + override fun test() +} + +interface ANonDefault { + fun test() {} +} + +interface B : A { + override fun test() {} +} + +interface C : ANonDefault, A { + override fun test() {} +} + +interface D : A, ANonDefault { + override fun test() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverrideWithFeature.txt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverrideWithFeature.txt new file mode 100644 index 00000000000..7ef05ffcf59 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverrideWithFeature.txt @@ -0,0 +1,43 @@ +package + +@kotlin.annotations.JvmDefaultFeature public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + @kotlin.annotations.JvmDefault public open fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface ANonDefault { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Abstract : A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public abstract override /*1*/ fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface B : A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface C : ANonDefault, A { + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ fun test(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface D : A, ANonDefault { + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ fun test(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.kt new file mode 100644 index 00000000000..14f5a2ad6dc --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.kt @@ -0,0 +1,32 @@ +// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE +// !API_VERSION: 1.3 +// !JVM_TARGET: 1.8 +interface A { + @kotlin.annotations.JvmDefault + val test: String + get() = "OK" +} + +interface Abstract : A { + override val test: String +} + +interface ANonDefault { + val test: String + get() = "ANonDefault" +} + +interface B: A { + override val test: String + get() = "B" +} + +interface C: ANonDefault, A { + override val test: String + get() = "C" +} + +interface D: A, ANonDefault { + override val test: String + get() = "C" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.txt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.txt new file mode 100644 index 00000000000..e7b9e261fe5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.txt @@ -0,0 +1,43 @@ +package + +public interface A { + @kotlin.annotations.JvmDefault public open val test: kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface ANonDefault { + public open val test: kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Abstract : A { + public abstract override /*1*/ val test: kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface B : A { + public open override /*1*/ val test: kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface C : ANonDefault, A { + public open override /*2*/ val test: kotlin.String + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface D : A, ANonDefault { + public open override /*2*/ val test: kotlin.String + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.kt new file mode 100644 index 00000000000..a98847001cd --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE +// !API_VERSION: 1.3 +// !JVM_TARGET: 1.6 +interface B { + + @kotlin.annotations.JvmDefault + fun test() {} + + @kotlin.annotations.JvmDefault + abstract fun test2(s: String = "") + + @kotlin.annotations.JvmDefault + abstract fun test3() + + + + @kotlin.annotations.JvmDefault + abstract val prop: String + + @kotlin.annotations.JvmDefault + abstract val prop2: String + + @kotlin.annotations.JvmDefault + val prop3: String + get() = "" + + @kotlin.annotations.JvmDefault + var prop4: String + get() = "" + set(value) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.txt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.txt new file mode 100644 index 00000000000..080785254a5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.txt @@ -0,0 +1,14 @@ +package + +public interface B { + @kotlin.annotations.JvmDefault public abstract val prop: kotlin.String + @kotlin.annotations.JvmDefault public abstract val prop2: kotlin.String + @kotlin.annotations.JvmDefault public open val prop3: kotlin.String + @kotlin.annotations.JvmDefault public open var prop4: kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + @kotlin.annotations.JvmDefault public open fun test(): kotlin.Unit + @kotlin.annotations.JvmDefault public abstract fun test2(/*0*/ s: kotlin.String = ...): kotlin.Unit + @kotlin.annotations.JvmDefault public abstract fun test3(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.kt new file mode 100644 index 00000000000..66bfb8a59f2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.kt @@ -0,0 +1,30 @@ +// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE +// !API_VERSION: 1.3 +// !JVM_TARGET: 1.8 +interface B { + + @kotlin.annotations.JvmDefault + fun test() {} + + @kotlin.annotations.JvmDefault + abstract fun test2(s: String = "") + + @kotlin.annotations.JvmDefault + abstract fun test3() + + + @kotlin.annotations.JvmDefault + abstract val prop: String + + @kotlin.annotations.JvmDefault + abstract val prop2: String + + @kotlin.annotations.JvmDefault + val prop3: String + get() = "" + + @kotlin.annotations.JvmDefault + var prop4: String + get() = "" + set(value) {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.txt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.txt new file mode 100644 index 00000000000..080785254a5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.txt @@ -0,0 +1,14 @@ +package + +public interface B { + @kotlin.annotations.JvmDefault public abstract val prop: kotlin.String + @kotlin.annotations.JvmDefault public abstract val prop2: kotlin.String + @kotlin.annotations.JvmDefault public open val prop3: kotlin.String + @kotlin.annotations.JvmDefault public open var prop4: kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + @kotlin.annotations.JvmDefault public open fun test(): kotlin.Unit + @kotlin.annotations.JvmDefault public abstract fun test2(/*0*/ s: kotlin.String = ...): kotlin.Unit + @kotlin.annotations.JvmDefault public abstract fun test3(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index d11eb68b06f..22ec11e035b 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -468,6 +468,63 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW } } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmDefault extends AbstractDiagnosticsTestWithStdLib { + public void testAllFilesPresentInJvmDefault() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("generic.kt") + public void testGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.kt"); + doTest(fileName); + } + + @TestMetadata("notInterface.kt") + public void testNotInterface() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.kt"); + doTest(fileName); + } + + @TestMetadata("propertyAccessor.kt") + public void testPropertyAccessor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.kt"); + doTest(fileName); + } + + @TestMetadata("simpleOverride.kt") + public void testSimpleOverride() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.kt"); + doTest(fileName); + } + + @TestMetadata("simpleOverrideWithFeature.kt") + public void testSimpleOverrideWithFeature() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverrideWithFeature.kt"); + doTest(fileName); + } + + @TestMetadata("simplePropertyOverride.kt") + public void testSimplePropertyOverride() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.kt"); + doTest(fileName); + } + + @TestMetadata("target6.kt") + public void testTarget6() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.kt"); + doTest(fileName); + } + + @TestMetadata("target8.kt") + public void testTarget8() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index a9e18a3c0c6..527a01bbf78 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -468,6 +468,63 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno } } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmDefault extends AbstractDiagnosticsTestWithStdLibUsingJavac { + public void testAllFilesPresentInJvmDefault() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("generic.kt") + public void testGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.kt"); + doTest(fileName); + } + + @TestMetadata("notInterface.kt") + public void testNotInterface() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.kt"); + doTest(fileName); + } + + @TestMetadata("propertyAccessor.kt") + public void testPropertyAccessor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.kt"); + doTest(fileName); + } + + @TestMetadata("simpleOverride.kt") + public void testSimpleOverride() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.kt"); + doTest(fileName); + } + + @TestMetadata("simpleOverrideWithFeature.kt") + public void testSimpleOverrideWithFeature() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverrideWithFeature.kt"); + doTest(fileName); + } + + @TestMetadata("simplePropertyOverride.kt") + public void testSimplePropertyOverride() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.kt"); + doTest(fileName); + } + + @TestMetadata("target6.kt") + public void testTarget6() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.kt"); + doTest(fileName); + } + + @TestMetadata("target8.kt") + public void testTarget8() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmField") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)