From b44785c24ed3bdb85833d7cfb778c319ea0ca9e2 Mon Sep 17 00:00:00 2001 From: Andrey Zinovyev Date: Mon, 21 Jun 2021 12:56:40 +0300 Subject: [PATCH] [FIR] NOTHING_TO_OVERRIDE diagnostic --- .../diagnostics/conflictingOverloads.kt | 4 +- .../CallBasedInExpressionGenerator.kt | 6 +-- .../RedundantModalityModifierChecker.kt | 2 +- .../testData/resolve/overrides/simple.kt | 2 +- .../properties/javaAccessorsComplex.kt | 4 +- .../declaration/FirOverrideChecker.kt | 4 +- ...JvmOverridesBackwardCompatibilityHelper.kt | 12 +++++- .../scopes/impl/FirStandardOverrideChecker.kt | 10 +++++ .../cannotOverrideInvisibleMember.fir.kt | 2 +- .../implementMethodsFromInterface.fir.kt | 25 ----------- .../implementMethodsFromInterface.kt | 1 + .../tests/defaultArguments/kt5232.fir.kt | 11 ----- .../tests/defaultArguments/kt5232.kt | 1 + .../overridesNothing.fir.kt | 2 +- .../overrides.fir.kt | 12 +++--- .../overridesJavaAnnotated.fir.kt | 4 +- .../diagnostics/tests/generics/kt5508.fir.kt | 2 +- .../sameSuperTraitDifferentBounds.fir.kt | 30 +++++++++++++ .../sameSuperTraitDifferentBounds.kt | 3 +- .../tests/override/Generics.fir.kt | 4 +- .../tests/override/NonGenerics.fir.kt | 4 +- .../differentSetsOfBounds.fir.kt | 7 --- .../typeParameters/differentSetsOfBounds.kt | 1 + .../substitutionInSuperType.fir.kt | 41 ------------------ .../substitutionInSuperType.kt | 1 + .../tests/platformTypes/rawOverrides.fir.kt | 41 ------------------ .../tests/platformTypes/rawOverrides.kt | 1 + .../platformTypes/rawSamOverrides.fir.kt | 41 ------------------ .../tests/platformTypes/rawSamOverrides.kt | 1 + .../rawTypes/rawSupertypeOverride.fir.kt | 10 ++--- .../saveAnnotationAfterSubstitution.fir.kt | 43 ------------------- .../saveAnnotationAfterSubstitution.kt | 1 + .../scopes/VisibilityInheritModifier.fir.kt | 2 +- .../forEachRemainingNullability.fir.kt | 4 +- .../notConsideredMethod.fir.kt | 2 +- .../targetedBuiltIns/blackListed.fir.kt | 2 +- .../testData/ir/irText/classes/kt45853.kt | 3 ++ .../builtins/jvm/JvmBuiltInsSignatures.kt | 3 +- 38 files changed, 99 insertions(+), 250 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/dataClasses/implementMethodsFromInterface.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/defaultArguments/kt5232.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitDifferentBounds.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/override/typeParameters/differentSetsOfBounds.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawOverrides.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawSamOverrides.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.fir.kt diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/conflictingOverloads.kt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/conflictingOverloads.kt index ee40af52669..dde780a5ce9 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/conflictingOverloads.kt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/conflictingOverloads.kt @@ -19,13 +19,13 @@ fun test(z: Int, c: Char) {} } class B : A { - override fun rest(s: String) {} + override fun rest(s: String) {} fun rest(s: String) {} fun rest(l: Long) {} - override val u = 310 + override val u = 310 } interface B diff --git a/compiler/fir/analysis-tests/testData/resolve/expresssions/CallBasedInExpressionGenerator.kt b/compiler/fir/analysis-tests/testData/resolve/expresssions/CallBasedInExpressionGenerator.kt index f31be1e628c..e50aa657ed5 100644 --- a/compiler/fir/analysis-tests/testData/resolve/expresssions/CallBasedInExpressionGenerator.kt +++ b/compiler/fir/analysis-tests/testData/resolve/expresssions/CallBasedInExpressionGenerator.kt @@ -17,17 +17,17 @@ class CallBasedInExpressionGenerator( private val resolvedCall = operatorReference.getResolvedCallWithAssert(codegen.bindingContext) private val isInverted = operatorReference.getReferencedNameElementType() == KtTokens.NOT_IN - override fun generate(argument: StackValue): BranchedValue = + override fun generate(argument: StackValue): BranchedValue = gen(argument).let { if (isInverted) Invert(it) else it } private fun gen(argument: StackValue): BranchedValue = object : BranchedValue(argument, null, argument.type, Opcodes.IFEQ) { - override fun putSelector(type: Type, kotlinType: KotlinType?, v: InstructionAdapter) { + override fun putSelector(type: Type, kotlinType: KotlinType?, v: InstructionAdapter) { invokeFunction(v) coerceTo(type, kotlinType, v) } - override fun condJump(jumpLabel: Label, v: InstructionAdapter, jumpIfFalse: Boolean) { + override fun condJump(jumpLabel: Label, v: InstructionAdapter, jumpIfFalse: Boolean) { invokeFunction(v) v.visitJumpInsn(if (jumpIfFalse) Opcodes.IFEQ else Opcodes.IFNE, jumpLabel) } diff --git a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantModalityModifierChecker.kt b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantModalityModifierChecker.kt index bf353fc648e..2bbc6c3a321 100644 --- a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantModalityModifierChecker.kt +++ b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantModalityModifierChecker.kt @@ -25,7 +25,7 @@ interface B { interface Foo expect abstract class AbstractClass : Foo { - abstract override fun foo() + abstract override fun foo() abstract fun bar() diff --git a/compiler/fir/analysis-tests/testData/resolve/overrides/simple.kt b/compiler/fir/analysis-tests/testData/resolve/overrides/simple.kt index 59cebb11ff3..1b5fec85375 100644 --- a/compiler/fir/analysis-tests/testData/resolve/overrides/simple.kt +++ b/compiler/fir/analysis-tests/testData/resolve/overrides/simple.kt @@ -9,7 +9,7 @@ open class A { class B : A() { override fun foo(): B = this fun bar(): B = this // Missing 'override' - override fun buz(p: B): B = this //No override as B not :> A + override fun buz(p: B): B = this //No override as B not :> A fun test() { foo() diff --git a/compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorsComplex.kt b/compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorsComplex.kt index 868a065a4e4..deabe8d254f 100644 --- a/compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorsComplex.kt +++ b/compiler/fir/analysis-tests/testData/resolve/properties/javaAccessorsComplex.kt @@ -6,8 +6,8 @@ public interface JA { // FILE: main.kt interface KB { - override fun getFoo(): F - override fun getBar(): F + override fun getFoo(): F + override fun getBar(): F } interface D1 : JA, KB diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt index 855605b0d6e..7e20a5b0bd7 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt @@ -250,10 +250,8 @@ object FirOverrideChecker : FirClassChecker() { } } - @Suppress("UNUSED_PARAMETER") // TODO: delete me after implementing body private fun DiagnosticReporter.reportNothingToOverride(declaration: FirMemberDeclaration, context: CheckerContext) { - // TODO: not ready yet, e.g., Collections - // reportOn(declaration.source, FirErrors.NOTHING_TO_OVERRIDE, declaration, context) + reportOn(declaration.source, FirErrors.NOTHING_TO_OVERRIDE, declaration, context) } private fun DiagnosticReporter.reportOverridingFinalMember( diff --git a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/session/FirJvmOverridesBackwardCompatibilityHelper.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/session/FirJvmOverridesBackwardCompatibilityHelper.kt index cdf342df2a3..8f5eca3fe0e 100644 --- a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/session/FirJvmOverridesBackwardCompatibilityHelper.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/session/FirJvmOverridesBackwardCompatibilityHelper.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction import org.jetbrains.kotlin.fir.declarations.utils.isFinal import org.jetbrains.kotlin.fir.dispatchReceiverTypeOrNull import org.jetbrains.kotlin.fir.originalOrSelf +import org.jetbrains.kotlin.fir.resolve.toFirRegularClass import org.jetbrains.kotlin.fir.scopes.getDirectOverriddenFunctions import org.jetbrains.kotlin.fir.scopes.getDirectOverriddenProperties import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol @@ -67,7 +68,16 @@ object FirJvmOverridesBackwardCompatibilityHelper : FirOverridesBackwardCompatib if (originalMember.origin !in javaOrigin) return false val containingClassName = originalMember.containingClass()?.classId?.asSingleFqName()?.toUnsafe() ?: return false // If the super class is mapped to a Kotlin built-in class, then we don't require `override` keyword. - if (JavaToKotlinClassMap.mapKotlinToJava(containingClassName) != null) return true + if (JavaToKotlinClassMap.mapKotlinToJava(containingClassName) != null) { + return true + } + + if (!originalMember.isAbstract) { + val containingClass = originalMember.containingClass()?.toFirRegularClass(context.session) + if (containingClass?.isInterface == false) { + return false + } + } val scope = symbol.dispatchReceiverTypeOrNull()?.toRegularClass(context.session)?.unsubstitutedScope(context) ?: return false diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt index 2fd9d8cd663..3c9e4b065e5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt @@ -58,9 +58,19 @@ class FirStandardOverrideChecker(private val session: FirSession) : FirAbstractO fun isEqualTypes(candidateTypeRef: FirTypeRef, baseTypeRef: FirTypeRef, substitutor: ConeSubstitutor): Boolean { candidateTypeRef.ensureResolvedTypeDeclaration(session, requiredPhase = FirResolvePhase.TYPES) baseTypeRef.ensureResolvedTypeDeclaration(session, requiredPhase = FirResolvePhase.TYPES) + if (candidateTypeRef is FirErrorTypeRef && baseTypeRef is FirErrorTypeRef) { + return maybeEqualErrorTypes(candidateTypeRef, baseTypeRef) + } return isEqualTypes(candidateTypeRef.coneType, baseTypeRef.coneType, substitutor) } + private fun maybeEqualErrorTypes(ref1: FirErrorTypeRef, ref2: FirErrorTypeRef): Boolean { + val delegated1 = ref1.delegatedTypeRef as? FirUserTypeRef ?: return false + val delegated2 = ref2.delegatedTypeRef as? FirUserTypeRef ?: return false + if (delegated1.qualifier.size != delegated2.qualifier.size) return false + return delegated1.qualifier.zip(delegated2.qualifier).all { (l, r) -> l.name == r.name } + } + /** * Good case complexity is O(1) diff --git a/compiler/testData/diagnostics/tests/annotations/rendering/cannotOverrideInvisibleMember.fir.kt b/compiler/testData/diagnostics/tests/annotations/rendering/cannotOverrideInvisibleMember.fir.kt index b00866f80a1..0fdf564fd21 100644 --- a/compiler/testData/diagnostics/tests/annotations/rendering/cannotOverrideInvisibleMember.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/rendering/cannotOverrideInvisibleMember.fir.kt @@ -11,5 +11,5 @@ open class B1 { } class D1 : B1() { - override fun foo() {} + override fun foo() {} } diff --git a/compiler/testData/diagnostics/tests/dataClasses/implementMethodsFromInterface.fir.kt b/compiler/testData/diagnostics/tests/dataClasses/implementMethodsFromInterface.fir.kt deleted file mode 100644 index bf3b2bc347a..00000000000 --- a/compiler/testData/diagnostics/tests/dataClasses/implementMethodsFromInterface.fir.kt +++ /dev/null @@ -1,25 +0,0 @@ -// KT-11306 ABSTRACT_MEMBER_NOT_IMPLEMENTED for data class should inheriting interfaces requiring equals(), hashCode(), or toString() - -interface Foo { - override fun equals(other: Any?): Boolean - override fun hashCode(): Int - override fun toString(): String -} - -data class FooImpl(val num: Int) : Foo - -data class FooImplSome(val num: Int) : Foo { - override fun hashCode() = 42 -} - -data class FooImplAll(val num: Int) : Foo { - override fun equals(other: Any?) = false - override fun hashCode() = 42 - override fun toString() = "OK" -} - - -data class WrongSignatures(val num: Int) : Foo { - override fun equals(other: WrongSignatures) = false - override fun hashCode(): Boolean = true -} diff --git a/compiler/testData/diagnostics/tests/dataClasses/implementMethodsFromInterface.kt b/compiler/testData/diagnostics/tests/dataClasses/implementMethodsFromInterface.kt index e6aadc77bd6..b7cc5c38c10 100644 --- a/compiler/testData/diagnostics/tests/dataClasses/implementMethodsFromInterface.kt +++ b/compiler/testData/diagnostics/tests/dataClasses/implementMethodsFromInterface.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // KT-11306 ABSTRACT_MEMBER_NOT_IMPLEMENTED for data class should inheriting interfaces requiring equals(), hashCode(), or toString() interface Foo { diff --git a/compiler/testData/diagnostics/tests/defaultArguments/kt5232.fir.kt b/compiler/testData/diagnostics/tests/defaultArguments/kt5232.fir.kt deleted file mode 100644 index c41593397bf..00000000000 --- a/compiler/testData/diagnostics/tests/defaultArguments/kt5232.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -interface A { - fun visit(a:Int, b:String="") : String = b + a -} - -class B : A { - override fun visit(a:Int, b:String) : String = b + a -} - -class C : A { - override fun visit(a:Int) : String = "" + a -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/defaultArguments/kt5232.kt b/compiler/testData/diagnostics/tests/defaultArguments/kt5232.kt index 649329ec316..9c628c18f2b 100644 --- a/compiler/testData/diagnostics/tests/defaultArguments/kt5232.kt +++ b/compiler/testData/diagnostics/tests/defaultArguments/kt5232.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL interface A { fun visit(a:Int, b:String="") : String = b + a } diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/overridesNothing.fir.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/overridesNothing.fir.kt index 664ad15e830..df44e409b58 100644 --- a/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/overridesNothing.fir.kt +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/accidentalOverrides/overridesNothing.fir.kt @@ -3,5 +3,5 @@ interface B { } class C : B { - override val x = 1 + override val x = 1 } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/overrides.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/overrides.fir.kt index 038434b4655..90b7b4cd4bc 100644 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/overrides.fir.kt +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/overrides.fir.kt @@ -5,10 +5,10 @@ interface A { fun bar(x: T!!): T!! } -interface B : A { - override fun foo(x: T1): T1 - override fun bar(x: T1!!): T1!! -} +//interface B : A { +// override fun foo(x: T1): T1 +// override fun bar(x: T1!!): T1!! +//} interface C : A { override fun foo(x: T2!!): T2!! @@ -17,7 +17,7 @@ interface C : A { interface D : A { override fun foo(x: String?): String? - override fun bar(x: String): String + override fun bar(x: String): String } interface E : A { @@ -26,7 +26,7 @@ interface E : A { } interface F : A { - override fun foo(x: String): String + override fun foo(x: String): String override fun bar(x: String?): String? } diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/overridesJavaAnnotated.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/overridesJavaAnnotated.fir.kt index 7eb6f5d041b..c0997b309b4 100644 --- a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/overridesJavaAnnotated.fir.kt +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/overridesJavaAnnotated.fir.kt @@ -32,8 +32,8 @@ interface E : A { } interface F : A { - override fun foo(x: String): String - override fun bar(x: String?): String? + override fun foo(x: String): String + override fun bar(x: String?): String? } interface G : A { diff --git a/compiler/testData/diagnostics/tests/generics/kt5508.fir.kt b/compiler/testData/diagnostics/tests/generics/kt5508.fir.kt index 932b33aea69..4011cf97716 100644 --- a/compiler/testData/diagnostics/tests/generics/kt5508.fir.kt +++ b/compiler/testData/diagnostics/tests/generics/kt5508.fir.kt @@ -11,7 +11,7 @@ abstract class A { // while for being a correct override it should be A.B>.B.B.C> // It happens because at the beginning we search implicit arguments for an outer classes through supertypes // See TypeResolver.computeImplicitOuterClassArguments for clarifications - override fun foo(x: B>) { + override fun foo(x: B>) { throw UnsupportedOperationException() } diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitDifferentBounds.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitDifferentBounds.fir.kt new file mode 100644 index 00000000000..a70bb847133 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitDifferentBounds.fir.kt @@ -0,0 +1,30 @@ +// fir reports NOTHING_TO_OVERRIDE because it keeps only one definition of p.Base +// MODULE: m1 +// FILE: x.kt +package p + +public interface Base { + public fun foo(t: Array) {} +} + +public interface A : Base + +// MODULE: m2 +// FILE: x.kt +package p + +public interface Base { + public fun foo(t: Array) {} +} + +public interface B : Base + +// MODULE: m3(m1, m2) +// FILE: x.kt + +import p.* + +class Foo: A, B { + override fun foo(t: Array) {} + override fun foo(t: Array) {} +} diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitDifferentBounds.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitDifferentBounds.kt index bcf88e59fbb..ab970bf3989 100644 --- a/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitDifferentBounds.kt +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateSuper/sameSuperTraitDifferentBounds.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // MODULE: m1 // FILE: x.kt package p @@ -27,4 +26,4 @@ import p.* class Foo: A, B { override fun foo(t: Array) {} override fun foo(t: Array) {} -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/override/Generics.fir.kt b/compiler/testData/diagnostics/tests/override/Generics.fir.kt index 6c0e076e169..8008eaa8b11 100644 --- a/compiler/testData/diagnostics/tests/override/Generics.fir.kt +++ b/compiler/testData/diagnostics/tests/override/Generics.fir.kt @@ -42,8 +42,8 @@ abstract class MyAbstractClass1 : MyTrait, MyAbstractClass() { class MyIllegalGenericClass1 : MyTrait, MyAbstractClass() {} class MyIllegalGenericClass2(r : R) : MyTrait, MyAbstractClass() { - override fun foo(r: R) = r - override val <T> pr : R = r + override fun foo(r: R) = r + override val <T> pr : R = r } class MyIllegalClass1 : MyTrait, MyAbstractClass() {} abstract class MyLegalAbstractClass1 : MyTrait, MyAbstractClass() {} diff --git a/compiler/testData/diagnostics/tests/override/NonGenerics.fir.kt b/compiler/testData/diagnostics/tests/override/NonGenerics.fir.kt index 7531f35ea21..3bbd774aae6 100644 --- a/compiler/testData/diagnostics/tests/override/NonGenerics.fir.kt +++ b/compiler/testData/diagnostics/tests/override/NonGenerics.fir.kt @@ -38,8 +38,8 @@ class MyChildClass() : MyClass() {} class MyIllegalClass4() : MyTrait, MyAbstractClass() { fun foo() {} val pr : Unit - override fun other() {} - override val otherPr : Int = 1 + override fun other() {} + override val otherPr : Int = 1 } class MyChildClass1() : MyClass() { diff --git a/compiler/testData/diagnostics/tests/override/typeParameters/differentSetsOfBounds.fir.kt b/compiler/testData/diagnostics/tests/override/typeParameters/differentSetsOfBounds.fir.kt deleted file mode 100644 index efe77a95f12..00000000000 --- a/compiler/testData/diagnostics/tests/override/typeParameters/differentSetsOfBounds.fir.kt +++ /dev/null @@ -1,7 +0,0 @@ -interface A { - fun foo() where T : Any, T : Cloneable? -} - -interface B : A { - override fun foo() where T : Any?, T : Cloneable -} diff --git a/compiler/testData/diagnostics/tests/override/typeParameters/differentSetsOfBounds.kt b/compiler/testData/diagnostics/tests/override/typeParameters/differentSetsOfBounds.kt index f048e5cf395..f1cda453c8f 100644 --- a/compiler/testData/diagnostics/tests/override/typeParameters/differentSetsOfBounds.kt +++ b/compiler/testData/diagnostics/tests/override/typeParameters/differentSetsOfBounds.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL interface A { fun foo() where T : Any, T : Cloneable? } diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.fir.kt deleted file mode 100644 index 70550717f38..00000000000 --- a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.fir.kt +++ /dev/null @@ -1,41 +0,0 @@ -// FILE: A.java - -import java.util.*; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class A { - public void bar(@NotNull T x) { - } -} - -// FILE: B1.java -public class B1 extends A { - // real override - public void bar(String x) { - } -} - -// FILE: B2.java -public class B2 extends A { - // fake override bar -} - -// FILE: k.kt - -class C1 : A() { - override fun bar(x: String) {} -} - -class C2 : A() { - override fun bar(x: String?) {} -} - -fun test() { - B1().bar(null) - B2().bar(null) - - C1().bar(null) -} - diff --git a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.kt b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.kt index 53bddd424f0..2451411a4da 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/notNullTypeParameter/substitutionInSuperType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: A.java import java.util.*; diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawOverrides.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawOverrides.fir.kt deleted file mode 100644 index 2923b6e0549..00000000000 --- a/compiler/testData/diagnostics/tests/platformTypes/rawOverrides.fir.kt +++ /dev/null @@ -1,41 +0,0 @@ -// FILE: A.java -import java.util.*; -public interface A { - E foo(T x, List y); -} - -// FILE: B.java -import java.util.*; -public interface B extends A { - @Override - public String foo(Object x, List y); -} - -// FILE: C.java -import java.util.*; -public abstract class C { - E bar(F x, List> y); -} - -// FILE: D.java -import java.util.*; -public class D extends C { - @Override - public String bar(CharSequence x, List y) { - return null; - } -} - -// FILE: main.kt - -class E : D(), B { - override fun foo(x: Any, y: List): String = "" - override fun bar(x: CharSequence?, y: List<*>?): String = "" -} - -class E2 : B { - override fun foo(x: Any, y: List): String = "" -} - - -class F : D() diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawOverrides.kt b/compiler/testData/diagnostics/tests/platformTypes/rawOverrides.kt index 15250dd0a00..2cb078fa70f 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawOverrides.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawOverrides.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: A.java import java.util.*; public interface A { diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawSamOverrides.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawSamOverrides.fir.kt deleted file mode 100644 index bfd6557874e..00000000000 --- a/compiler/testData/diagnostics/tests/platformTypes/rawSamOverrides.fir.kt +++ /dev/null @@ -1,41 +0,0 @@ -// (failed) attempt to reproduce exception in -// http://stackoverflow.com/questions/42571812/unsupportedoperationexception-while-building-a-kotlin-project-in-idea - -// FILE: Fun.java -public interface Fun { - public void invoke(T x); -} - -// FILE: A.java -public interface A { - public void foo(T x, Fun y); -} - -// FILE: B.java -public interface B extends A { - @Override - public void foo(Object x, Fun y); -} - -// FILE: C.java -public abstract class C { - public abstract void bar(Fun y); - - public static void aStaticMethod(T x, Fun y) {} - - public static abstract class D extends C { - @Override - public void bar(Fun y) {} - - public static void aStaticMethod(Object x, Fun y) {} - } -} - -// FILE: main.kt -class E1 : C.D(), B { - override fun foo(x: Any, y: Fun) {} -} - -class E2 : B { - override fun foo(x: Any, y: Fun) {} -} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawSamOverrides.kt b/compiler/testData/diagnostics/tests/platformTypes/rawSamOverrides.kt index 31d2a2d4ac6..06c20fff4ac 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawSamOverrides.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawSamOverrides.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // (failed) attempt to reproduce exception in // http://stackoverflow.com/questions/42571812/unsupportedoperationexception-while-building-a-kotlin-project-in-idea diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.fir.kt index a2140ed2e02..624bd5fbdce 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.fir.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertypeOverride.fir.kt @@ -18,21 +18,21 @@ public class RawADerived extends A { import java.util.*; class B1 : RawADerived() { - override fun foo(x: CharSequence, y: Map, z: HashMap): A<*> = null!! + override fun foo(x: CharSequence, y: Map, z: HashMap): A<*> = null!! - override fun bar(d: Array>>) {} + override fun bar(d: Array>>) {} } class B2 : RawADerived() { - override fun foo(x: CharSequence?, y: MutableMap, z: HashMap): A = null!! + override fun foo(x: CharSequence?, y: MutableMap, z: HashMap): A = null!! - override fun bar(d: Array>>) {} + override fun bar(d: Array>>) {} } class B3 : RawADerived() { // Type of second parameter (y) is not equal to overridden // RawADerived.foo.y --- (MutableMap..Map) is not a subtype of Map - override fun foo(x: CharSequence, y: Map, z: HashMap): A<*> = null!! + override fun foo(x: CharSequence, y: Map, z: HashMap): A<*> = null!! } class B4 : RawADerived() { diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.fir.kt deleted file mode 100644 index 96c0111f5e5..00000000000 --- a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.fir.kt +++ /dev/null @@ -1,43 +0,0 @@ -// FILE: A.java - -import org.jetbrains.annotations.*; - -public interface A { - void foo(@NotNull T x, @Nullable T y); -} - -// FILE: B1.java - -// contains fake_override fun foo(/*0*/ org.jetbrains.annotations.NotNull() x: kotlin.String, /*1*/ org.jetbrains.annotations.Nullable() y: kotlin.String?) -public interface B1 extends A {} - -// FILE: B2.java -import org.jetbrains.annotations.*; - -public interface B2 extends A { - // Ok, consistent override - // override fun foo(/*0*/ org.jetbrains.annotations.NotNull() x: kotlin.String, /*1*/ org.jetbrains.annotations.Nullable() y: kotlin.String?) - void foo(@NotNull String x, @Nullable String y); -} - -// FILE: B3.java -import org.jetbrains.annotations.*; - -public interface B3 extends A { - // inconsistent override, both parameters are platform - // override /*1*/ fun foo(/*0*/ org.jetbrains.annotations.Nullable() x: kotlin.String!, /*1*/ org.jetbrains.annotations.NotNull() y: kotlin.String!): kotlin.Unit - void foo(@Nullable String x, @NotNull String y); -} - -// FILE: main.kt - -// fake_override fun foo(/*0*/ org.jetbrains.annotations.NotNull() x: kotlin.String, /*1*/ org.jetbrains.annotations.Nullable() y: kotlin.String?): kotlin.Unit -interface C1 : A - -// fake_override fun foo(/*0*/ org.jetbrains.annotations.NotNull() x: kotlin.String?, /*1*/ org.jetbrains.annotations.Nullable() y: kotlin.String?): kotlin.Unit -interface C2 : A - -interface C3 : B1 { - // inconsistent override - override fun foo(x: String?, y: String?); -} diff --git a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.kt b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.kt index 80b2e1e08bb..ae1a718bd31 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/typeEnhancement/saveAnnotationAfterSubstitution.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: A.java import org.jetbrains.annotations.*; diff --git a/compiler/testData/diagnostics/tests/scopes/VisibilityInheritModifier.fir.kt b/compiler/testData/diagnostics/tests/scopes/VisibilityInheritModifier.fir.kt index 74da7ebc34e..ac4d447f3b7 100644 --- a/compiler/testData/diagnostics/tests/scopes/VisibilityInheritModifier.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/VisibilityInheritModifier.fir.kt @@ -18,7 +18,7 @@ open class D { } class E : D() { - internal override fun self() = this + internal override fun self() = this fun test() { val s : E = self() diff --git a/compiler/testData/diagnostics/tests/targetedBuiltIns/forEachRemainingNullability.fir.kt b/compiler/testData/diagnostics/tests/targetedBuiltIns/forEachRemainingNullability.fir.kt index d456941ce4b..cc02859a6fe 100644 --- a/compiler/testData/diagnostics/tests/targetedBuiltIns/forEachRemainingNullability.fir.kt +++ b/compiler/testData/diagnostics/tests/targetedBuiltIns/forEachRemainingNullability.fir.kt @@ -11,7 +11,7 @@ abstract class MyIt2 : Iterator { } abstract class MyIt3 : Iterator { - override fun forEachRemaining(x: Consumer?) {} + override fun forEachRemaining(x: Consumer?) {} } abstract class MyIt4 : Iterator { @@ -23,7 +23,7 @@ abstract class MyIt5 : Iterator { } abstract class MyIt6 : Iterator { - override fun forEachRemaining(x: Consumer) {} + override fun forEachRemaining(x: Consumer) {} } abstract class MyIt7 : Iterator { diff --git a/compiler/testData/diagnostics/tests/testWithModifiedMockJdk/notConsideredMethod.fir.kt b/compiler/testData/diagnostics/tests/testWithModifiedMockJdk/notConsideredMethod.fir.kt index 43d5f154075..795cc0e5d0d 100644 --- a/compiler/testData/diagnostics/tests/testWithModifiedMockJdk/notConsideredMethod.fir.kt +++ b/compiler/testData/diagnostics/tests/testWithModifiedMockJdk/notConsideredMethod.fir.kt @@ -3,7 +3,7 @@ interface A : MutableCollection { // Override of deprecated function could be marked as deprecated too - override fun nonExistingMethod(x: String) = "" + override fun nonExistingMethod(x: String) = "" } fun foo(x: MutableCollection, y: Collection, z: A) { diff --git a/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/blackListed.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/blackListed.fir.kt index 40e8b61ed19..21fb611001e 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/blackListed.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/blackListed.fir.kt @@ -2,7 +2,7 @@ abstract class A : MutableList { override fun sort(/*0*/ p0: java.util.Comparator) { - super.sort(p0) + super.sort(p0) } } diff --git a/compiler/testData/ir/irText/classes/kt45853.kt b/compiler/testData/ir/irText/classes/kt45853.kt index d56f3664e5d..fdd516c3dd9 100644 --- a/compiler/testData/ir/irText/classes/kt45853.kt +++ b/compiler/testData/ir/irText/classes/kt45853.kt @@ -1,4 +1,5 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR // SKIP_KT_DUMP // DUMP_EXTERNAL_CLASS: X // DUMP_EXTERNAL_CLASS: AX @@ -8,6 +9,8 @@ abstract class A { abstract val a: A? } +//Fir doesn't treat B.getA as an override, because it is not return-type compatible with AX.getA +// Which might be correct behaivour. So disable fir till KT-46042 class B() : AX() { override fun getA(): X? = super.a } diff --git a/core/compiler.common.jvm/src/org/jetbrains/kotlin/builtins/jvm/JvmBuiltInsSignatures.kt b/core/compiler.common.jvm/src/org/jetbrains/kotlin/builtins/jvm/JvmBuiltInsSignatures.kt index d0ce29847ba..33fdca17d32 100644 --- a/core/compiler.common.jvm/src/org/jetbrains/kotlin/builtins/jvm/JvmBuiltInsSignatures.kt +++ b/core/compiler.common.jvm/src/org/jetbrains/kotlin/builtins/jvm/JvmBuiltInsSignatures.kt @@ -98,7 +98,8 @@ object JvmBuiltInsSignatures { inJavaUtil( "List", - "replaceAll(Ljava/util/function/UnaryOperator;)V" + "replaceAll(Ljava/util/function/UnaryOperator;)V", + "sort(Ljava/util/Comparator;)V" ) + inJavaUtil(