Handle case when u-literals are using without unsigned declarations

This commit is contained in:
Mikhail Zarechenskiy
2018-05-28 17:30:42 +03:00
parent 8cd2d2e44c
commit 0da3ae328e
10 changed files with 71 additions and 9 deletions
@@ -885,6 +885,8 @@ public interface Errors {
DiagnosticFactory1<KtElement, KtElement> ILLEGAL_ESCAPE = DiagnosticFactory1.create(ERROR, CUT_CHAR_QUOTES);
DiagnosticFactory1<KtConstantExpression, KotlinType> NULL_FOR_NONNULL_TYPE = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<KtEscapeStringTemplateEntry> ILLEGAL_ESCAPE_SEQUENCE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtConstantExpression> UNSIGNED_LITERAL_WITHOUT_DECLARATIONS_ON_CLASSPATH = DiagnosticFactory0.create(ERROR);
// Casts and is-checks
@@ -382,6 +382,7 @@ public class DefaultErrorMessages {
MAP.put(RESOLUTION_TO_CLASSIFIER, "{2}", NAME, TO_STRING, STRING);
MAP.put(NOT_A_CLASS, "Not a class");
MAP.put(ILLEGAL_ESCAPE_SEQUENCE, "Illegal escape sequence");
MAP.put(UNSIGNED_LITERAL_WITHOUT_DECLARATIONS_ON_CLASSPATH, "Type of the constant expression cannot be resolved. Please make sure you have the required dependencies for unsigned types in the classpath");
MAP.put(RESERVED_SYNTAX_IN_CALLABLE_REFERENCE_LHS, "Left-hand side of callable reference matches expression syntax reserved for future releases");
@@ -935,7 +935,7 @@ private class ConstantExpressionEvaluatorVisitor(
expectedType: KotlinType
): CompileTimeConstant<*>? {
if (TypeUtils.noExpectedType(expectedType) || expectedType.isError) {
return IntegerValueTypeConstant(value, constantExpressionEvaluator.module, parameters)
return createIntegerValueTypeConstant(value, constantExpressionEvaluator.module, parameters)
}
val integerValue = ConstantValueFactory.createIntegerConstantValue(value, expectedType, parameters.isUnsigned)
if (integerValue != null) {
@@ -206,7 +206,13 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
expression, context.trace, context.expectedType
);
if (!(compileTimeConstant instanceof IntegerValueTypeConstant)) {
if (compileTimeConstant instanceof UnsignedErrorValueTypeConstant) {
ErrorValue.ErrorValueWithMessage value = ((UnsignedErrorValueTypeConstant) compileTimeConstant).getErrorValue();
context.trace.report(Errors.UNSIGNED_LITERAL_WITHOUT_DECLARATIONS_ON_CLASSPATH.on(expression));
return TypeInfoFactoryKt.createTypeInfo(value.getType(components.moduleDescriptor), context);
}
else if (!(compileTimeConstant instanceof IntegerValueTypeConstant)) {
CompileTimeConstantChecker constantChecker = new CompileTimeConstantChecker(context, components.moduleDescriptor, false);
ConstantValue constantValue =
compileTimeConstant != null ? ((TypedCompileTimeConstant) compileTimeConstant).getConstantValue() : null;