[FE] Type-safety refactoring: Make areCompatibleClassScopes to return Incompatible.WeakIncompatible

Review: https://jetbrains.team/p/kt/reviews/11039/timeline

For StrongIncompatible `actual` declaration is considered as overload
and error reports on expected declaration. For WeakIncompatible the
error is reported straight away

Before the refactoring `areCompatibleClassScopes` returned just
`Incompatible`. It is bad because StrongIncompatible isn't possible for
classes (classes can't be overloaded). Now all class incompatibilities
are weak.

The commit has a minor impact on observable behavior (cases where we
reported the compilation problems are still reported but on another
elements):
- We no longer report type parameter class incompatibilities on expect
  declaration, we report them only on actuals (it happened because all
  WeakIncompatible are reported only on actuals)
- In a sense, Java implicit actualization was the only way to "overload"
  classes (it would be a redeclaration compilation problem, so it
  doesn't count as a valid "overload"). And since type parameters
  incompatibility was StrongIncompatible for classes, we counted them as
  "overloads" and didn't report incompatibility problems on Kotlin
  class. Now we do report. (see
  implicitJavaActualization_multipleActuals)
This commit is contained in:
Nikita Bobko
2023-08-08 12:55:43 +02:00
committed by teamcity
parent 98ec13b51a
commit d4758014ec
6 changed files with 52 additions and 60 deletions
@@ -5,24 +5,6 @@ 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 <main> for JVM
The following declaration is incompatible because number of type parameters is different:
public final actual class C1<A, Extra>
expect class C1<A>
^
compiler/testData/multiplatform/incompatibleClasses/common.kt:16:16: error: expected class 'C3' has no actual declaration in module <main> for JVM
The following declaration is incompatible because upper bounds of type parameters are different:
public final actual class C3<D, E : D?>
expect class C3<D, E : D>
^
compiler/testData/multiplatform/incompatibleClasses/common.kt:18:16: error: expected class 'C4' has no actual declaration in module <main> for JVM
The following declaration is incompatible because upper bounds of type parameters are different:
public actual typealias C4<F> = C4Impl<F>
expect class C4<F>
^
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