Merge ConstantExpressionEvaluator and CompileTimeConstantResolver
This commit is contained in:
@@ -244,10 +244,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
try {
|
||||
if (selector instanceof JetExpression) {
|
||||
JetExpression expression = (JetExpression) selector;
|
||||
CompileTimeConstant<?> constant = bindingContext.get(BindingContext.COMPILE_TIME_VALUE, expression);
|
||||
if (constant != null) {
|
||||
return StackValue.constant(constant.getValue(), expressionType(expression));
|
||||
}
|
||||
JavaClassDescriptor samInterface = bindingContext.get(CodegenBinding.SAM_VALUE, expression);
|
||||
if (samInterface != null) {
|
||||
return genSamInterfaceValue(expression, samInterface, visitor);
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowInstructionsGenerator
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.LocalFunctionDeclarationInstruction;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.Pseudocode;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.PseudocodeImpl;
|
||||
import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -581,8 +582,7 @@ public class JetControlFlowProcessor {
|
||||
}
|
||||
boolean conditionIsTrueConstant = false;
|
||||
if (condition instanceof JetConstantExpression && condition.getNode().getElementType() == JetNodeTypes.BOOLEAN_CONSTANT) {
|
||||
if (BooleanValue.TRUE == new CompileTimeConstantResolver().getBooleanValue(
|
||||
(JetConstantExpression) condition, KotlinBuiltIns.getInstance().getBooleanType())) {
|
||||
if (BooleanValue.TRUE == ConstantExpressionEvaluator.object$.evaluate(condition, trace, KotlinBuiltIns.getInstance().getBooleanType())) {
|
||||
conditionIsTrueConstant = true;
|
||||
}
|
||||
}
|
||||
|
||||
+28
-21
@@ -34,6 +34,7 @@ import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import java.lang.Short as JShort
|
||||
import java.lang.Byte as JByte
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument
|
||||
import org.jetbrains.jet.JetNodeTypes
|
||||
|
||||
[suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")]
|
||||
public class ConstantExpressionEvaluator private (val trace: BindingTrace) : JetVisitor<CompileTimeConstant<*>, JetType>() {
|
||||
@@ -71,7 +72,19 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
}
|
||||
|
||||
override fun visitConstantExpression(expression: JetConstantExpression, expectedType: JetType?): CompileTimeConstant<*>? {
|
||||
return trace.get(BindingContext.COMPILE_TIME_VALUE, expression)
|
||||
val text = expression.getText()
|
||||
if (text == null) return null
|
||||
val result: Any? = when (expression.getNode().getElementType()) {
|
||||
JetNodeTypes.INTEGER_CONSTANT -> CompileTimeConstantResolver.parseLongValue(text)
|
||||
JetNodeTypes.FLOAT_CONSTANT -> CompileTimeConstantResolver.parseDoubleValue(text)
|
||||
JetNodeTypes.BOOLEAN_CONSTANT -> CompileTimeConstantResolver.parseBooleanValue(text)
|
||||
JetNodeTypes.CHARACTER_CONSTANT -> CompileTimeConstantResolver.parseCharValue(text)
|
||||
JetNodeTypes.NULL -> null
|
||||
else -> throw IllegalArgumentException("Unsupported constant: " + expression)
|
||||
}
|
||||
if (result == null && expression.getNode().getElementType() == JetNodeTypes.NULL) return NullValue.NULL
|
||||
|
||||
return createCompileTimeConstant(result, expectedType)
|
||||
}
|
||||
|
||||
override fun visitParenthesizedExpression(expression: JetParenthesizedExpression, expectedType: JetType?): CompileTimeConstant<*>? {
|
||||
@@ -164,7 +177,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
else if (argumentsEntrySet.size() == 1) {
|
||||
val (parameter, argument) = argumentsEntrySet.first()
|
||||
|
||||
val argumentForParameter = createOperationArgumentForFristParameter(argument, parameter)
|
||||
val argumentForParameter = createOperationArgumentForFirstParameter(argument, parameter)
|
||||
if (argumentForParameter == null) return null
|
||||
|
||||
val function = binaryOperations[BinaryOperationKey(argumentForReceiver.ctcType, argumentForParameter.ctcType, resultingDescriptorName)]
|
||||
@@ -258,7 +271,6 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
}
|
||||
|
||||
private fun resolveArguments(valueArguments: List<ValueArgument>, expectedType: JetType): List<CompileTimeConstant<*>> {
|
||||
//todo flatMap
|
||||
val constants = arrayListOf<CompileTimeConstant<*>>()
|
||||
for (argument in valueArguments) {
|
||||
val argumentExpression = argument.getArgumentExpression()
|
||||
@@ -298,7 +310,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
return OperationArgument(receiverValue, receiverCompileTimeType)
|
||||
}
|
||||
|
||||
private fun createOperationArgumentForFristParameter(argument: ResolvedValueArgument, parameter: ValueParameterDescriptor): OperationArgument? {
|
||||
private fun createOperationArgumentForFirstParameter(argument: ResolvedValueArgument, parameter: ValueParameterDescriptor): OperationArgument? {
|
||||
val argumentCompileTimeType = getCompileTimeType(parameter.getType())
|
||||
if (argumentCompileTimeType == null) return null
|
||||
|
||||
@@ -348,44 +360,39 @@ private fun createStringConstant(value: CompileTimeConstant<*>?): StringValue? {
|
||||
}
|
||||
}
|
||||
|
||||
private fun createCompileTimeConstant(value: Any?, expectedType: JetType?): CompileTimeConstant<*>? {
|
||||
public fun createCompileTimeConstant(value: Any?, expectedType: JetType?): CompileTimeConstant<*>? {
|
||||
return when(value) {
|
||||
null -> null
|
||||
is Byte, is Short, is Int, is Long -> getIntegerValue((value as Number).toLong(), expectedType ?: TypeUtils.NO_EXPECTED_TYPE)
|
||||
is Char -> CharValue(value)
|
||||
is Float -> if (CompileTimeConstantResolver.noExpectedTypeOrError(expectedType) ||
|
||||
expectedType == KotlinBuiltIns.getInstance().getDoubleType()) DoubleValue(value.toDouble())
|
||||
else FloatValue(value)
|
||||
is Float -> FloatValue(value)
|
||||
is Double -> DoubleValue(value)
|
||||
is Boolean -> if (value) BooleanValue.TRUE else BooleanValue.FALSE
|
||||
is Boolean -> BooleanValue.valueOf(value)
|
||||
is String -> StringValue(value)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun getIntegerValue(value: Long, expectedType: JetType): CompileTimeConstant<*>? {
|
||||
if (CompileTimeConstantResolver.noExpectedTypeOrError(expectedType)) {
|
||||
if (Integer.MIN_VALUE <= value && value <= Integer.MAX_VALUE) {
|
||||
return IntValue(value.toInt())
|
||||
}
|
||||
|
||||
return LongValue(value)
|
||||
}
|
||||
|
||||
fun defaultIntegerValue(value: Long) = when (value) {
|
||||
in Integer.MIN_VALUE..Integer.MAX_VALUE.toLong() -> IntValue(value.toInt())
|
||||
value.toInt().toLong() -> IntValue(value.toInt())
|
||||
else -> LongValue(value)
|
||||
}
|
||||
|
||||
if (CompileTimeConstantResolver.noExpectedTypeOrError(expectedType)) {
|
||||
return defaultIntegerValue(value)
|
||||
}
|
||||
|
||||
val builtIns = KotlinBuiltIns.getInstance()
|
||||
|
||||
return when (TypeUtils.makeNotNullable(expectedType)) {
|
||||
builtIns.getIntType() -> IntValue(value.toInt())
|
||||
builtIns.getLongType() -> LongValue(value)
|
||||
builtIns.getShortType() -> when (value) {
|
||||
in JShort.MIN_VALUE..JShort.MAX_VALUE.toLong() -> ShortValue(value.toShort())
|
||||
value.toShort().toLong() -> ShortValue(value.toShort())
|
||||
else -> defaultIntegerValue(value)
|
||||
}
|
||||
builtIns.getByteType() -> when (value) {
|
||||
in JByte.MIN_VALUE..JByte.MAX_VALUE.toLong() -> ByteValue(value.toByte())
|
||||
value.toByte().toLong() -> ByteValue(value.toByte())
|
||||
else -> defaultIntegerValue(value)
|
||||
}
|
||||
builtIns.getCharType() -> IntValue(value.toInt())
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ContextDependency;
|
||||
|
||||
+4
-6
@@ -22,15 +22,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.CallResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.CheckValueArgumentsMode;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallImpl;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantResolver;
|
||||
import org.jetbrains.jet.lang.resolve.constants.ErrorValue;
|
||||
import org.jetbrains.jet.lang.resolve.constants.NumberValueTypeConstructor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -299,11 +301,7 @@ public class ArgumentTypeResolver {
|
||||
}
|
||||
return;
|
||||
}
|
||||
CompileTimeConstant<?> constant =
|
||||
new CompileTimeConstantResolver().getCompileTimeConstant((JetConstantExpression) expression, numberType);
|
||||
|
||||
if (!(constant instanceof ErrorValue)) {
|
||||
context.trace.record(BindingContext.COMPILE_TIME_VALUE, expression, constant);
|
||||
}
|
||||
ConstantExpressionEvaluator.object$.evaluate(expression, context.trace, numberType);
|
||||
}
|
||||
}
|
||||
|
||||
+106
-201
@@ -16,19 +16,18 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.constants;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.jet.lang.psi.JetConstantExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
@@ -38,125 +37,74 @@ import java.util.Set;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
|
||||
public class CompileTimeConstantResolver {
|
||||
private static final Set<DiagnosticFactory> errorsThatDependOnExpectedType =
|
||||
Sets.<DiagnosticFactory>newHashSet(CONSTANT_EXPECTED_TYPE_MISMATCH, NULL_FOR_NONNULL_TYPE);
|
||||
|
||||
private final KotlinBuiltIns builtIns;
|
||||
private final BindingTrace trace;
|
||||
private final boolean checkOnlyErrorsThatDependOnExpectedType;
|
||||
|
||||
public CompileTimeConstantResolver() {
|
||||
public CompileTimeConstantResolver(@NotNull BindingTrace trace, boolean checkOnlyErrorsThatDependOnExpectedType) {
|
||||
this.checkOnlyErrorsThatDependOnExpectedType = checkOnlyErrorsThatDependOnExpectedType;
|
||||
this.builtIns = KotlinBuiltIns.getInstance();
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Diagnostic checkConstantExpressionType(
|
||||
@NotNull JetConstantExpression expression,
|
||||
@NotNull JetType expectedType
|
||||
) {
|
||||
CompileTimeConstant<?> compileTimeConstant = getCompileTimeConstant(expression, expectedType);
|
||||
Set<DiagnosticFactory> errorsThatDependOnExpectedType =
|
||||
Sets.<DiagnosticFactory>newHashSet(CONSTANT_EXPECTED_TYPE_MISMATCH, NULL_FOR_NONNULL_TYPE);
|
||||
|
||||
if (compileTimeConstant instanceof ErrorValueWithDiagnostic) {
|
||||
Diagnostic diagnostic = ((ErrorValueWithDiagnostic) compileTimeConstant).getDiagnostic();
|
||||
if (errorsThatDependOnExpectedType.contains(diagnostic.getFactory())) {
|
||||
return diagnostic;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompileTimeConstant<?> getCompileTimeConstant(
|
||||
@NotNull JetConstantExpression expression,
|
||||
@NotNull JetType expectedType
|
||||
) {
|
||||
// return true if there is an error
|
||||
public boolean checkConstantExpressionType(@NotNull JetConstantExpression expression, @NotNull JetType expectedType) {
|
||||
CompileTimeConstant<?> compileTimeConstant = ConstantExpressionEvaluator.object$.evaluate(expression, trace, expectedType);
|
||||
IElementType elementType = expression.getNode().getElementType();
|
||||
|
||||
CompileTimeConstant<?> value;
|
||||
if (elementType == JetNodeTypes.INTEGER_CONSTANT) {
|
||||
value = getIntegerValue(expression, expectedType);
|
||||
return checkIntegerValue(compileTimeConstant, expectedType, expression);
|
||||
}
|
||||
else if (elementType == JetNodeTypes.FLOAT_CONSTANT) {
|
||||
value = getFloatValue(expression, expectedType);
|
||||
return checkFloatValue(compileTimeConstant, expectedType, expression);
|
||||
}
|
||||
else if (elementType == JetNodeTypes.BOOLEAN_CONSTANT) {
|
||||
value = getBooleanValue(expression, expectedType);
|
||||
return checkBooleanValue(compileTimeConstant, expectedType, expression);
|
||||
}
|
||||
else if (elementType == JetNodeTypes.CHARACTER_CONSTANT) {
|
||||
value = getCharValue(expression, expectedType);
|
||||
return checkCharValue(compileTimeConstant, expectedType, expression);
|
||||
}
|
||||
else if (elementType == JetNodeTypes.NULL) {
|
||||
value = getNullValue(expression, expectedType);
|
||||
return checkNullValue(expectedType, expression);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unsupported constant: " + expression);
|
||||
}
|
||||
return value;
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompileTimeConstant<?> getIntegerValue(
|
||||
@NotNull JetConstantExpression expression, @NotNull JetType expectedType
|
||||
) {
|
||||
String text = expression.getText();
|
||||
return getIntegerValue(parseLongValue(text), expectedType, expression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompileTimeConstant<?> getIntegerValue(
|
||||
@Nullable Long value,
|
||||
private boolean checkIntegerValue(
|
||||
@Nullable CompileTimeConstant value,
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull JetConstantExpression expression
|
||||
) {
|
||||
if (value == null) {
|
||||
return createErrorValue(INT_LITERAL_OUT_OF_RANGE.on(expression));
|
||||
return reportError(INT_LITERAL_OUT_OF_RANGE.on(expression));
|
||||
}
|
||||
if (noExpectedTypeOrError(expectedType)) {
|
||||
if (Integer.MIN_VALUE <= value && value <= Integer.MAX_VALUE) {
|
||||
return new IntValue(value.intValue());
|
||||
}
|
||||
return new LongValue(value);
|
||||
}
|
||||
Function<Long, ? extends CompileTimeConstant<?>> create;
|
||||
long lowerBound;
|
||||
long upperBound;
|
||||
TypeConstructor constructor = expectedType.getConstructor();
|
||||
if (constructor == builtIns.getInt().getTypeConstructor()) {
|
||||
create = IntValue.CREATE;
|
||||
lowerBound = Integer.MIN_VALUE;
|
||||
upperBound = Integer.MAX_VALUE;
|
||||
}
|
||||
else if (constructor == builtIns.getLong().getTypeConstructor()) {
|
||||
create = LongValue.CREATE;
|
||||
lowerBound = Long.MIN_VALUE;
|
||||
upperBound = Long.MAX_VALUE;
|
||||
}
|
||||
else if (constructor == builtIns.getShort().getTypeConstructor()) {
|
||||
create = ShortValue.CREATE;
|
||||
lowerBound = Short.MIN_VALUE;
|
||||
upperBound = Short.MAX_VALUE;
|
||||
}
|
||||
else if (constructor == builtIns.getByte().getTypeConstructor()) {
|
||||
create = ByteValue.CREATE;
|
||||
lowerBound = Byte.MIN_VALUE;
|
||||
upperBound = Byte.MAX_VALUE;
|
||||
}
|
||||
else {
|
||||
JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
|
||||
JetType intType = builtIns.getIntType();
|
||||
JetType longType = builtIns.getLongType();
|
||||
if (typeChecker.isSubtypeOf(intType, expectedType)) {
|
||||
return getIntegerValue(value, intType, expression);
|
||||
}
|
||||
else if (typeChecker.isSubtypeOf(longType, expectedType)) {
|
||||
return getIntegerValue(value, longType, expression);
|
||||
}
|
||||
else {
|
||||
return createErrorValue(CONSTANT_EXPECTED_TYPE_MISMATCH.on(expression, "integer", expectedType));
|
||||
if (!noExpectedTypeOrError(expectedType)) {
|
||||
JetType valueType = value.getType(KotlinBuiltIns.getInstance());
|
||||
if (!JetTypeChecker.INSTANCE.isSubtypeOf(valueType, expectedType)) {
|
||||
return reportError(CONSTANT_EXPECTED_TYPE_MISMATCH.on(expression, "integer", expectedType));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value != null && lowerBound <= value && value <= upperBound) {
|
||||
return create.apply(value);
|
||||
public boolean checkFloatValue(
|
||||
@Nullable CompileTimeConstant value,
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull JetConstantExpression expression
|
||||
) {
|
||||
if (value == null) {
|
||||
return reportError(FLOAT_LITERAL_OUT_OF_RANGE.on(expression));
|
||||
}
|
||||
return createErrorValue(CONSTANT_EXPECTED_TYPE_MISMATCH.on(expression, "integer", expectedType));
|
||||
if (!noExpectedTypeOrError(expectedType)) {
|
||||
JetType valueType = value.getType(KotlinBuiltIns.getInstance());
|
||||
if (!JetTypeChecker.INSTANCE.isSubtypeOf(valueType, expectedType)) {
|
||||
return reportError(CONSTANT_EXPECTED_TYPE_MISMATCH.on(expression, "floating-point", expectedType));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -192,128 +140,107 @@ public class CompileTimeConstantResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompileTimeConstant<?> getFloatValue(
|
||||
@NotNull JetConstantExpression expression, @NotNull JetType expectedType
|
||||
) {
|
||||
String text = expression.getText();
|
||||
try {
|
||||
if (noExpectedTypeOrError(expectedType)
|
||||
|| JetTypeChecker.INSTANCE.isSubtypeOf(builtIns.getDoubleType(), expectedType)) {
|
||||
return new DoubleValue(Double.parseDouble(text));
|
||||
}
|
||||
else if (JetTypeChecker.INSTANCE.isSubtypeOf(builtIns.getFloatType(), expectedType)) {
|
||||
return new FloatValue(Float.parseFloat(text));
|
||||
}
|
||||
else {
|
||||
return createErrorValue(CONSTANT_EXPECTED_TYPE_MISMATCH.on(expression, "floating-point", expectedType));
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return createErrorValue(FLOAT_LITERAL_OUT_OF_RANGE.on(expression));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static CompileTimeConstant<?> checkNativeType(
|
||||
JetType expectedType,
|
||||
String title,
|
||||
JetType nativeType,
|
||||
JetConstantExpression expression
|
||||
) {
|
||||
if (!noExpectedTypeOrError(expectedType)
|
||||
&& !JetTypeChecker.INSTANCE.isSubtypeOf(nativeType, expectedType)) {
|
||||
|
||||
return createErrorValue(CONSTANT_EXPECTED_TYPE_MISMATCH.on(expression, title, expectedType));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompileTimeConstant<?> getBooleanValue(
|
||||
@NotNull JetConstantExpression expression, @NotNull JetType expectedType
|
||||
) {
|
||||
String text = expression.getText();
|
||||
CompileTimeConstant<?> error = checkNativeType(expectedType, "boolean", builtIns.getBooleanType(), expression);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
public static Object parseBooleanValue(@NotNull String text) {
|
||||
if ("true".equals(text)) {
|
||||
return BooleanValue.TRUE;
|
||||
return true;
|
||||
}
|
||||
else if ("false".equals(text)) {
|
||||
return BooleanValue.FALSE;
|
||||
return false;
|
||||
}
|
||||
throw new IllegalStateException("Must not happen. A boolean literal has text: " + text);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompileTimeConstant<?> getCharValue(
|
||||
@NotNull JetConstantExpression expression, @NotNull JetType expectedType
|
||||
private boolean checkBooleanValue(
|
||||
@Nullable CompileTimeConstant value,
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull JetConstantExpression expression
|
||||
) {
|
||||
String text = expression.getText();
|
||||
CompileTimeConstant<?> error = checkNativeType(expectedType, "character", builtIns.getCharType(), expression);
|
||||
if (error != null) {
|
||||
return error;
|
||||
if (!noExpectedTypeOrError(expectedType)
|
||||
&& !JetTypeChecker.INSTANCE.isSubtypeOf(builtIns.getBooleanType(), expectedType)) {
|
||||
return reportError(CONSTANT_EXPECTED_TYPE_MISMATCH.on(expression, "boolean", expectedType));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Character parseCharValue(@NotNull String text) {
|
||||
// Strip the quotes
|
||||
if (text.length() < 2 || text.charAt(0) != '\'' || text.charAt(text.length() - 1) != '\'') {
|
||||
return createErrorValue(INCORRECT_CHARACTER_LITERAL.on(expression));
|
||||
return null;
|
||||
}
|
||||
text = text.substring(1, text.length() - 1); // now there're no quotes
|
||||
|
||||
if (text.length() == 0) {
|
||||
return createErrorValue(EMPTY_CHARACTER_LITERAL.on(expression));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (text.charAt(0) != '\\') {
|
||||
// No escape
|
||||
if (text.length() == 1) {
|
||||
return new CharValue(text.charAt(0));
|
||||
return text.charAt(0);
|
||||
}
|
||||
return createErrorValue(TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL.on(expression, expression));
|
||||
}
|
||||
return escapedStringToCharValue(text, expression);
|
||||
return escapedStringToCharValue(text);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CompileTimeConstant<?> escapedStringToCharValue(
|
||||
@NotNull String text,
|
||||
@NotNull JetElement expression
|
||||
) {
|
||||
assert text.length() > 0 && text.charAt(0) == '\\' : "Only escaped sequences must be passed to this routine: " + text;
|
||||
@Nullable
|
||||
public static Character escapedStringToCharValue(@NotNull String text) {
|
||||
if (!(text.length() > 0 && text.charAt(0) == '\\')) return null;
|
||||
|
||||
// Escape
|
||||
String escape = text.substring(1); // strip the slash
|
||||
switch (escape.length()) {
|
||||
case 0:
|
||||
// bare slash
|
||||
return illegalEscape(expression);
|
||||
case 0: return null;
|
||||
case 1:
|
||||
// one-char escape
|
||||
Character escaped = translateEscape(escape.charAt(0));
|
||||
if (escaped == null) {
|
||||
return illegalEscape(expression);
|
||||
return null;
|
||||
}
|
||||
return new CharValue(escaped);
|
||||
return escaped;
|
||||
case 5:
|
||||
// unicode escape
|
||||
if (escape.charAt(0) == 'u') {
|
||||
try {
|
||||
Integer intValue = Integer.valueOf(escape.substring(1), 16);
|
||||
return new CharValue((char) intValue.intValue());
|
||||
return (char) intValue.intValue();
|
||||
} catch (NumberFormatException e) {
|
||||
// Will be reported below
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return illegalEscape(expression);
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static CompileTimeConstant<?> illegalEscape(@NotNull JetElement expression) {
|
||||
return createErrorValue(ILLEGAL_ESCAPE.on(expression, expression));
|
||||
private boolean checkCharValue(CompileTimeConstant<?> constant, JetType expectedType, JetConstantExpression expression) {
|
||||
String text = expression.getText();
|
||||
if (!noExpectedTypeOrError(expectedType)
|
||||
&& !JetTypeChecker.INSTANCE.isSubtypeOf(builtIns.getCharType(), expectedType)) {
|
||||
return reportError(CONSTANT_EXPECTED_TYPE_MISMATCH.on(expression, "character", expectedType));
|
||||
}
|
||||
|
||||
// Strip the quotes
|
||||
if (text.length() < 2 || text.charAt(0) != '\'' || text.charAt(text.length() - 1) != '\'') {
|
||||
return reportError(INCORRECT_CHARACTER_LITERAL.on(expression));
|
||||
}
|
||||
text = text.substring(1, text.length() - 1); // now there're no quotes
|
||||
|
||||
if (text.length() == 0) {
|
||||
return reportError(EMPTY_CHARACTER_LITERAL.on(expression));
|
||||
}
|
||||
|
||||
if (text.charAt(0) != '\\') {
|
||||
// No escape
|
||||
if (text.length() == 1) {
|
||||
return false;
|
||||
}
|
||||
return reportError(TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL.on(expression, expression));
|
||||
}
|
||||
if (constant == null) {
|
||||
return reportError(ILLEGAL_ESCAPE.on(expression, expression));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -339,44 +266,22 @@ public class CompileTimeConstantResolver {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CompileTimeConstant<?> getNullValue(@NotNull JetConstantExpression expression, @NotNull JetType expectedType) {
|
||||
if (noExpectedTypeOrError(expectedType) || expectedType.isNullable()) {
|
||||
return NullValue.NULL;
|
||||
public boolean checkNullValue(@NotNull JetType expectedType, @NotNull JetConstantExpression expression) {
|
||||
if (!noExpectedTypeOrError(expectedType) && !expectedType.isNullable()) {
|
||||
return reportError(NULL_FOR_NONNULL_TYPE.on(expression, expectedType));
|
||||
}
|
||||
return createErrorValue(NULL_FOR_NONNULL_TYPE.on(expression, expectedType));
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean noExpectedTypeOrError(JetType expectedType) {
|
||||
return TypeUtils.noExpectedType(expectedType) || expectedType.isError();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ErrorValue createErrorValue(@NotNull Diagnostic diagnostic) {
|
||||
return new ErrorValueWithDiagnostic(diagnostic);
|
||||
}
|
||||
|
||||
public static class ErrorValueWithDiagnostic extends ErrorValue {
|
||||
private final Diagnostic diagnostic;
|
||||
|
||||
public ErrorValueWithDiagnostic(@NotNull Diagnostic diagnostic) {
|
||||
this.diagnostic = diagnostic;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic getDiagnostic() {
|
||||
return diagnostic;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return DefaultErrorMessages.RENDERER.render(diagnostic);
|
||||
private boolean reportError(@NotNull Diagnostic diagnostic) {
|
||||
if (!checkOnlyErrorsThatDependOnExpectedType || errorsThatDependOnExpectedType.contains(diagnostic.getFactory())) {
|
||||
trace.report(diagnostic);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ public class DoubleValueTypeConstructor extends NumberValueTypeConstructor {
|
||||
// order of types matters
|
||||
// 'getPrimitiveNumberType' returns first of supertypes that is a subtype of expected type
|
||||
// for expected type 'Any' result type 'Double' should be returned
|
||||
supertypes = Lists.newArrayList(KotlinBuiltIns.getInstance().getDoubleType(), KotlinBuiltIns.getInstance().getFloatType());
|
||||
supertypes = Lists.newArrayList(KotlinBuiltIns.getInstance().getDoubleType());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+10
-30
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallExpressionResolver;
|
||||
@@ -71,7 +72,6 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getStaticNestedClassesScope;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.DEPENDENT;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.INDEPENDENT;
|
||||
import static org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantResolver.ErrorValueWithDiagnostic;
|
||||
import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
|
||||
@@ -134,7 +134,6 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
IElementType elementType = expression.getNode().getElementType();
|
||||
String text = expression.getNode().getText();
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
CompileTimeConstantResolver compileTimeConstantResolver = context.getCompileTimeConstantResolver();
|
||||
|
||||
if (noExpectedType(context.expectedType) && context.contextDependency == DEPENDENT) {
|
||||
if (elementType == JetNodeTypes.INTEGER_CONSTANT) {
|
||||
@@ -150,15 +149,13 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CompileTimeConstant<?> value = compileTimeConstantResolver.getCompileTimeConstant(expression, context.expectedType);
|
||||
if (value instanceof ErrorValue) {
|
||||
assert value instanceof ErrorValueWithDiagnostic;
|
||||
//noinspection CastConflictsWithInstanceof
|
||||
context.trace.report(((ErrorValueWithDiagnostic)value).getDiagnostic());
|
||||
CompileTimeConstantResolver compileTimeConstantResolver = context.getCompileTimeConstantResolver();
|
||||
boolean hasError = compileTimeConstantResolver.checkConstantExpressionType(expression, context.expectedType);
|
||||
if (hasError) {
|
||||
return JetTypeInfo.create(getDefaultType(elementType), context.dataFlowInfo);
|
||||
}
|
||||
context.trace.record(BindingContext.COMPILE_TIME_VALUE, expression, value);
|
||||
CompileTimeConstant<?> value = ConstantExpressionEvaluator.object$.evaluate(expression, context.trace, context.expectedType);
|
||||
assert value != null : "CompileTimeConstant should be evaluated for constant expression or an error should be recorded " + expression.getText();
|
||||
return DataFlowUtils.checkType(value.getType(builtIns), expression, context, context.dataFlowInfo);
|
||||
}
|
||||
|
||||
@@ -1173,10 +1170,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
@Override
|
||||
public JetTypeInfo visitStringTemplateExpression(@NotNull JetStringTemplateExpression expression, ExpressionTypingContext contextWithExpectedType) {
|
||||
final ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE).replaceContextDependency(INDEPENDENT);
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final boolean[] isCompileTimeValue = new boolean[] { true };
|
||||
final DataFlowInfo[] dataFlowInfo = new DataFlowInfo[] { context.dataFlowInfo };
|
||||
|
||||
for (JetStringTemplateEntry entry : expression.getEntries()) {
|
||||
entry.accept(new JetVisitorVoid() {
|
||||
|
||||
@@ -1187,32 +1181,18 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetTypeInfo typeInfo = facade.getTypeInfo(entryExpression, context.replaceDataFlowInfo(dataFlowInfo[0]));
|
||||
dataFlowInfo[0] = typeInfo.getDataFlowInfo();
|
||||
}
|
||||
isCompileTimeValue[0] = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLiteralStringTemplateEntry(@NotNull JetLiteralStringTemplateEntry entry) {
|
||||
builder.append(entry.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEscapeStringTemplateEntry(@NotNull JetEscapeStringTemplateEntry entry) {
|
||||
CompileTimeConstant<?> character = CompileTimeConstantResolver.escapedStringToCharValue(entry.getText(), entry);
|
||||
if (character instanceof ErrorValue) {
|
||||
assert character instanceof ErrorValueWithDiagnostic;
|
||||
//noinspection CastConflictsWithInstanceof
|
||||
context.trace.report(((ErrorValueWithDiagnostic) character).getDiagnostic());
|
||||
isCompileTimeValue[0] = false;
|
||||
}
|
||||
else {
|
||||
builder.append(((CharValue) character).getValue());
|
||||
Character character = CompileTimeConstantResolver.escapedStringToCharValue(entry.getText());
|
||||
if (character == null) {
|
||||
context.trace.report(Errors.ILLEGAL_ESCAPE.on(entry, entry));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (isCompileTimeValue[0]) {
|
||||
context.trace.record(BindingContext.COMPILE_TIME_VALUE, expression, new StringValue(builder.toString()));
|
||||
}
|
||||
ConstantExpressionEvaluator.object$.evaluate(expression, context.trace, contextWithExpectedType.expectedType);
|
||||
return DataFlowUtils.checkType(KotlinBuiltIns.getInstance().getStringType(), expression, contextWithExpectedType, dataFlowInfo[0]);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
@@ -166,11 +165,7 @@ public class DataFlowUtils {
|
||||
}
|
||||
|
||||
if (expression instanceof JetConstantExpression) {
|
||||
Diagnostic diagnostic =
|
||||
new CompileTimeConstantResolver().checkConstantExpressionType((JetConstantExpression) expression, expectedType);
|
||||
if (diagnostic != null) {
|
||||
trace.report(diagnostic);
|
||||
}
|
||||
new CompileTimeConstantResolver(trace, true).checkConstantExpressionType((JetConstantExpression) expression, expectedType);
|
||||
return expressionType;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
|
||||
|
||||
public CompileTimeConstantResolver getCompileTimeConstantResolver() {
|
||||
if (compileTimeConstantResolver == null) {
|
||||
compileTimeConstantResolver = new CompileTimeConstantResolver();
|
||||
compileTimeConstantResolver = new CompileTimeConstantResolver(trace, false);
|
||||
}
|
||||
return compileTimeConstantResolver;
|
||||
}
|
||||
|
||||
+2
-5
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallExpressionResolver;
|
||||
@@ -395,11 +396,7 @@ public class ExpressionTypingServices {
|
||||
if (defaultValue != null) {
|
||||
getType(declaringScope, defaultValue, valueParameterDescriptor.getType(), dataFlowInfo, trace);
|
||||
if (DescriptorUtils.isAnnotationClass(DescriptorUtils.getContainingClass(declaringScope))) {
|
||||
CompileTimeConstant<?> constant =
|
||||
AnnotationResolver.resolveExpressionToCompileTimeValue(defaultValue, valueParameterDescriptor.getType(), trace);
|
||||
if (constant != null) {
|
||||
trace.record(BindingContext.COMPILE_TIME_VALUE, defaultValue, constant);
|
||||
}
|
||||
ConstantExpressionEvaluator.object$.evaluate(defaultValue, trace, valueParameterDescriptor.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ val zbyte : Byte? = 3
|
||||
val zshort : Short? = 4
|
||||
val zchar : Char? = 'c'
|
||||
val zdouble : Double? = 1.0
|
||||
val zfloat : Float? = 2.0
|
||||
val zfloat : Float? = 2.0.toFloat()
|
||||
|
||||
fun box(): String {
|
||||
return "OK"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
object TestObject {
|
||||
val testFloat: Float = 0.9999
|
||||
val otherFloat: Float = 1.01
|
||||
val testFloat: Float = 0.9999.toFloat()
|
||||
val otherFloat: Float = 1.01.toFloat()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class Foo {
|
||||
class object {
|
||||
val i: Int = 2
|
||||
val s: Short = 2
|
||||
val f: Float = 2.0
|
||||
val f: Float = 2.0.toFloat()
|
||||
val d: Double = 2.0
|
||||
val l: Long = 2
|
||||
val b: Byte = 2
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ annotation class Ann(
|
||||
|
||||
val i: Int = 2
|
||||
val s: Short = 2
|
||||
val f: Float = 2.0
|
||||
val f: Float = 2.0.toFloat()
|
||||
val d: Double = 2.0
|
||||
val l: Long = 2
|
||||
val b: Byte = 2
|
||||
|
||||
@@ -27,4 +27,4 @@ fun box(): String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Ann(1, 1, 1, 1.0, 1.0, 1, 'c', true) class MyClass
|
||||
Ann(1, 1, 1, 1.0.toFloat(), 1.0, 1, 'c', true) class MyClass
|
||||
|
||||
@@ -69,7 +69,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(5.5, 5.0, 4.5, 4.0)) {
|
||||
if (list7 != listOf<Float>(5.5.toFloat(), 5.0.toFloat(), 4.5.toFloat(), 4.0.toFloat())) {
|
||||
return "Wrong elements for 5.5.toFloat() downTo 3.7.toFloat() step 0.5.toFloat(): $list7"
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(4.0, 4.5, 5.0, 5.5)) {
|
||||
if (list7 != listOf<Float>(4.0.toFloat(), 4.5.toFloat(), 5.0.toFloat(), 5.5.toFloat())) {
|
||||
return "Wrong elements for 4.0.toFloat()..5.8.toFloat() step 0.5.toFloat(): $list7"
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ fun box(): String {
|
||||
list2.add(i)
|
||||
if (list2.size() > 23) break
|
||||
}
|
||||
if (list2 != listOf<Float>(0.0)) {
|
||||
if (list2 != listOf<Float>(0.0.toFloat())) {
|
||||
return "Wrong elements for 0.0.toFloat()..5.0.toFloat() step j.Float.POSITIVE_INFINITY: $list2"
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ fun box(): String {
|
||||
list4.add(i)
|
||||
if (list4.size() > 23) break
|
||||
}
|
||||
if (list4 != listOf<Float>(5.0)) {
|
||||
if (list4 != listOf<Float>(5.0.toFloat())) {
|
||||
return "Wrong elements for 5.0.toFloat() downTo 0.0.toFloat() step j.Float.POSITIVE_INFINITY: $list4"
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(3.0, 4.0, 5.0)) {
|
||||
if (list7 != listOf<Float>(3.0.toFloat(), 4.0.toFloat(), 5.0.toFloat())) {
|
||||
return "Wrong elements for (5.0.toFloat() downTo 3.0.toFloat()).reversed(): $list7"
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -64,13 +64,13 @@ fun box(): String {
|
||||
}
|
||||
|
||||
val list7 = ArrayList<Float>()
|
||||
val range7 = (5.8.toFloat() downTo 4.0.toFloat() step 0.5).reversed()
|
||||
val range7 = (5.8.toFloat() downTo 4.0.toFloat() step 0.5.toFloat()).reversed()
|
||||
for (i in range7) {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(4.0, 4.5, 5.0, 5.5)) {
|
||||
return "Wrong elements for (5.8.toFloat() downTo 4.0.toFloat() step 0.5).reversed(): $list7"
|
||||
if (list7 != listOf<Float>(4.0.toFloat(), 4.5.toFloat(), 5.0.toFloat(), 5.5.toFloat())) {
|
||||
return "Wrong elements for (5.8.toFloat() downTo 4.0.toFloat() step 0.5.toFloat()).reversed(): $list7"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
|
||||
@@ -69,7 +69,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(5.0, 4.0, 3.0)) {
|
||||
if (list7 != listOf<Float>(5.0.toFloat(), 4.0.toFloat(), 3.0.toFloat())) {
|
||||
return "Wrong elements for (3.0.toFloat()..5.0.toFloat()).reversed(): $list7"
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -64,13 +64,13 @@ fun box(): String {
|
||||
}
|
||||
|
||||
val list7 = ArrayList<Float>()
|
||||
val range7 = (4.0.toFloat()..6.0.toFloat() step 0.5).reversed()
|
||||
val range7 = (4.0.toFloat()..6.0.toFloat() step 0.5.toFloat()).reversed()
|
||||
for (i in range7) {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(6.0, 5.5, 5.0, 4.5, 4.0)) {
|
||||
return "Wrong elements for (4.0.toFloat()..6.0.toFloat() step 0.5).reversed(): $list7"
|
||||
if (list7 != listOf<Float>(6.0.toFloat(), 5.5.toFloat(), 5.0.toFloat(), 4.5.toFloat(), 4.0.toFloat())) {
|
||||
return "Wrong elements for (4.0.toFloat()..6.0.toFloat() step 0.5.toFloat()).reversed(): $list7"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
|
||||
@@ -69,7 +69,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0)) {
|
||||
if (list7 != listOf<Float>(9.0.toFloat(), 8.0.toFloat(), 7.0.toFloat(), 6.0.toFloat(), 5.0.toFloat(), 4.0.toFloat(), 3.0.toFloat())) {
|
||||
return "Wrong elements for 9.0.toFloat() downTo 3.0.toFloat(): $list7"
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)) {
|
||||
if (list7 != listOf<Float>(3.0.toFloat(), 4.0.toFloat(), 5.0.toFloat(), 6.0.toFloat(), 7.0.toFloat(), 8.0.toFloat(), 9.0.toFloat())) {
|
||||
return "Wrong elements for 3.0.toFloat()..9.0.toFloat(): $list7"
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)) {
|
||||
if (list7 != listOf<Float>(3.0.toFloat(), 4.0.toFloat(), 5.0.toFloat(), 6.0.toFloat(), 7.0.toFloat(), 8.0.toFloat(), 9.0.toFloat())) {
|
||||
return "Wrong elements for (1.5.toFloat() * 2.toFloat())..(3.0.toFloat() * 3.0.toFloat()): $list7"
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(6.0, 5.5, 5.0, 4.5, 4.0)) {
|
||||
if (list7 != listOf<Float>(6.0.toFloat(), 5.5.toFloat(), 5.0.toFloat(), 4.5.toFloat(), 4.0.toFloat())) {
|
||||
return "Wrong elements for 6.0.toFloat() downTo 4.0.toFloat() step 0.5.toFloat(): $list7"
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(4.0, 4.5, 5.0, 5.5, 6.0)) {
|
||||
if (list7 != listOf<Float>(4.0.toFloat(), 4.5.toFloat(), 5.0.toFloat(), 5.5.toFloat(), 6.0.toFloat())) {
|
||||
return "Wrong elements for 4.0.toFloat()..6.0.toFloat() step 0.5.toFloat(): $list7"
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(5.5, 5.0, 4.5, 4.0)) {
|
||||
if (list7 != listOf<Float>(5.5.toFloat(), 5.0.toFloat(), 4.5.toFloat(), 4.0.toFloat())) {
|
||||
return "Wrong elements for 5.5.toFloat() downTo 3.7.toFloat() step 0.5.toFloat(): $list7"
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(4.0, 4.5, 5.0, 5.5)) {
|
||||
if (list7 != listOf<Float>(4.0.toFloat(), 4.5.toFloat(), 5.0.toFloat(), 5.5.toFloat())) {
|
||||
return "Wrong elements for 4.0.toFloat()..5.8.toFloat() step 0.5.toFloat(): $list7"
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ fun box(): String {
|
||||
list2.add(i)
|
||||
if (list2.size() > 23) break
|
||||
}
|
||||
if (list2 != listOf<Float>(0.0)) {
|
||||
if (list2 != listOf<Float>(0.0.toFloat())) {
|
||||
return "Wrong elements for 0.0.toFloat()..5.0.toFloat() step j.Float.POSITIVE_INFINITY: $list2"
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ fun box(): String {
|
||||
list4.add(i)
|
||||
if (list4.size() > 23) break
|
||||
}
|
||||
if (list4 != listOf<Float>(5.0)) {
|
||||
if (list4 != listOf<Float>(5.0.toFloat())) {
|
||||
return "Wrong elements for 5.0.toFloat() downTo 0.0.toFloat() step j.Float.POSITIVE_INFINITY: $list4"
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(3.0, 4.0, 5.0)) {
|
||||
if (list7 != listOf<Float>(3.0.toFloat(), 4.0.toFloat(), 5.0.toFloat())) {
|
||||
return "Wrong elements for (5.0.toFloat() downTo 3.0.toFloat()).reversed(): $list7"
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -58,12 +58,12 @@ fun box(): String {
|
||||
}
|
||||
|
||||
val list7 = ArrayList<Float>()
|
||||
for (i in (5.8.toFloat() downTo 4.0.toFloat() step 0.5).reversed()) {
|
||||
for (i in (5.8.toFloat() downTo 4.0.toFloat() step 0.5.toFloat()).reversed()) {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(4.0, 4.5, 5.0, 5.5)) {
|
||||
return "Wrong elements for (5.8.toFloat() downTo 4.0.toFloat() step 0.5).reversed(): $list7"
|
||||
if (list7 != listOf<Float>(4.0.toFloat(), 4.5.toFloat(), 5.0.toFloat(), 5.5.toFloat())) {
|
||||
return "Wrong elements for (5.8.toFloat() downTo 4.0.toFloat() step 0.5.toFloat()).reversed(): $list7"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
|
||||
@@ -62,7 +62,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(5.0, 4.0, 3.0)) {
|
||||
if (list7 != listOf<Float>(5.0.toFloat(), 4.0.toFloat(), 3.0.toFloat())) {
|
||||
return "Wrong elements for (3.0.toFloat()..5.0.toFloat()).reversed(): $list7"
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -58,12 +58,12 @@ fun box(): String {
|
||||
}
|
||||
|
||||
val list7 = ArrayList<Float>()
|
||||
for (i in (4.0.toFloat()..6.0.toFloat() step 0.5).reversed()) {
|
||||
for (i in (4.0.toFloat()..6.0.toFloat() step 0.5.toFloat()).reversed()) {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(6.0, 5.5, 5.0, 4.5, 4.0)) {
|
||||
return "Wrong elements for (4.0.toFloat()..6.0.toFloat() step 0.5).reversed(): $list7"
|
||||
if (list7 != listOf<Float>(6.0.toFloat(), 5.5.toFloat(), 5.0.toFloat(), 4.5.toFloat(), 4.0.toFloat())) {
|
||||
return "Wrong elements for (4.0.toFloat()..6.0.toFloat() step 0.5.toFloat()).reversed(): $list7"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
|
||||
@@ -62,7 +62,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0)) {
|
||||
if (list7 != listOf<Float>(9.0.toFloat(), 8.0.toFloat(), 7.0.toFloat(), 6.0.toFloat(), 5.0.toFloat(), 4.0.toFloat(), 3.0.toFloat())) {
|
||||
return "Wrong elements for 9.0.toFloat() downTo 3.0.toFloat(): $list7"
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)) {
|
||||
if (list7 != listOf<Float>(3.0.toFloat(), 4.0.toFloat(), 5.0.toFloat(), 6.0.toFloat(), 7.0.toFloat(), 8.0.toFloat(), 9.0.toFloat())) {
|
||||
return "Wrong elements for 3.0.toFloat()..9.0.toFloat(): $list7"
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)) {
|
||||
if (list7 != listOf<Float>(3.0.toFloat(), 4.0.toFloat(), 5.0.toFloat(), 6.0.toFloat(), 7.0.toFloat(), 8.0.toFloat(), 9.0.toFloat())) {
|
||||
return "Wrong elements for (1.5.toFloat() * 2.toFloat())..(3.0.toFloat() * 3.0.toFloat()): $list7"
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(6.0, 5.5, 5.0, 4.5, 4.0)) {
|
||||
if (list7 != listOf<Float>(6.0.toFloat(), 5.5.toFloat(), 5.0.toFloat(), 4.5.toFloat(), 4.0.toFloat())) {
|
||||
return "Wrong elements for 6.0.toFloat() downTo 4.0.toFloat() step 0.5.toFloat(): $list7"
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ fun box(): String {
|
||||
list7.add(i)
|
||||
if (list7.size() > 23) break
|
||||
}
|
||||
if (list7 != listOf<Float>(4.0, 4.5, 5.0, 5.5, 6.0)) {
|
||||
if (list7 != listOf<Float>(4.0.toFloat(), 4.5.toFloat(), 5.0.toFloat(), 5.5.toFloat(), 6.0.toFloat())) {
|
||||
return "Wrong elements for 4.0.toFloat()..6.0.toFloat() step 0.5.toFloat(): $list7"
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class Test {
|
||||
val vbyte: Byte = 11
|
||||
val vlong: Long = 12
|
||||
val vdouble: Double = 1.2
|
||||
val vfloat: Float = 1.3
|
||||
val vfloat: Float = 1.3.toFloat()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ trait Test {
|
||||
val vbyte: Byte = 11
|
||||
val vlong: Long = 12
|
||||
val vdouble: Double = 1.2
|
||||
val vfloat: Float = 1.3
|
||||
val vfloat: Float = 1.3.toFloat()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,8 @@ fun varargFloat(vararg v: Float) = v
|
||||
|
||||
fun varargDouble(vararg v: Double) = v
|
||||
|
||||
fun <T> testFun(<!UNUSED_PARAMETER!>p<!>: T) {}
|
||||
|
||||
fun test() {
|
||||
1: Byte
|
||||
1: Short
|
||||
@@ -20,10 +22,10 @@ fun test() {
|
||||
0b001: Int
|
||||
|
||||
0.1: Double
|
||||
0.1: Float
|
||||
0.1.toFloat(): Float
|
||||
|
||||
1e5: Double
|
||||
1e-5: Float
|
||||
1e-5.toFloat(): Float
|
||||
|
||||
<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>: Double
|
||||
<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>: Float
|
||||
@@ -39,6 +41,11 @@ fun test() {
|
||||
varargShort(0x777, 1, 2, 3, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>200000<!>, 0b111)
|
||||
varargInt(0x77777777, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>0x7777777777<!>, 1, 2, 3, 2000000000, 0b111)
|
||||
varargLong(0x777777777777, 1, 2, 3, 200000, 0b111)
|
||||
varargFloat(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, 1.0, <!TYPE_MISMATCH!>-0.1<!>, 1e4, 1e-4, <!TYPE_MISMATCH!>-1e4<!>)
|
||||
varargFloat(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!>, <!TYPE_MISMATCH!>-0.1<!>, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1e4<!>, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1e-4<!>, <!TYPE_MISMATCH!>-1e4<!>)
|
||||
varargDouble(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, 1.0, -0.1, 1e4, 1e-4, -1e4)
|
||||
|
||||
testFun(1.0)
|
||||
testFun<Float>(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!>)
|
||||
testFun(1.0.toFloat())
|
||||
testFun<Float>(1.0.toFloat())
|
||||
}
|
||||
@@ -5,7 +5,7 @@ fun <T> id(t: T): T = t
|
||||
fun <T> either(t1: T, <!UNUSED_PARAMETER!>t2<!>: T): T = t1
|
||||
|
||||
fun test() {
|
||||
val <!UNUSED_VARIABLE!>a<!>: Float = id(2.0)
|
||||
val <!UNUSED_VARIABLE!>a<!>: Float = id(2.0.toFloat())
|
||||
|
||||
val b = id(2.0)
|
||||
b: Double
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package test
|
||||
|
||||
// val prop1: 3.4028235E38.toFloat()
|
||||
val prop1: Float = java.lang.Float.MAX_VALUE + 1
|
||||
|
||||
// val prop2: 3.4028234663852886E38.toDouble()
|
||||
val prop2: Double = java.lang.Float.MAX_VALUE + 1.0
|
||||
|
||||
// val prop3: 3.4028235E38.toFloat()
|
||||
val prop3 = java.lang.Float.MAX_VALUE + 1
|
||||
|
||||
// val prop4: 3.4028235E38.toFloat()
|
||||
val prop4 = java.lang.Float.MAX_VALUE - 1
|
||||
|
||||
// val prop5: 3.4028235E38.toFloat()
|
||||
val prop5: Int = java.lang.Float.MAX_VALUE + 1
|
||||
|
||||
// val prop6: 2.0.toFloat()
|
||||
val prop6: Float = 1.0.toFloat() + 1
|
||||
|
||||
// val prop7: 2.0.toDouble()
|
||||
val prop7: Double = 1.0 + 1.0
|
||||
|
||||
// val prop8: 2.0.toDouble()
|
||||
val prop8: Float = 1.0.toDouble() + 1.0
|
||||
|
||||
// val prop9: -2.0.toDouble()
|
||||
val prop9: Double = -2.0
|
||||
@@ -0,0 +1,19 @@
|
||||
package test
|
||||
|
||||
// _ prop1: 513105426295.toLong()
|
||||
val prop1: Int = 0x7777777777
|
||||
|
||||
// _ prop2: 513105426295.toLong()
|
||||
val prop2: Long = 0x7777777777
|
||||
|
||||
// _ prop3: 513105426295.toLong()
|
||||
val prop3 = 0x7777777777
|
||||
|
||||
// _ prop4: -2147483648.toInt()
|
||||
val prop4: Int = Integer.MAX_VALUE + 1
|
||||
|
||||
// _ prop5: -2147483648.toLong()
|
||||
val prop5: Long = Integer.MAX_VALUE + 1
|
||||
|
||||
// _ prop6: -2147483648.toInt()
|
||||
val prop6 = Integer.MAX_VALUE + 1
|
||||
@@ -15,6 +15,6 @@ ByteAnno(42)
|
||||
LongAnno(42)
|
||||
CharAnno('A')
|
||||
BooleanAnno(false)
|
||||
FloatAnno(3.14)
|
||||
FloatAnno(3.14.toFloat())
|
||||
DoubleAnno(3.14)
|
||||
class Class
|
||||
|
||||
@@ -10,6 +10,6 @@ annotation class Ann(
|
||||
val b7: Char
|
||||
)
|
||||
|
||||
Ann(-1, -1, -1, -1, -1.0, -1.0, -'c') class MyClass
|
||||
Ann(-1, -1, -1, -1, -1.0, -1.0.toFloat(), -'c') class MyClass
|
||||
|
||||
// EXPECTED: Ann[b1 = -1.toByte(): jet.Byte, b2 = -1.toShort(): jet.Short, b3 = -1.toInt(): jet.Int, b4 = -1.toLong(): jet.Long, b5 = -1.0.toDouble(): jet.Double, b6 = -1.0.toDouble(): jet.Double, b7 = -99.toInt(): jet.Int]
|
||||
// EXPECTED: Ann[b1 = -1.toByte(): jet.Byte, b2 = -1.toShort(): jet.Short, b3 = -1.toInt(): jet.Int, b4 = -1.toLong(): jet.Long, b5 = -1.0.toDouble(): jet.Double, b6 = -1.0.toFloat(): jet.Float, b7 = -99.toInt(): jet.Int]
|
||||
|
||||
@@ -10,6 +10,6 @@ annotation class Ann(
|
||||
val b7: Char
|
||||
)
|
||||
|
||||
Ann(+1, +1, +1, +1, +1.0, +1.0, +'c') class MyClass
|
||||
Ann(+1, +1, +1, +1, +1.0, +1.0.toFloat(), +'c') class MyClass
|
||||
|
||||
// EXPECTED: Ann[b1 = 1.toByte(): jet.Byte, b2 = 1.toShort(): jet.Short, b3 = 1.toInt(): jet.Int, b4 = 1.toLong(): jet.Long, b5 = 1.0.toDouble(): jet.Double, b6 = 1.0.toDouble(): jet.Double, b7 = 99.toInt(): jet.Int]
|
||||
// EXPECTED: Ann[b1 = 1.toByte(): jet.Byte, b2 = 1.toShort(): jet.Short, b3 = 1.toInt(): jet.Int, b4 = 1.toLong(): jet.Long, b5 = 1.0.toDouble(): jet.Double, b6 = 1.0.toFloat(): jet.Float, b7 = 99.toInt(): jet.Int]
|
||||
|
||||
@@ -2,11 +2,9 @@ package test
|
||||
|
||||
annotation class Ann(
|
||||
val b1: Float,
|
||||
val b2: Float,
|
||||
val b3: Float,
|
||||
val b4: Float
|
||||
val b2: Float
|
||||
)
|
||||
|
||||
Ann(1.0, 1.toFloat(), 1.0.toFloat()) class MyClass
|
||||
Ann(1.toFloat(), 1.0.toFloat()) class MyClass
|
||||
|
||||
// EXPECTED: Ann[b1 = 1.0.toFloat(): jet.Float, b2 = 1.0.toFloat(): jet.Float, b3 = 1.0.toFloat(): jet.Float]
|
||||
// EXPECTED: Ann[b1 = 1.0.toFloat(): jet.Float, b2 = 1.0.toFloat(): jet.Float]
|
||||
@@ -36,6 +36,16 @@ public class EvaluateExpressionTestGenerated extends AbstractEvaluateExpressionT
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/evaluate"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("floatsAndDoubles.kt")
|
||||
public void testFloatsAndDoubles() throws Exception {
|
||||
doTest("compiler/testData/evaluate/floatsAndDoubles.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("integers.kt")
|
||||
public void testIntegers() throws Exception {
|
||||
doTest("compiler/testData/evaluate/integers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("strings.kt")
|
||||
public void testStrings() throws Exception {
|
||||
doTest("compiler/testData/evaluate/strings.kt");
|
||||
|
||||
@@ -17,7 +17,7 @@ fun box(): String {
|
||||
test("shortArray", shortArray(0, 1, 2, 3, 4), "0, 1, 2, 3, 4")
|
||||
test("intArray,", intArray(0, 1, 2, 3, 4), "0, 1, 2, 3, 4")
|
||||
test("longArray", longArray(0, 1, 2, 3, 4), "0, 1, 2, 3, 4")
|
||||
test("floatArray", floatArray(0.0, 1.0, 2.0, 3.0, 4.0), "0.0, 1.0, 2.0, 3.0, 4.0")
|
||||
test("floatArray", floatArray(0.0.toFloat(), 1.0.toFloat(), 2.0.toFloat(), 3.0.toFloat(), 4.0.toFloat()), "0.0, 1.0, 2.0, 3.0, 4.0")
|
||||
test("doubleArray", doubleArray(0.0, 1.1, 2.2, 3.3, 4.4), "0.0, 1.1, 2.2, 3.3, 4.4")
|
||||
}
|
||||
catch (e : Fail) {
|
||||
|
||||
@@ -90,7 +90,7 @@ class ArraysJVMTest {
|
||||
expect(2000000000000, { longArray(3000000000000, 2000000000000).min() })
|
||||
expect(1, { byteArray(1, 3, 2).min() })
|
||||
expect(2, { shortArray(3, 2).min() })
|
||||
expect(2.0, { floatArray(3.0, 2.0).min() })
|
||||
expect(2.0.toFloat(), { floatArray(3.0.toFloat(), 2.0.toFloat()).min() })
|
||||
expect(2.0, { doubleArray(2.0, 3.0).min() })
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ class ArraysJVMTest {
|
||||
expect(3000000000000, { longArray(3000000000000, 2000000000000).max() })
|
||||
expect(3, { byteArray(1, 3, 2).max() })
|
||||
expect(3, { shortArray(3, 2).max() })
|
||||
expect(3.0, { floatArray(3.0, 2.0).max() })
|
||||
expect(3.0.toFloat(), { floatArray(3.0.toFloat(), 2.0.toFloat()).max() })
|
||||
expect(3.0, { doubleArray(2.0, 3.0).max() })
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ class ArraysJVMTest {
|
||||
expect(2000000000000, { longArray(3000000000000, 2000000000000).minBy { it + 1 } })
|
||||
expect(1, { byteArray(1, 3, 2).minBy { it * it } })
|
||||
expect(3, { shortArray(3, 2).minBy { "a" } })
|
||||
expect(2.0, { floatArray(3.0, 2.0).minBy { it.toString() } })
|
||||
expect(2.0.toFloat(), { floatArray(3.0.toFloat(), 2.0.toFloat()).minBy { it.toString() } })
|
||||
expect(2.0, { doubleArray(2.0, 3.0).minBy { Math.sqrt(it) } })
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ class ArraysJVMTest {
|
||||
expect(3000000000000, { longArray(3000000000000, 2000000000000).maxBy { it + 1 } })
|
||||
expect(3, { byteArray(1, 3, 2).maxBy { it * it } })
|
||||
expect(3, { shortArray(3, 2).maxBy { "a" } })
|
||||
expect(3.0, { floatArray(3.0, 2.0).maxBy { it.toString() } })
|
||||
expect(3.0.toFloat(), { floatArray(3.0.toFloat(), 2.0.toFloat()).maxBy { it.toString() } })
|
||||
expect(3.0, { doubleArray(2.0, 3.0).maxBy { Math.sqrt(it) } })
|
||||
}
|
||||
|
||||
@@ -144,6 +144,6 @@ class ArraysJVMTest {
|
||||
expect(200) { byteArray(100, 100).sum() }
|
||||
expect(50000) { shortArray(20000, 30000).sum() }
|
||||
expect(3000000000000) { longArray(1000000000000, 2000000000000).sum() }
|
||||
expect(3.0) { floatArray(1.0, 2.0).sum() }
|
||||
expect(3.0.toFloat()) { floatArray(1.0.toFloat(), 2.0.toFloat()).sum() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ class ArraysTest {
|
||||
test fun floatArray() {
|
||||
val arr = FloatArray(2)
|
||||
|
||||
val expected: Float = 0.0
|
||||
val expected: Float = 0.0.toFloat()
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(expected, arr[0])
|
||||
assertEquals(expected, arr[1])
|
||||
|
||||
@@ -77,7 +77,7 @@ public class RangeIterationTest {
|
||||
|
||||
doTest(3.0..9.0, 3.0, 9.0, 1.0, listOf(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))
|
||||
doTest(3.0.toFloat()..9.0.toFloat(), 3.0.toFloat(), 9.0.toFloat(), 1.toFloat(),
|
||||
listOf<Float>(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))
|
||||
listOf<Float>(3.0.toFloat(), 4.0.toFloat(), 5.0.toFloat(), 6.0.toFloat(), 7.0.toFloat(), 8.0.toFloat(), 9.0.toFloat()))
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ public class RangeIterationTest {
|
||||
|
||||
doTest((1.5 * 2)..(3.0 * 3.0), 3.0, 9.0, 1.0, listOf(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))
|
||||
doTest((1.5.toFloat() * 2.toFloat())..(3.0.toFloat() * 3.0.toFloat()), 3.0.toFloat(), 9.0.toFloat(), 1.toFloat(),
|
||||
listOf<Float>(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))
|
||||
listOf<Float>(3.0.toFloat(), 4.0.toFloat(), 5.0.toFloat(), 6.0.toFloat(), 7.0.toFloat(), 8.0.toFloat(), 9.0.toFloat()))
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ public class RangeIterationTest {
|
||||
|
||||
doTest(9.0 downTo 3.0, 9.0, 3.0, -1.0, listOf(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0))
|
||||
doTest(9.0.toFloat() downTo 3.0.toFloat(), 9.0.toFloat(), 3.0.toFloat(), -1.0.toFloat(),
|
||||
listOf<Float>(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0))
|
||||
listOf<Float>(9.0.toFloat(), 8.0.toFloat(), 7.0.toFloat(), 6.0.toFloat(), 5.0.toFloat(), 4.0.toFloat(), 3.0.toFloat()))
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ public class RangeIterationTest {
|
||||
|
||||
doTest(4.0..6.0 step 0.5, 4.0, 6.0, 0.5, listOf(4.0, 4.5, 5.0, 5.5, 6.0))
|
||||
doTest(4.0.toFloat()..6.0.toFloat() step 0.5.toFloat(), 4.0.toFloat(), 6.0.toFloat(), 0.5.toFloat(),
|
||||
listOf<Float>(4.0, 4.5, 5.0, 5.5, 6.0))
|
||||
listOf<Float>(4.0.toFloat(), 4.5.toFloat(), 5.0.toFloat(), 5.5.toFloat(), 6.0.toFloat()))
|
||||
}
|
||||
|
||||
test fun simpleSteppedDownTo() {
|
||||
@@ -156,7 +156,7 @@ public class RangeIterationTest {
|
||||
|
||||
doTest(6.0 downTo 4.0 step 0.5, 6.0, 4.0, -0.5, listOf(6.0, 5.5, 5.0, 4.5, 4.0))
|
||||
doTest(6.0.toFloat() downTo 4.0.toFloat() step 0.5.toFloat(), 6.0.toFloat(), 4.0.toFloat(), -0.5.toFloat(),
|
||||
listOf<Float>(6.0, 5.5, 5.0, 4.5, 4.0))
|
||||
listOf<Float>(6.0.toFloat(), 5.5.toFloat(), 5.0.toFloat(), 4.5.toFloat(), 4.0.toFloat()))
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ public class RangeIterationTest {
|
||||
|
||||
doTest(4.0..5.8 step 0.5, 4.0, 5.8, 0.5, listOf(4.0, 4.5, 5.0, 5.5))
|
||||
doTest(4.0.toFloat()..5.8.toFloat() step 0.5.toFloat(), 4.0.toFloat(), 5.8.toFloat(), 0.5.toFloat(),
|
||||
listOf<Float>(4.0, 4.5, 5.0, 5.5))
|
||||
listOf<Float>(4.0.toFloat(), 4.5.toFloat(), 5.0.toFloat(), 5.5.toFloat()))
|
||||
}
|
||||
|
||||
// 'inexact' means last element is not equal to sequence end
|
||||
@@ -185,7 +185,7 @@ public class RangeIterationTest {
|
||||
|
||||
doTest(5.5 downTo 3.7 step 0.5, 5.5, 3.7, -0.5, listOf(5.5, 5.0, 4.5, 4.0))
|
||||
doTest(5.5.toFloat() downTo 3.7.toFloat() step 0.5.toFloat(), 5.5.toFloat(), 3.7.toFloat(), -0.5.toFloat(),
|
||||
listOf<Float>(5.5, 5.0, 4.5, 4.0))
|
||||
listOf<Float>(5.5.toFloat(), 5.0.toFloat(), 4.5.toFloat(), 4.0.toFloat()))
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ public class RangeIterationTest {
|
||||
|
||||
doTest((3.0..5.0).reversed(), 5.0, 3.0, -1.0, listOf(5.0, 4.0, 3.0))
|
||||
doTest((3.0.toFloat()..5.0.toFloat()).reversed(), 5.0.toFloat(), 3.0.toFloat(), -1.toFloat(),
|
||||
listOf<Float>(5.0, 4.0, 3.0))
|
||||
listOf<Float>(5.0.toFloat(), 4.0.toFloat(), 3.0.toFloat()))
|
||||
}
|
||||
|
||||
test fun reversedBackSequence() {
|
||||
@@ -236,7 +236,7 @@ public class RangeIterationTest {
|
||||
|
||||
doTest((5.0 downTo 3.0).reversed(), 3.0, 5.0, 1.0, listOf(3.0, 4.0, 5.0))
|
||||
doTest((5.0.toFloat() downTo 3.0.toFloat()).reversed(), 3.0.toFloat(), 5.0.toFloat(), 1.toFloat(),
|
||||
listOf<Float>(3.0, 4.0, 5.0))
|
||||
listOf<Float>(3.0.toFloat(), 4.0.toFloat(), 5.0.toFloat()))
|
||||
}
|
||||
|
||||
test fun reversedSimpleSteppedRange() {
|
||||
@@ -248,8 +248,8 @@ public class RangeIterationTest {
|
||||
doTest(('c'..'g' step 2).reversed(), 'g', 'c', -2, listOf('g', 'e', 'c'))
|
||||
|
||||
doTest((4.0..6.0 step 0.5).reversed(), 6.0, 4.0, -0.5, listOf(6.0, 5.5, 5.0, 4.5, 4.0))
|
||||
doTest((4.0.toFloat()..6.0.toFloat() step 0.5).reversed(), 6.0.toFloat(), 4.0.toFloat(), -0.5.toFloat(),
|
||||
listOf<Float>(6.0, 5.5, 5.0, 4.5, 4.0))
|
||||
doTest((4.0.toFloat()..6.0.toFloat() step 0.5.toFloat()).reversed(), 6.0.toFloat(), 4.0.toFloat(), -0.5.toFloat(),
|
||||
listOf<Float>(6.0.toFloat(), 5.5.toFloat(), 5.0.toFloat(), 4.5.toFloat(), 4.0.toFloat()))
|
||||
}
|
||||
|
||||
// 'inexact' means last element is not equal to sequence end
|
||||
@@ -262,17 +262,17 @@ public class RangeIterationTest {
|
||||
doTest(('d' downTo 'a' step 2).reversed(), 'a', 'd', 2, listOf('a', 'c'))
|
||||
|
||||
doTest((5.8 downTo 4.0 step 0.5).reversed(), 4.0, 5.8, 0.5, listOf(4.0, 4.5, 5.0, 5.5))
|
||||
doTest((5.8.toFloat() downTo 4.0.toFloat() step 0.5).reversed(), 4.0.toFloat(), 5.8.toFloat(), 0.5.toFloat(),
|
||||
listOf<Float>(4.0, 4.5, 5.0, 5.5))
|
||||
doTest((5.8.toFloat() downTo 4.0.toFloat() step 0.5.toFloat()).reversed(), 4.0.toFloat(), 5.8.toFloat(), 0.5.toFloat(),
|
||||
listOf<Float>(4.0.toFloat(), 4.5.toFloat(), 5.0.toFloat(), 5.5.toFloat()))
|
||||
}
|
||||
|
||||
test fun infiniteSteps() {
|
||||
doTest(0.0..5.0 step j.Double.POSITIVE_INFINITY, 0.0, 5.0, j.Double.POSITIVE_INFINITY, listOf(0.0))
|
||||
doTest(0.0.toFloat()..5.0.toFloat() step j.Float.POSITIVE_INFINITY, 0.0.toFloat(), 5.0.toFloat(), j.Float.POSITIVE_INFINITY,
|
||||
listOf<Float>(0.0))
|
||||
listOf<Float>(0.0.toFloat()))
|
||||
doTest(5.0 downTo 0.0 step j.Double.POSITIVE_INFINITY, 5.0, 0.0, j.Double.NEGATIVE_INFINITY, listOf(5.0))
|
||||
doTest(5.0.toFloat() downTo 0.0.toFloat() step j.Float.POSITIVE_INFINITY, 5.0.toFloat(), 0.0.toFloat(), j.Float.NEGATIVE_INFINITY,
|
||||
listOf<Float>(5.0))
|
||||
listOf<Float>(5.0.toFloat()))
|
||||
}
|
||||
|
||||
test fun nanEnds() {
|
||||
|
||||
Reference in New Issue
Block a user