From 27136ef8be14d4536a2af51a38b199fed1addd90 Mon Sep 17 00:00:00 2001 From: "simon.ogorodnik" Date: Tue, 24 Mar 2020 02:22:53 +0300 Subject: [PATCH] [FIR] Support unsigned integer literals --- .../jetbrains/kotlin/fir/types/ConeTypes.kt | 1 + .../jetbrains/kotlin/fir/dump/HtmlFirDump.kt | 4 ++ .../kotlin/fir/backend/ConversionUtils.kt | 9 ++- .../kotlin/fir/builder/BaseFirBuilder.kt | 8 ++- .../kotlin/fir/resolve/ScopeUtils.kt | 7 +- ...egerLiteralTypeApproximationTransformer.kt | 15 +--- .../FirExpressionsResolveTransformer.kt | 71 ++++++++++--------- .../scopes/impl/FirIntegerLiteralTypeScope.kt | 46 +++--------- .../jetbrains/kotlin/fir/types/TypeUtils.kt | 2 +- .../kotlin/fir/expressions/FirConstKind.kt | 9 +++ .../fir/types/ConeIntegerLiteralTypeImpl.kt | 25 +++++-- .../kotlin/fir/types/FirTypeUtils.kt | 5 ++ 12 files changed, 111 insertions(+), 91 deletions(-) diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt index 11ddb47951b..4a755890cd9 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt @@ -221,6 +221,7 @@ class ConeTypeVariableTypeConstructor(val debugName: String) : ConeClassifierLoo abstract class ConeIntegerLiteralType( val value: Long, + val isUnsigned: Boolean, override val nullability: ConeNullability ) : ConeSimpleKotlinType(), TypeConstructorMarker { abstract val possibleTypes: Collection diff --git a/compiler/fir/dump/src/org/jetbrains/kotlin/fir/dump/HtmlFirDump.kt b/compiler/fir/dump/src/org/jetbrains/kotlin/fir/dump/HtmlFirDump.kt index a6c78663016..05f698edf8e 100644 --- a/compiler/fir/dump/src/org/jetbrains/kotlin/fir/dump/HtmlFirDump.kt +++ b/compiler/fir/dump/src/org/jetbrains/kotlin/fir/dump/HtmlFirDump.kt @@ -784,6 +784,10 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver +value.toString() keyword("L") } + FirConstKind.UnsignedLong -> { + +value.toString() + keyword("UL") + } FirConstKind.Float -> { +value.toString() keyword("F") diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt index 1205db8421c..40c41a1de05 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt @@ -145,14 +145,21 @@ private fun FirConstKind<*>.toIrConstKind(): IrConstKind<*> = when (this) { FirConstKind.Null -> IrConstKind.Null FirConstKind.Boolean -> IrConstKind.Boolean FirConstKind.Char -> IrConstKind.Char + FirConstKind.Byte -> IrConstKind.Byte FirConstKind.Short -> IrConstKind.Short FirConstKind.Int -> IrConstKind.Int FirConstKind.Long -> IrConstKind.Long + + FirConstKind.UnsignedByte -> IrConstKind.Byte + FirConstKind.UnsignedShort -> IrConstKind.Short + FirConstKind.UnsignedInt -> IrConstKind.Int + FirConstKind.UnsignedLong -> IrConstKind.Long + FirConstKind.String -> IrConstKind.String FirConstKind.Float -> IrConstKind.Float FirConstKind.Double -> IrConstKind.Double - FirConstKind.IntegerLiteral -> throw IllegalArgumentException() + FirConstKind.IntegerLiteral, FirConstKind.UnsignedIntegerLiteral -> throw IllegalArgumentException() } internal fun FirClass<*>.collectCallableNamesFromSupertypes(session: FirSession, result: MutableList = mutableListOf()): List { diff --git a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt index cb1d68b80df..a85edd7c6ae 100644 --- a/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt +++ b/compiler/fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt @@ -224,9 +224,15 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte ) } - hasLongSuffix(text) || hasUnsignedSuffix(text) || hasUnsignedLongSuffix(text) -> { + hasUnsignedLongSuffix(text) -> { + FirConstKind.UnsignedLong + } + hasLongSuffix(text) -> { FirConstKind.Long } + hasUnsignedSuffix(text) -> { + FirConstKind.UnsignedIntegerLiteral + } else -> { FirConstKind.IntegerLiteral diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt index 8fd14717924..f2fe5340ec7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt @@ -58,10 +58,13 @@ fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession) @Suppress("USELESS_CAST") // TODO: remove once fixed: https://youtrack.jetbrains.com/issue/KT-35635 scopeSession.getOrBuild( - FirIntegerLiteralTypeScope.ILT_SYMBOL, + when { + isUnsigned -> FirIntegerLiteralTypeScope.ILTKey.Unsigned + else -> FirIntegerLiteralTypeScope.ILTKey.Signed + }, FirIntegerLiteralTypeScope.SCOPE_SESSION_KEY ) { - FirIntegerLiteralTypeScope(useSiteSession) + FirIntegerLiteralTypeScope(useSiteSession, isUnsigned) } as FirScope } else -> null diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralTypeApproximationTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralTypeApproximationTransformer.kt index a13f5f489b2..3b2e826d497 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralTypeApproximationTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralTypeApproximationTransformer.kt @@ -116,16 +116,6 @@ class IntegerLiteralTypeApproximationTransformer( } } -fun ConeClassLikeType.toConstKind(): FirConstKind<*> { - return when (classId) { - StandardClassIds.Int -> FirConstKind.Int - StandardClassIds.Long -> FirConstKind.Long - StandardClassIds.Short -> FirConstKind.Short - StandardClassIds.Byte -> FirConstKind.Byte - else -> throw IllegalStateException() - } -} - fun FirFunctionCall.getOriginalFunction(): FirCallableDeclaration<*>? { val symbol: AbstractFirBasedSymbol<*>? = when (val reference = calleeReference) { is FirResolvedNamedReference -> reference.resolvedSymbol @@ -148,7 +138,8 @@ class IntegerOperatorsTypeUpdater(val approximator: IntegerLiteralTypeApproximat return functionCall.transformExplicitReceiver(approximator, expectedType).compose() } // TODO: maybe unsafe? - val receiverValue = functionCall.explicitReceiver!!.typeRef.coneTypeSafe()?.value ?: return functionCall.compose() + val receiverType = functionCall.explicitReceiver!!.typeRef.coneTypeSafe() ?: return functionCall.compose() + val receiverValue = receiverType.value val kind = function.kind val resultValue = when { kind.unary -> when (kind) { @@ -193,7 +184,7 @@ class IntegerOperatorsTypeUpdater(val approximator: IntegerLiteralTypeApproximat } } } - functionCall.replaceTypeRef(functionCall.resultType.resolvedTypeFromPrototype(ConeIntegerLiteralTypeImpl(resultValue))) + functionCall.replaceTypeRef(functionCall.resultType.resolvedTypeFromPrototype(ConeIntegerLiteralTypeImpl(resultValue, isUnsigned = receiverType.isUnsigned))) return functionCall.toOperatorCall().compose() } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index 96b446abab5..923c21acfcf 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -504,44 +504,51 @@ class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransformer) : data: ResolutionMode, ): CompositeTransformResult { constExpression.annotations.forEach { it.accept(this, data) } - val kind = constExpression.kind - val symbol = when (kind) { - FirConstKind.Null -> StandardClassIds.Nothing(symbolProvider) - FirConstKind.Boolean -> StandardClassIds.Boolean(symbolProvider) - FirConstKind.Char -> StandardClassIds.Char(symbolProvider) - FirConstKind.Byte -> StandardClassIds.Byte(symbolProvider) - FirConstKind.Short -> StandardClassIds.Short(symbolProvider) - FirConstKind.Int -> StandardClassIds.Int(symbolProvider) - FirConstKind.Long -> StandardClassIds.Long(symbolProvider) - FirConstKind.String -> StandardClassIds.String(symbolProvider) - FirConstKind.Float -> StandardClassIds.Float(symbolProvider) - FirConstKind.Double -> StandardClassIds.Double(symbolProvider) - FirConstKind.IntegerLiteral -> null + fun constructLiteralType(classId: ClassId, isNullable: Boolean = false): ConeKotlinType { + val symbol = symbolProvider.getClassLikeSymbolByFqName(classId) ?: return ConeClassErrorType("Missing stdlib class: ${classId}") + return symbol.toLookupTag().constructClassType(emptyArray(), isNullable) } - val type = if (symbol != null) { - ConeClassLikeTypeImpl(symbol.toLookupTag(), emptyArray(), isNullable = kind == FirConstKind.Null) - } else { - val integerLiteralType = ConeIntegerLiteralTypeImpl(constExpression.value as Long) - val expectedType = data.expectedType?.coneTypeSafe() - if (expectedType != null) { - val approximatedType = integerLiteralType.getApproximatedType(expectedType) - val newConstKind = approximatedType.toConstKind() - if (newConstKind == null) { - constExpression.replaceKind(FirConstKind.Int as FirConstKind) - dataFlowAnalyzer.exitConstExpresion(constExpression as FirConstExpression<*>) - constExpression.resultType = buildErrorTypeRef { - source = constExpression.source - diagnostic = FirTypeMismatchError(expectedType, integerLiteralType.getApproximatedType()) + val kind = constExpression.kind + val type = when (kind) { + FirConstKind.Null -> session.builtinTypes.nullableNothingType.type + FirConstKind.Boolean -> session.builtinTypes.booleanType.type + FirConstKind.Char -> constructLiteralType(StandardClassIds.Char) + FirConstKind.Byte -> constructLiteralType(StandardClassIds.Byte) + FirConstKind.Short -> constructLiteralType(StandardClassIds.Short) + FirConstKind.Int -> constructLiteralType(StandardClassIds.Int) + FirConstKind.Long -> constructLiteralType(StandardClassIds.Long) + FirConstKind.String -> constructLiteralType(StandardClassIds.String) + FirConstKind.Float -> constructLiteralType(StandardClassIds.Float) + FirConstKind.Double -> constructLiteralType(StandardClassIds.Double) + FirConstKind.IntegerLiteral, FirConstKind.UnsignedIntegerLiteral -> { + val integerLiteralType = ConeIntegerLiteralTypeImpl(constExpression.value as Long, isUnsigned = kind == FirConstKind.UnsignedIntegerLiteral) + val expectedType = data.expectedType?.coneTypeSafe() + if (expectedType != null) { + val approximatedType = integerLiteralType.getApproximatedType(expectedType) + val newConstKind = approximatedType.toConstKind() + if (newConstKind == null) { + constExpression.replaceKind(FirConstKind.Int as FirConstKind) + dataFlowAnalyzer.exitConstExpresion(constExpression as FirConstExpression<*>) + constExpression.resultType = buildErrorTypeRef { + source = constExpression.source + diagnostic = FirTypeMismatchError(expectedType, integerLiteralType.getApproximatedType()) + } + return constExpression.compose() } - return constExpression.compose() + constExpression.replaceKind(newConstKind as FirConstKind) + approximatedType + } else { + integerLiteralType } - constExpression.replaceKind(newConstKind as FirConstKind) - approximatedType - } else { - integerLiteralType } + + FirConstKind.UnsignedByte -> constructLiteralType(StandardClassIds.UByte) + FirConstKind.UnsignedShort -> constructLiteralType(StandardClassIds.UShort) + FirConstKind.UnsignedInt -> constructLiteralType(StandardClassIds.UInt) + FirConstKind.UnsignedLong -> constructLiteralType(StandardClassIds.ULong) } + dataFlowAnalyzer.exitConstExpresion(constExpression as FirConstExpression<*>) constExpression.resultType = constExpression.resultType.resolvedTypeFromPrototype(type) return constExpression.compose() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerLiteralTypeScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerLiteralTypeScope.kt index f7407cf1d92..91d15a9bd98 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerLiteralTypeScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerLiteralTypeScope.kt @@ -19,9 +19,7 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirSimpleFunctionImpl import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.resolve.scopeSessionKey import org.jetbrains.kotlin.fir.scopes.FirScope -import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol import org.jetbrains.kotlin.fir.symbols.CallableId -import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralType import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralTypeImpl @@ -32,45 +30,19 @@ import org.jetbrains.kotlin.fir.visitors.FirVisitor import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.util.OperatorNameConventions -private object FirIntegerLiteralTypeClassifierSymbol : FirClassifierSymbol() { - override fun toLookupTag(): ConeClassifierLookupTag { - throw IllegalStateException("Should not be called") - } -} -private object FirIntegerLiteralTypeClassifier : FirDeclaration, FirSymbolOwner { - override val symbol: AbstractFirBasedSymbol - get() = FirIntegerLiteralTypeClassifierSymbol - - override val source: FirSourceElement? get() = throw IllegalStateException("Should not be called") - override val session: FirSession get() = throw IllegalStateException("Should not be called") - override val resolvePhase: FirResolvePhase get() = throw IllegalStateException("Should not be called") - - override fun accept(visitor: FirVisitor, data: D): R { - throw IllegalStateException("Should not be called") +class FirIntegerLiteralTypeScope(private val session: FirSession, val isUnsigned: Boolean) : FirScope() { + sealed class ILTKey { + object Signed : ILTKey() + object Unsigned : ILTKey() } - override fun replaceResolvePhase(newResolvePhase: FirResolvePhase) { - throw IllegalStateException("Should not be called") - } - - override fun acceptChildren(visitor: FirVisitor, data: D) { - throw IllegalStateException("Should not be called") - } - - override fun transformChildren(transformer: FirTransformer, data: D): FirElement { - throw IllegalStateException("Should not be called") - } -} - -class FirIntegerLiteralTypeScope(private val session: FirSession) : FirScope() { companion object { val BINARY_OPERATOR_NAMES = FirIntegerOperator.Kind.values().filterNot { it.unary }.map { it.operatorName } val UNARY_OPERATOR_NAMES = FirIntegerOperator.Kind.values().filter { it.unary }.map { it.operatorName } private val ALL_OPERATORS = FirIntegerOperator.Kind.values().map { it.operatorName to it }.toMap() - val ILT_SYMBOL: FirClassifierSymbol<*> = FirIntegerLiteralTypeClassifierSymbol - val SCOPE_SESSION_KEY = scopeSessionKey, FirIntegerLiteralTypeScope>() + val SCOPE_SESSION_KEY = scopeSessionKey() } private val BINARY_OPERATOR_SYMBOLS = BINARY_OPERATOR_NAMES.map { name -> @@ -80,7 +52,7 @@ class FirIntegerLiteralTypeScope(private val session: FirSession) : FirScope() { valueParameters += buildValueParameter { source = null session = this@FirIntegerLiteralTypeScope.session - returnTypeRef = FirILTTypeRefPlaceHolder() + returnTypeRef = FirILTTypeRefPlaceHolder(isUnsigned) this.name = valueParameterName symbol = FirVariableSymbol(valueParameterName) defaultValue = null @@ -100,7 +72,7 @@ class FirIntegerLiteralTypeScope(private val session: FirSession) : FirScope() { private fun createFirFunction(name: Name, symbol: FirNamedFunctionSymbol): FirSimpleFunctionImpl = FirIntegerOperator( source = null, session, - FirILTTypeRefPlaceHolder(), + FirILTTypeRefPlaceHolder(isUnsigned), receiverTypeRef = null, ALL_OPERATORS.getValue(name), FirResolvedDeclarationStatusImpl(Visibilities.PUBLIC, FirEffectiveVisibility.Public, Modality.FINAL), @@ -166,10 +138,10 @@ class FirIntegerOperator @FirImplementationDetail constructor( } } -class FirILTTypeRefPlaceHolder : FirResolvedTypeRef() { +class FirILTTypeRefPlaceHolder(isUnsigned: Boolean) : FirResolvedTypeRef() { override val source: FirSourceElement? get() = null override val annotations: List get() = emptyList() - override var type: ConeIntegerLiteralType = ConeIntegerLiteralTypeImpl(0) + override var type: ConeIntegerLiteralType = ConeIntegerLiteralTypeImpl(0, isUnsigned) override val delegatedTypeRef: FirTypeRef? get() = null override fun acceptChildren(visitor: FirVisitor, data: D) {} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt index 71d27fd3591..14f9402f728 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt @@ -146,7 +146,7 @@ fun T.withNullability(nullability: ConeNullability, typeCon ConeNullability.NULLABLE -> original.withNullability(nullability) ConeNullability.UNKNOWN -> original.withNullability(nullability) } - is ConeIntegerLiteralType -> ConeIntegerLiteralTypeImpl(value, nullability) + is ConeIntegerLiteralType -> ConeIntegerLiteralTypeImpl(value, isUnsigned, nullability) else -> error("sealed: ${this::class}") } as T } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirConstKind.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirConstKind.kt index a767b7de6f9..02a5d8ce6bd 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirConstKind.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/FirConstKind.kt @@ -9,14 +9,23 @@ sealed class FirConstKind(val asString: kotlin.String) { object Null : FirConstKind("Null") object Boolean : FirConstKind("Boolean") object Char : FirConstKind("Char") + object Byte : FirConstKind("Byte") + object UnsignedByte : FirConstKind("UByte") object Short : FirConstKind("Short") + object UnsignedShort : FirConstKind("UShort") object Int : FirConstKind("Int") + object UnsignedInt : FirConstKind("UInt") object Long : FirConstKind("Long") + object UnsignedLong : FirConstKind("ULong") + object String : FirConstKind("String") + object Float : FirConstKind("Float") object Double : FirConstKind("Double") + object IntegerLiteral : FirConstKind("IntegerLiteral") + object UnsignedIntegerLiteral : FirConstKind("UnsignedIntegerLiteral") override fun toString() = asString } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt index d6e92a2a6d2..d6d4cd780b0 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.types.model.SimpleTypeMarker class ConeIntegerLiteralTypeImpl : ConeIntegerLiteralType { override val possibleTypes: Collection - constructor(value: Long, nullability: ConeNullability = ConeNullability.NOT_NULL) : super(value, nullability) { + constructor(value: Long, isUnsigned: Boolean, nullability: ConeNullability = ConeNullability.NOT_NULL) : super(value, isUnsigned, nullability) { possibleTypes = mutableListOf() fun checkBoundsAndAddPossibleType(classId: ClassId, range: LongRange) { @@ -30,15 +30,26 @@ class ConeIntegerLiteralTypeImpl : ConeIntegerLiteralType { checkBoundsAndAddPossibleType(StandardClassIds.Short, SHORT_RANGE) } - addSignedPossibleTypes() - // TODO: add support of unsigned types + fun addUnsignedPossibleType() { + checkBoundsAndAddPossibleType(StandardClassIds.UInt, UINT_RANGE) + possibleTypes += createType(StandardClassIds.ULong) + checkBoundsAndAddPossibleType(StandardClassIds.UByte, UBYTE_RANGE) + checkBoundsAndAddPossibleType(StandardClassIds.UShort, USHORT_RANGE) + } + + if (isUnsigned) { + addUnsignedPossibleType() + } else { + addSignedPossibleTypes() + } } private constructor( value: Long, possibleTypes: Collection, + isUnsigned: Boolean, nullability: ConeNullability = ConeNullability.NOT_NULL - ) : super(value, nullability) { + ) : super(value, isUnsigned, nullability) { this.possibleTypes = possibleTypes } @@ -68,6 +79,10 @@ class ConeIntegerLiteralTypeImpl : ConeIntegerLiteralType { private val BYTE_RANGE = Byte.MIN_VALUE.toLong()..Byte.MAX_VALUE.toLong() private val SHORT_RANGE = Short.MIN_VALUE.toLong()..Short.MAX_VALUE.toLong() + private val UBYTE_RANGE = UByte.MIN_VALUE.toLong()..UByte.MAX_VALUE.toLong() + private val USHORT_RANGE = UShort.MIN_VALUE.toLong()..UShort.MAX_VALUE.toLong() + private val UINT_RANGE = UInt.MIN_VALUE.toLong()..UInt.MAX_VALUE.toLong() + private val COMPARABLE_TAG = ConeClassLikeLookupTagImpl(StandardClassIds.Comparable) fun findCommonSuperType(types: Collection): SimpleTypeMarker? { @@ -114,7 +129,7 @@ class ConeIntegerLiteralTypeImpl : ConeIntegerLiteralType { Mode.COMMON_SUPER_TYPE -> left.possibleTypes intersect right.possibleTypes Mode.INTERSECTION_TYPE -> left.possibleTypes union right.possibleTypes } - return ConeIntegerLiteralTypeImpl(left.value, possibleTypes) + return ConeIntegerLiteralTypeImpl(left.value, possibleTypes, left.isUnsigned) } private fun fold(left: ConeIntegerLiteralType, right: SimpleTypeMarker): SimpleTypeMarker? = diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirTypeUtils.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirTypeUtils.kt index 4f3eb162a8d..d61f7917af5 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirTypeUtils.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/FirTypeUtils.kt @@ -59,5 +59,10 @@ fun ConeClassLikeType.toConstKind(): FirConstKind<*>? = when (lookupTag.classId) StandardClassIds.Short -> FirConstKind.Short StandardClassIds.Int -> FirConstKind.Int StandardClassIds.Long -> FirConstKind.Long + + StandardClassIds.UInt -> FirConstKind.UnsignedInt + StandardClassIds.ULong -> FirConstKind.UnsignedLong + StandardClassIds.UShort -> FirConstKind.UnsignedShort + StandardClassIds.UByte -> FirConstKind.UnsignedByte else -> null }