From 43d06f85e384936a082d62126600269247831d5c Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 12 Mar 2019 11:09:42 +0300 Subject: [PATCH] Add raw type comparison for Java (J2K mapping is taken into account) NB: Java enhancement scope does not perform substitution, so we could have some duplicates inside "type enhancement" testData Related to KT-29937 --- .../fir/java/scopes/JavaClassUseSiteScope.kt | 22 ++++++++++++++----- .../kotlin/fir/symbols/impl/FirClassSymbol.kt | 10 +++++++++ .../fir/symbols/impl/FirTypeAliasSymbol.kt | 10 +++++++++ .../symbols/impl/FirTypeParameterSymbol.kt | 8 +++++++ .../return/SubclassOfMapEntry.fir.txt | 2 ++ 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteScope.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteScope.kt index ce8c1bff279..90c110ad721 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteScope.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteScope.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.java.scopes +import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirNamedFunction @@ -18,8 +19,8 @@ import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol import org.jetbrains.kotlin.fir.symbols.ConeFunctionSymbol import org.jetbrains.kotlin.fir.symbols.ConePropertySymbol import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol -import org.jetbrains.kotlin.fir.types.ConeKotlinType -import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.typeContext +import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.name.Name class JavaClassUseSiteScope( @@ -33,10 +34,21 @@ class JavaClassUseSiteScope( //base symbol as key, overridden as value private val overriddenByBase = mutableMapOf() - @Suppress("UNUSED_PARAMETER") + private val context: ConeTypeContext = session.typeContext + private fun isEqualTypes(a: ConeKotlinType, b: ConeKotlinType): Boolean { - // TODO: introduce normal type comparison - return true + if (a is ConeFlexibleType) return isEqualTypes(a.lowerBound, b) + if (b is ConeFlexibleType) return isEqualTypes(a, b.lowerBound) + with(context) { + if (a is ConeClassLikeType && b is ConeClassLikeType) { + val aId = a.lookupTag.classId + val bId = b.lookupTag.classId + val aMapped = JavaToKotlinClassMap.mapJavaToKotlin(aId.asSingleFqName()) ?: aId + val bMapped = JavaToKotlinClassMap.mapJavaToKotlin(bId.asSingleFqName()) ?: bId + return aMapped == bMapped + } + return isEqualTypeConstructors(a.typeConstructor(), b.typeConstructor()) + } } private fun isEqualTypes(a: FirTypeRef, b: FirTypeRef) = diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirClassSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirClassSymbol.kt index 153304864de..1f80eb0eab7 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirClassSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirClassSymbol.kt @@ -14,4 +14,14 @@ import org.jetbrains.kotlin.name.ClassId class FirClassSymbol(override val classId: ClassId) : ConeClassSymbol, AbstractFirBasedSymbol() { override fun toLookupTag(): ConeClassLikeLookupTag = ConeClassLikeLookupTagImpl(classId) + + override fun equals(other: Any?): Boolean = + other is FirClassSymbol && classId == other.classId && fir == other.fir + + override fun hashCode(): Int { + var result = 31 + result = result * 19 + classId.hashCode() + result = result * 19 + fir.hashCode() + return result + } } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirTypeAliasSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirTypeAliasSymbol.kt index b7fb4c8d0fb..4b3e264b4f5 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirTypeAliasSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirTypeAliasSymbol.kt @@ -16,6 +16,16 @@ class FirTypeAliasSymbol( override val classId: ClassId ) : ConeTypeAliasSymbol, AbstractFirBasedSymbol() { override fun toLookupTag(): ConeClassLikeLookupTag = TypeAliasLookupTagImpl(classId) + + override fun equals(other: Any?): Boolean = + other is FirTypeAliasSymbol && classId == other.classId && fir == other.fir + + override fun hashCode(): Int { + var result = 31 + result = result * 19 + classId.hashCode() + result = result * 19 + fir.hashCode() + return result + } } class TypeAliasLookupTagImpl( diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirTypeParameterSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirTypeParameterSymbol.kt index 2ffbb38cf4f..2209efd1f62 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirTypeParameterSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirTypeParameterSymbol.kt @@ -19,4 +19,12 @@ class FirTypeParameterSymbol : AbstractFirBasedSymbol(), ConeT get() = this override fun toLookupTag(): ConeTypeParameterLookupTag = this + + override fun equals(other: Any?): Boolean { + return other is FirTypeParameterSymbol && fir == other.fir + } + + override fun hashCode(): Int { + return fir.hashCode() + } } diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/SubclassOfMapEntry.fir.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/SubclassOfMapEntry.fir.txt index 029996b957a..ac40fe16abb 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/SubclassOfMapEntry.fir.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/SubclassOfMapEntry.fir.txt @@ -1,4 +1,6 @@ public abstract interface SubclassOfMapEntry : R|java/util/Map.Entry| { public abstract operator function setValue(value: R|ft|!): R|ft|! + public abstract operator function setValue(: R|ft|!): R|ft|! + }