[FIR] Forbid erroneous ===-checks

It was decided to forbid such comparisons,
as we know how `===` works. Also, added some more
test cases, just for comparison.

Reusing the proper `canHaveSubtypes()`
from `TypeUtils` prevents a breaking change
in:

- `comparingTripleWithPair.kt`
- `comparisonOfGenericInterfaceWithGenericClass.kt`

But it does lead to warnings
(instead of errors) in
`incompatibleEnumEntryClasses.kt`, which is an
unrelated mistake that will be fixed in the next
commit.

The refactoring in `canHaveSubtypes()` is purely
cosmetic - otherwise reading these conditions is hard
(and they don't fit my screen vertically).

^KT-62646
^KT-65541
^KT-57779
This commit is contained in:
Nikolay Lunyak
2024-02-26 10:46:32 +02:00
committed by Space Team
parent 6bf987e772
commit 226d4df277
23 changed files with 219 additions and 82 deletions
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.model.TypeArgumentMarker
enum class ProjectionKind {
@@ -84,3 +85,11 @@ fun ConeKotlinTypeProjection.replaceType(newType: ConeKotlinType): ConeKotlinTyp
is ConeKotlinTypeConflictingProjection -> ConeKotlinTypeConflictingProjection(newType)
}
}
val ConeTypeProjection.variance: Variance
get() = when (this.kind) {
ProjectionKind.STAR -> Variance.OUT_VARIANCE
ProjectionKind.IN -> Variance.IN_VARIANCE
ProjectionKind.OUT -> Variance.OUT_VARIANCE
ProjectionKind.INVARIANT -> Variance.INVARIANT
}