[FIR] KT-54220: Don't crash on unsigned integers when no stdlib present

^KT-54220 Fixed
This commit is contained in:
Nikolay Lunyak
2022-11-04 09:57:09 +02:00
parent b03e14f565
commit 267ce1d892
23 changed files with 128 additions and 7 deletions
@@ -87,6 +87,7 @@ enum class DiagnosticKind {
IntLiteralOutOfRange,
FloatLiteralOutOfRange,
WrongLongSuffix,
UnsignedNumbersAreNotPresent,
IsEnumEntry,
EnumEntryAsType,
@@ -5,6 +5,8 @@
package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.isLong
import org.jetbrains.kotlin.fir.isULong
import org.jetbrains.kotlin.name.StandardClassIds
@@ -38,6 +40,7 @@ class ConeIntegerLiteralConstantTypeImpl(
fun create(
value: Long,
isUnsigned: Boolean,
isTypePresent: (ConeClassLikeType) -> Boolean,
nullability: ConeNullability = ConeNullability.NOT_NULL
): ConeSimpleKotlinType {
val possibleTypes = mutableListOf<ConeClassLikeType>()
@@ -64,6 +67,9 @@ class ConeIntegerLiteralConstantTypeImpl(
if (isUnsigned) {
addUnsignedPossibleType()
if (possibleTypes.any { !isTypePresent(it) }) {
return ConeErrorType(ConeSimpleDiagnostic("Unsigned integers need stdlib", DiagnosticKind.UnsignedNumbersAreNotPresent))
}
} else {
addSignedPossibleTypes()
}