[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
@@ -25,7 +25,12 @@ sealed class ExpectActualCompatibility<out D> {
object ParameterShape : StrongIncompatible<Nothing>("parameter shapes are different (extension vs non-extension)")
object ParameterCount : StrongIncompatible<Nothing>("number of value parameters is different")
object TypeParameterCount : StrongIncompatible<Nothing>("number of type parameters is different")
// FunctionTypeParameterCount is strong because functions can be overloaded by type parameter count
object FunctionTypeParameterCount : StrongIncompatible<Nothing>("number of type parameters is different")
// ClassTypeParameterCount is weak because classes cannot be overloaded
object ClassTypeParameterCount : WeakIncompatible<Nothing>(FunctionTypeParameterCount.reason)
object ParameterTypes : StrongIncompatible<Nothing>("parameter types are different")
object ReturnType : StrongIncompatible<Nothing>("return type is different")
@@ -79,7 +84,12 @@ sealed class ExpectActualCompatibility<out D> {
object Modality : WeakIncompatible<Nothing>("modality is different")
object Visibility : WeakIncompatible<Nothing>("visibility is different")
object TypeParameterUpperBounds : StrongIncompatible<Nothing>("upper bounds of type parameters are different")
// FunctionTypeParameterUpperBounds is weak because functions can be overloaded by type parameter upper bounds
object FunctionTypeParameterUpperBounds : StrongIncompatible<Nothing>("upper bounds of type parameters are different")
// ClassTypeParameterUpperBounds is strong because classes cannot be overloaded
object ClassTypeParameterUpperBounds : WeakIncompatible<Nothing>(FunctionTypeParameterUpperBounds.reason)
object TypeParameterVariance : WeakIncompatible<Nothing>("declaration-site variances of type parameters are different")
object TypeParameterReified : WeakIncompatible<Nothing>(
"some type parameter is reified in one declaration and non-reified in the other"