[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
@@ -203,6 +203,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.UNSIGNED_LITERAL_WITHOUT_DECLARATIONS_ON_CLASSPATH) { firDiagnostic ->
UnsignedLiteralWithoutDeclarationsOnClasspathImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirErrors.DIVISION_BY_ZERO) { firDiagnostic ->
DivisionByZeroImpl(
firDiagnostic as KtPsiDiagnostic,
@@ -179,6 +179,10 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
override val diagnosticClass get() = WrongLongSuffix::class
}
abstract class UnsignedLiteralWithoutDeclarationsOnClasspath : KtFirDiagnostic<KtElement>() {
override val diagnosticClass get() = UnsignedLiteralWithoutDeclarationsOnClasspath::class
}
abstract class DivisionByZero : KtFirDiagnostic<KtExpression>() {
override val diagnosticClass get() = DivisionByZero::class
}
@@ -201,6 +201,11 @@ internal class WrongLongSuffixImpl(
override val token: KtLifetimeToken,
) : KtFirDiagnostic.WrongLongSuffix(), KtAbstractFirDiagnostic<KtElement>
internal class UnsignedLiteralWithoutDeclarationsOnClasspathImpl(
override val firDiagnostic: KtPsiDiagnostic,
override val token: KtLifetimeToken,
) : KtFirDiagnostic.UnsignedLiteralWithoutDeclarationsOnClasspath(), KtAbstractFirDiagnostic<KtElement>
internal class DivisionByZeroImpl(
override val firDiagnostic: KtPsiDiagnostic,
override val token: KtLifetimeToken,
@@ -368,6 +368,7 @@ internal object FirCompileTimeConstantEvaluator {
ConstantValueKind.UnsignedShort -> value.toLong().toUShort()
ConstantValueKind.UnsignedInt -> value.toLong().toUInt()
ConstantValueKind.UnsignedLong -> value.toLong().toULong()
ConstantValueKind.UnsignedIntegerLiteral -> value.toLong().toULong()
else -> null
}
}