diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/CompileTimeConstantResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/CompileTimeConstantResolver.java index 1f7340bf7e1..312febc7ea6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/CompileTimeConstantResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/CompileTimeConstantResolver.java @@ -81,7 +81,7 @@ public class CompileTimeConstantResolver { if (value == null) { return OUT_OF_RANGE; } - if (noExpectedType(expectedType)) { + if (noExpectedTypeOrUnitOrError(expectedType)) { if (Integer.MIN_VALUE <= value && value <= Integer.MAX_VALUE) { return new IntValue(value.intValue()); } @@ -166,7 +166,7 @@ public class CompileTimeConstantResolver { @NotNull public CompileTimeConstant getFloatValue(@NotNull String text, @NotNull JetType expectedType) { - if (noExpectedType(expectedType) + if (noExpectedTypeOrUnitOrError(expectedType) || JetTypeChecker.INSTANCE.isSubtypeOf(builtIns.getDoubleType(), expectedType)) { try { return new DoubleValue(Double.parseDouble(text)); @@ -190,7 +190,7 @@ public class CompileTimeConstantResolver { @Nullable private CompileTimeConstant checkNativeType(String text, JetType expectedType, String title, JetType nativeType) { - if (!noExpectedType(expectedType) + if (!noExpectedTypeOrUnitOrError(expectedType) && !JetTypeChecker.INSTANCE.isSubtypeOf(nativeType, expectedType)) { return new ErrorValue("A " + title + " literal " + text + " does not conform to the expected type " + expectedType); } @@ -300,13 +300,13 @@ public class CompileTimeConstantResolver { @NotNull public CompileTimeConstant getNullValue(@NotNull JetType expectedType) { - if (noExpectedType(expectedType) || expectedType.isNullable()) { + if (noExpectedTypeOrUnitOrError(expectedType) || expectedType.isNullable()) { return NullValue.NULL; } return new ErrorValue("Null can not be a value of a non-null type " + expectedType); } - private boolean noExpectedType(JetType expectedType) { + private static boolean noExpectedTypeOrUnitOrError(JetType expectedType) { return TypeUtils.noExpectedType(expectedType) || KotlinBuiltIns.getInstance().isUnit(expectedType) || ErrorUtils.isErrorType(expectedType); } }