[FIR] Let attributes opt-in to participating in ConeClassLikeTypeImpl structural equality
This is required for EnhancedTypeForWarningAttribute because scopes
should not be reused between cone types with different values of
this attribute.
#KT-63208
(cherry picked from commit 9189154cae)
This commit is contained in:
committed by
Space Team
parent
ccba52aae4
commit
c39262195d
+3
-3
@@ -141,7 +141,7 @@ FILE: [ResolvedTo(IMPORTS)] Derived.kt
|
|||||||
BODY_RESOLVE:
|
BODY_RESOLVE:
|
||||||
TARGET: public open override [<synthetic> BODY_RESOLVE] val something: R|@R|Anno|(s = <strcat>(String(type: ), R|/prop|)) kotlin/String|
|
TARGET: public open override [<synthetic> BODY_RESOLVE] val something: R|@R|Anno|(s = <strcat>(String(type: ), R|/prop|)) kotlin/String|
|
||||||
@R|Anno|[Types](s = <strcat>(String(number: ), R|/prop|)) public [<synthetic> ResolvedTo(BODY_RESOLVE)] get(): R|@R|Anno|(s = <strcat>(String(type: ), R|/prop|)) kotlin/String| {
|
@R|Anno|[Types](s = <strcat>(String(number: ), R|/prop|)) public [<synthetic> ResolvedTo(BODY_RESOLVE)] get(): R|@R|Anno|(s = <strcat>(String(type: ), R|/prop|)) kotlin/String| {
|
||||||
^getSomething String(str).R|kotlin/also|<R|@R|Anno|(s = <strcat>(String(type: ), R|/prop|)) kotlin/String|>(::R|kotlin/io/println|)
|
^getSomething String(str).R|kotlin/also|<R|kotlin/String|>(::R|kotlin/io/println|)
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE: [ResolvedTo(IMPORTS)] Derived.kt
|
FILE: [ResolvedTo(IMPORTS)] Derived.kt
|
||||||
@@ -151,7 +151,7 @@ FILE: [ResolvedTo(IMPORTS)] Derived.kt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@R|Anno|[Types](s = <strcat>(String(number: ), R|/prop|)) public open override [ResolvedTo(BODY_RESOLVE)] fun getSomething(): R|@R|Anno|(s = <strcat>(String(type: ), R|/prop|)) kotlin/String| {
|
@R|Anno|[Types](s = <strcat>(String(number: ), R|/prop|)) public open override [ResolvedTo(BODY_RESOLVE)] fun getSomething(): R|@R|Anno|(s = <strcat>(String(type: ), R|/prop|)) kotlin/String| {
|
||||||
^getSomething String(str).R|kotlin/also|<R|@R|Anno|(s = <strcat>(String(type: ), R|/prop|)) kotlin/String|>(::R|kotlin/io/println|)
|
^getSomething String(str).R|kotlin/also|<R|kotlin/String|>(::R|kotlin/io/println|)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ FILE: [ResolvedTo(BODY_RESOLVE)] Derived.kt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@R|Anno|[Types](s = <strcat>(String(number: ), R|/prop|)) public open override [ResolvedTo(BODY_RESOLVE)] fun getSomething(): R|@R|Anno|(s = <strcat>(String(type: ), R|/prop|)) kotlin/String| {
|
@R|Anno|[Types](s = <strcat>(String(number: ), R|/prop|)) public open override [ResolvedTo(BODY_RESOLVE)] fun getSomething(): R|@R|Anno|(s = <strcat>(String(type: ), R|/prop|)) kotlin/String| {
|
||||||
^getSomething String(str).R|kotlin/also|<R|@R|Anno|(s = <strcat>(String(type: ), R|/prop|)) kotlin/String|>(::R|kotlin/io/println|)
|
^getSomething String(str).R|kotlin/also|<R|kotlin/String|>(::R|kotlin/io/println|)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-5
@@ -18,10 +18,7 @@ import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
|||||||
import org.jetbrains.kotlin.fir.declarations.utils.canHaveAbstractDeclaration
|
import org.jetbrains.kotlin.fir.declarations.utils.canHaveAbstractDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isAbstract
|
import org.jetbrains.kotlin.fir.declarations.utils.isAbstract
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
||||||
import org.jetbrains.kotlin.fir.types.ConeErrorType
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.coneType
|
|
||||||
import org.jetbrains.kotlin.fir.types.hasError
|
|
||||||
import org.jetbrains.kotlin.fir.types.isUnit
|
|
||||||
|
|
||||||
object FirPropertyAccessorsTypesChecker : FirPropertyChecker() {
|
object FirPropertyAccessorsTypesChecker : FirPropertyChecker() {
|
||||||
override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
@@ -100,7 +97,7 @@ object FirPropertyAccessorsTypesChecker : FirPropertyChecker() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valueSetterType != propertyType && !valueSetterType.hasError()) {
|
if (valueSetterType.withAttributes(ConeAttributes.Empty) != propertyType.withAttributes(ConeAttributes.Empty) && !valueSetterType.hasError()) {
|
||||||
reporter.reportOn(valueSetterTypeSource, FirErrors.WRONG_SETTER_PARAMETER_TYPE, propertyType, valueSetterType, context)
|
reporter.reportOn(valueSetterTypeSource, FirErrors.WRONG_SETTER_PARAMETER_TYPE, propertyType, valueSetterType, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ abstract class ConeAttribute<out T : ConeAttribute<T>> : AnnotationMarker {
|
|||||||
abstract override fun toString(): String
|
abstract override fun toString(): String
|
||||||
open fun renderForReadability(): String? = null
|
open fun renderForReadability(): String? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signals that this attribute properly implements the [equals] and [hashCode] protocol.
|
||||||
|
*
|
||||||
|
* If it returns `true`, attributes will be compared using structural equality in [ConeAttributes.definitelyDifferFrom].
|
||||||
|
*/
|
||||||
|
open val implementsEquality: Boolean get() = false
|
||||||
|
|
||||||
abstract val key: KClass<out T>
|
abstract val key: KClass<out T>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,6 +159,32 @@ class ConeAttributes private constructor(attributes: List<ConeAttribute<*>>) : A
|
|||||||
return create(attributes)
|
return create(attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns `true` if this instance is definitely not equal to the [other] instance.
|
||||||
|
* This is `true` when one instance contains an attribute **type** that the other doesn't contain or both instances contain
|
||||||
|
* an attribute of a type where [ConeAttribute.implementsEquality]` == true` and the attribute's [equals] method returns `false`.
|
||||||
|
*
|
||||||
|
* A return value of `false` doesn't guarantee that the instances are equal because [ConeAttribute.implementsEquality] is optional,
|
||||||
|
* i.e., not all attributes can be compared structurally.
|
||||||
|
*
|
||||||
|
* @see org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl.equals
|
||||||
|
*/
|
||||||
|
infix fun definitelyDifferFrom(other: ConeAttributes): Boolean {
|
||||||
|
if (this === other) return false
|
||||||
|
if (this.isEmpty() && other.isEmpty()) return false
|
||||||
|
|
||||||
|
for (index in indices) {
|
||||||
|
val a = arrayMap[index]
|
||||||
|
val b = other.arrayMap[index]
|
||||||
|
|
||||||
|
if (a == null && b == null) continue
|
||||||
|
if ((a == null) != (b == null)) return true
|
||||||
|
if (a!!.implementsEquality && a != b) return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the [transform] to all attributes that are subtypes of [ConeAttributeWithConeType] and returns a [ConeAttributes]
|
* Applies the [transform] to all attributes that are subtypes of [ConeAttributeWithConeType] and returns a [ConeAttributes]
|
||||||
* with the results of transforms that were not-`null` or `null` if no attributes were transformed.
|
* with the results of transforms that were not-`null` or `null` if no attributes were transformed.
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class ConeClassLikeTypeImpl(
|
|||||||
if (lookupTag != other.lookupTag) return false
|
if (lookupTag != other.lookupTag) return false
|
||||||
if (!typeArguments.contentEquals(other.typeArguments)) return false
|
if (!typeArguments.contentEquals(other.typeArguments)) return false
|
||||||
if (nullability != other.nullability) return false
|
if (nullability != other.nullability) return false
|
||||||
|
if (attributes definitelyDifferFrom other.attributes) return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
+19
@@ -25,6 +25,25 @@ class EnhancedTypeForWarningAttribute(
|
|||||||
|
|
||||||
override val keepInInferredDeclarationType: Boolean
|
override val keepInInferredDeclarationType: Boolean
|
||||||
get() = true
|
get() = true
|
||||||
|
|
||||||
|
override val implementsEquality: Boolean
|
||||||
|
get() = true
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as EnhancedTypeForWarningAttribute
|
||||||
|
|
||||||
|
if (coneType != other.coneType) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = coneType.hashCode()
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val ConeAttributes.enhancedTypeForWarning: EnhancedTypeForWarningAttribute? by ConeAttributes.attributeAccessor<EnhancedTypeForWarningAttribute>()
|
val ConeAttributes.enhancedTypeForWarning: EnhancedTypeForWarningAttribute? by ConeAttributes.attributeAccessor<EnhancedTypeForWarningAttribute>()
|
||||||
|
|||||||
-14
@@ -1,18 +1,4 @@
|
|||||||
MODULE main
|
MODULE main
|
||||||
CLASS MLItr.class
|
|
||||||
CLASS METADATA
|
|
||||||
FUNCTION add(Ljava/lang/String;)V
|
|
||||||
Property: class.metadata.function.valueParameters
|
|
||||||
K1
|
|
||||||
(element: kotlin/String)
|
|
||||||
K2
|
|
||||||
(element: @kotlin/jvm/internal/EnhancedNullability kotlin/String)
|
|
||||||
FUNCTION set(Ljava/lang/String;)V
|
|
||||||
Property: class.metadata.function.valueParameters
|
|
||||||
K1
|
|
||||||
(element: kotlin/String)
|
|
||||||
K2
|
|
||||||
(element: @kotlin/jvm/internal/EnhancedNullability kotlin/String)
|
|
||||||
CLASS C.class
|
CLASS C.class
|
||||||
CLASS METADATA
|
CLASS METADATA
|
||||||
K1
|
K1
|
||||||
|
|||||||
-14
@@ -1,18 +1,4 @@
|
|||||||
MODULE main
|
MODULE main
|
||||||
CLASS MLItr.class
|
|
||||||
CLASS METADATA
|
|
||||||
FUNCTION add(Ljava/lang/String;)V
|
|
||||||
Property: class.metadata.function.valueParameters
|
|
||||||
K1
|
|
||||||
(element: kotlin/String)
|
|
||||||
K2
|
|
||||||
(element: @kotlin/jvm/internal/EnhancedNullability kotlin/String)
|
|
||||||
FUNCTION set(Ljava/lang/String;)V
|
|
||||||
Property: class.metadata.function.valueParameters
|
|
||||||
K1
|
|
||||||
(element: kotlin/String)
|
|
||||||
K2
|
|
||||||
(element: @kotlin/jvm/internal/EnhancedNullability kotlin/String)
|
|
||||||
CLASS C.class
|
CLASS C.class
|
||||||
CLASS METADATA
|
CLASS METADATA
|
||||||
K1
|
K1
|
||||||
|
|||||||
-14
@@ -1,18 +1,4 @@
|
|||||||
MODULE main
|
MODULE main
|
||||||
CLASS MLItr.class
|
|
||||||
CLASS METADATA
|
|
||||||
FUNCTION add(Ljava/lang/String;)V
|
|
||||||
Property: class.metadata.function.valueParameters
|
|
||||||
K1
|
|
||||||
(element: kotlin/String)
|
|
||||||
K2
|
|
||||||
(element: @kotlin/jvm/internal/EnhancedNullability kotlin/String)
|
|
||||||
FUNCTION set(Ljava/lang/String;)V
|
|
||||||
Property: class.metadata.function.valueParameters
|
|
||||||
K1
|
|
||||||
(element: kotlin/String)
|
|
||||||
K2
|
|
||||||
(element: @kotlin/jvm/internal/EnhancedNullability kotlin/String)
|
|
||||||
CLASS C.class
|
CLASS C.class
|
||||||
CLASS METADATA
|
CLASS METADATA
|
||||||
K1
|
K1
|
||||||
|
|||||||
-14
@@ -1,18 +1,4 @@
|
|||||||
MODULE main
|
MODULE main
|
||||||
CLASS MLItr.class
|
|
||||||
CLASS METADATA
|
|
||||||
FUNCTION add(Ljava/lang/String;)V
|
|
||||||
Property: class.metadata.function.valueParameters
|
|
||||||
K1
|
|
||||||
(element: kotlin/String)
|
|
||||||
K2
|
|
||||||
(element: @kotlin/jvm/internal/EnhancedNullability kotlin/String)
|
|
||||||
FUNCTION set(Ljava/lang/String;)V
|
|
||||||
Property: class.metadata.function.valueParameters
|
|
||||||
K1
|
|
||||||
(element: kotlin/String)
|
|
||||||
K2
|
|
||||||
(element: @kotlin/jvm/internal/EnhancedNullability kotlin/String)
|
|
||||||
CLASS C.class
|
CLASS C.class
|
||||||
CLASS METADATA
|
CLASS METADATA
|
||||||
K1
|
K1
|
||||||
|
|||||||
Vendored
-14
@@ -1,18 +1,4 @@
|
|||||||
MODULE main
|
MODULE main
|
||||||
CLASS MLItr.class
|
|
||||||
CLASS METADATA
|
|
||||||
FUNCTION add(Ljava/lang/String;)V
|
|
||||||
Property: class.metadata.function.valueParameters
|
|
||||||
K1
|
|
||||||
(element: kotlin/String)
|
|
||||||
K2
|
|
||||||
(element: @kotlin/jvm/internal/EnhancedNullability kotlin/String)
|
|
||||||
FUNCTION set(Ljava/lang/String;)V
|
|
||||||
Property: class.metadata.function.valueParameters
|
|
||||||
K1
|
|
||||||
(element: kotlin/String)
|
|
||||||
K2
|
|
||||||
(element: @kotlin/jvm/internal/EnhancedNullability kotlin/String)
|
|
||||||
CLASS C.class
|
CLASS C.class
|
||||||
CLASS METADATA
|
CLASS METADATA
|
||||||
K1
|
K1
|
||||||
|
|||||||
-14
@@ -1,18 +1,4 @@
|
|||||||
MODULE main
|
MODULE main
|
||||||
CLASS MLItr.class
|
|
||||||
CLASS METADATA
|
|
||||||
FUNCTION add(Ljava/lang/String;)V
|
|
||||||
Property: class.metadata.function.valueParameters
|
|
||||||
K1
|
|
||||||
(element: kotlin/String)
|
|
||||||
K2
|
|
||||||
(element: @kotlin/jvm/internal/EnhancedNullability kotlin/String)
|
|
||||||
FUNCTION set(Ljava/lang/String;)V
|
|
||||||
Property: class.metadata.function.valueParameters
|
|
||||||
K1
|
|
||||||
(element: kotlin/String)
|
|
||||||
K2
|
|
||||||
(element: @kotlin/jvm/internal/EnhancedNullability kotlin/String)
|
|
||||||
CLASS C.class
|
CLASS C.class
|
||||||
CLASS METADATA
|
CLASS METADATA
|
||||||
K1
|
K1
|
||||||
|
|||||||
Reference in New Issue
Block a user