From 61d1963ddb650e298de13189dcd2d5f3f1ffaae3 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Fri, 13 Oct 2017 03:27:01 +0300 Subject: [PATCH] Mark incompatibilities related to the declaration signature as STRONG --- .../ExpectedActualDeclarationChecker.kt | 6 ++--- ...tDeclarationWithStrongIncompatibilities.kt | 6 +++++ ...DeclarationWithStrongIncompatibilities.txt | 4 +++ ...ectDeclarationWithWeakIncompatibilities.kt | 15 +++++++---- ...ctDeclarationWithWeakIncompatibilities.txt | 26 ++++++++++++++++--- ...lityCheckForExplicitAndImplicitOverride.kt | 2 +- .../functionIncorrectSignature/output.txt | 9 +++++++ .../incompatibleCallables/output.txt | 24 +++++++++++++++++ .../incompatibleClasses/output.txt | 6 +++++ 9 files changed, 85 insertions(+), 13 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExpectedActualDeclarationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExpectedActualDeclarationChecker.kt index 4146324d639..fa5c5a081e4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExpectedActualDeclarationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExpectedActualDeclarationChecker.kt @@ -306,13 +306,13 @@ object ExpectedActualDeclarationChecker : DeclarationChecker { sealed class Incompatible(val reason: String?, val kind: IncompatibilityKind = IncompatibilityKind.WEAK) : Compatibility() { // Callables - object ParameterShape : Incompatible("parameter shapes are different (extension vs non-extension)") + object ParameterShape : Incompatible("parameter shapes are different (extension vs non-extension)", IncompatibilityKind.STRONG) object ParameterCount : Incompatible("number of value parameters is different", IncompatibilityKind.STRONG) - object TypeParameterCount : Incompatible("number of type parameters is different") + object TypeParameterCount : Incompatible("number of type parameters is different", IncompatibilityKind.STRONG) object ParameterTypes : Incompatible("parameter types are different", IncompatibilityKind.STRONG) - object ReturnType : Incompatible("return type is different") + object ReturnType : Incompatible("return type is different", IncompatibilityKind.STRONG) object ParameterNames : Incompatible("parameter names are different") object TypeParameterNames : Incompatible("names of type parameters are different") diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithStrongIncompatibilities.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithStrongIncompatibilities.kt index 2bc7b96500a..524dbf95704 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithStrongIncompatibilities.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithStrongIncompatibilities.kt @@ -8,6 +8,9 @@ expect fun foo2(x: Int) expect class NoArgConstructor() +expect fun foo3(): Int +expect fun foo4(): Int + // MODULE: m2-jvm(m1-common) // FILE: jvm.kt @@ -20,6 +23,9 @@ fun foo1(x: String) {} fun foo2(x: Int, y: Int) {} fun foo2(x: String) {} +actual fun foo3(): String = "" +fun foo4(x: Int): String = "" + actual class NoArgConstructor { actual constructor() actual constructor(x: Int) diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithStrongIncompatibilities.txt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithStrongIncompatibilities.txt index 205a6e8add0..c950dd608b7 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithStrongIncompatibilities.txt +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithStrongIncompatibilities.txt @@ -3,6 +3,8 @@ package public expect fun foo1(/*0*/ x: kotlin.Int): kotlin.Unit public expect fun foo2(/*0*/ x: kotlin.Int): kotlin.Unit +public expect fun foo3(): kotlin.Int +public expect fun foo4(): kotlin.Int public final expect class NoArgConstructor { public constructor NoArgConstructor() @@ -20,6 +22,8 @@ public fun foo1(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int): kotlin.Unit public fun foo1(/*0*/ x: kotlin.String): kotlin.Unit public fun foo2(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int): kotlin.Unit public fun foo2(/*0*/ x: kotlin.String): kotlin.Unit +public actual fun foo3(): kotlin.String +public fun foo4(/*0*/ x: kotlin.Int): kotlin.String public final actual class NoArgConstructor { public constructor NoArgConstructor() diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.kt index 183070dd793..64dabad62b0 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.kt @@ -6,18 +6,23 @@ expect class Foo1 expect class Foo2 -expect fun foo1(): Int expect fun foo2(): Int -expect fun foo3(): Int + +expect val s: String + +expect open class Foo3 // MODULE: m2-jvm(m1-common) // FILE: jvm.kt -interface Foo1 +interface Foo1 actual interface Foo2 -actual fun foo1(): String = "" +actual var s: String = "value" fun foo2(): Int = 0 -fun foo3(x: Int): String = "" + +actual class Foo3 + +class Foo3 diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.txt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.txt index 7f622bc8150..6f49e7480a5 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.txt +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.txt @@ -1,9 +1,8 @@ // -- Module: -- package -public expect fun foo1(): kotlin.Int +public expect val s: kotlin.String public expect fun foo2(): kotlin.Int -public expect fun foo3(): kotlin.Int public final expect class Foo1 { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -17,13 +16,18 @@ public final expect class Foo2 { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } +public open expect class Foo3 { + 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 +} + // -- Module: -- package -public actual fun foo1(): kotlin.String +public actual var s: kotlin.String public fun foo2(): kotlin.Int -public fun foo3(/*0*/ x: kotlin.Int): kotlin.String public interface Foo1 { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -36,3 +40,17 @@ public actual interface Foo2 { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } + +public final actual class Foo3 { + public constructor Foo3() + 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 final class Foo3 { + public constructor Foo3() + 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/tests/multiplatform/headerClass/modalityCheckForExplicitAndImplicitOverride.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/modalityCheckForExplicitAndImplicitOverride.kt index f54681b3d17..08f48fa58b9 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/headerClass/modalityCheckForExplicitAndImplicitOverride.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/modalityCheckForExplicitAndImplicitOverride.kt @@ -23,7 +23,7 @@ open class Open { } actual open class Foo1 : Open() { - override val x = super.x + override val x = super.x } actual open class Foo2 : Open() diff --git a/compiler/testData/multiplatform/classScopes/functionIncorrectSignature/output.txt b/compiler/testData/multiplatform/classScopes/functionIncorrectSignature/output.txt index 3a0efc42b7b..ecca778177b 100644 --- a/compiler/testData/multiplatform/classScopes/functionIncorrectSignature/output.txt +++ b/compiler/testData/multiplatform/classScopes/functionIncorrectSignature/output.txt @@ -5,6 +5,15 @@ Output: -- JVM -- Exit code: COMPILATION_ERROR Output: +compiler/testData/multiplatform/classScopes/functionIncorrectSignature/jvm.kt:1:14: error: actual class 'Foo' has no corresponding members for expected class members: + + public final expect fun function(b: ByteArray): Int + + The following declaration is incompatible because return type is different: + public final actual fun function(b: ByteArray): Long + +actual class Foo { + ^ compiler/testData/multiplatform/classScopes/functionIncorrectSignature/jvm.kt:2:40: error: actual function 'function' has no corresponding expected declaration The following declaration is incompatible because return type is different: public final expect fun function(b: ByteArray): Int diff --git a/compiler/testData/multiplatform/incompatibleCallables/output.txt b/compiler/testData/multiplatform/incompatibleCallables/output.txt index 6315aa89432..a39b8696040 100644 --- a/compiler/testData/multiplatform/incompatibleCallables/output.txt +++ b/compiler/testData/multiplatform/incompatibleCallables/output.txt @@ -8,6 +8,12 @@ expect fun f21(c: suspend Unit.() -> Unit) -- JVM -- Exit code: COMPILATION_ERROR Output: +compiler/testData/multiplatform/incompatibleCallables/common.kt:1:12: error: expected function 'f1' has no actual declaration in module +The following declaration is incompatible because return type is different: + public actual fun f1(): String + +expect fun f1() + ^ compiler/testData/multiplatform/incompatibleCallables/common.kt:5:14: error: expected function 'f3' has no actual declaration in module The following declaration is incompatible because parameter types are different: public actual fun f3(name: Double): Unit @@ -20,12 +26,30 @@ The following declaration is incompatible because parameter types are different: expect fun String.f3ext() ^ +compiler/testData/multiplatform/incompatibleCallables/common.kt:8:14: error: expected function 'f4' has no actual declaration in module +The following declaration is incompatible because parameter shapes are different (extension vs non-extension): + public actual fun String.f4(): Unit + +expect fun f4(name: String) + ^ +compiler/testData/multiplatform/incompatibleCallables/common.kt:10:12: error: expected function 'f5' has no actual declaration in module +The following declaration is incompatible because parameter shapes are different (extension vs non-extension): + public actual fun f5(name: String): Unit + +expect fun String.f5() + ^ compiler/testData/multiplatform/incompatibleCallables/common.kt:12:14: error: expected function 'f6' has no actual declaration in module The following declaration is incompatible because number of value parameters is different: public actual fun f6(p2: Int): Unit expect fun f6(p1: String, p2: Int) ^ +compiler/testData/multiplatform/incompatibleCallables/common.kt:14:12: error: expected function 'f7' has no actual declaration in module +The following declaration is incompatible because number of type parameters is different: + public actual fun f7(): Unit + +expect fun f7() + ^ compiler/testData/multiplatform/incompatibleCallables/common.kt:32:15: error: expected function 'f21' has no actual declaration in module The following declaration is incompatible because parameter types are different: public actual fun f21(c: Unit.() -> Unit): Unit diff --git a/compiler/testData/multiplatform/incompatibleClasses/output.txt b/compiler/testData/multiplatform/incompatibleClasses/output.txt index 6639137a39b..02a75b8a3a1 100644 --- a/compiler/testData/multiplatform/incompatibleClasses/output.txt +++ b/compiler/testData/multiplatform/incompatibleClasses/output.txt @@ -5,6 +5,12 @@ Output: -- JVM -- Exit code: COMPILATION_ERROR Output: +compiler/testData/multiplatform/incompatibleClasses/common.kt:14:16: error: expected class 'C1' has no actual declaration in module +The following declaration is incompatible because number of type parameters is different: + public final actual class C1 + +expect class C1 + ^ compiler/testData/multiplatform/incompatibleClasses/jvm.kt:1:8: error: actual interface 'PClass' has no corresponding expected declaration The following declaration is incompatible because class kinds are different (class, interface, object, enum, annotation): public final expect class PClass