report ERROR_COMPILE_TIME_VALUE for constants instead of TYPE_MISMATCH
(functionality returned)
This commit is contained in:
@@ -39,8 +39,7 @@ import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus;
|
|||||||
import org.jetbrains.jet.lang.resolve.calls.tasks.ResolutionTask;
|
import org.jetbrains.jet.lang.resolve.calls.tasks.ResolutionTask;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.tasks.TaskPrioritizer;
|
import org.jetbrains.jet.lang.resolve.calls.tasks.TaskPrioritizer;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.util.ExpressionAsFunctionDescriptor;
|
import org.jetbrains.jet.lang.resolve.calls.util.ExpressionAsFunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.ConstantUtils;
|
import org.jetbrains.jet.lang.resolve.constants.*;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.NumberValueTypeConstructor;
|
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
@@ -55,8 +54,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPER_IS_NOT_AN_EXPRESSION;
|
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.DONT_CARE;
|
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.DONT_CARE;
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.PLACEHOLDER_FUNCTION_TYPE;
|
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.PLACEHOLDER_FUNCTION_TYPE;
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS;
|
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS;
|
||||||
@@ -364,7 +362,16 @@ public class CandidateResolver {
|
|||||||
type = ConstantUtils.updateConstantValueType(constructor, expectedType, expression, context);
|
type = ConstantUtils.updateConstantValueType(constructor, expectedType, expression, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DataFlowUtils.checkType(type, expression, newContext);
|
if (expression instanceof JetConstantExpression && !KotlinBuiltIns.getInstance().isUnit(expectedType)) {
|
||||||
|
CompileTimeConstant<?> value =
|
||||||
|
new CompileTimeConstantResolver().getCompileTimeConstant((JetConstantExpression) expression, expectedType);
|
||||||
|
if (value instanceof ErrorValue) {
|
||||||
|
context.trace.report(ERROR_COMPILE_TIME_VALUE.on(expression, ((ErrorValue) value).getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DataFlowUtils.checkType(type, expression, newContext);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+38
-5
@@ -17,13 +17,15 @@
|
|||||||
package org.jetbrains.jet.lang.resolve.constants;
|
package org.jetbrains.jet.lang.resolve.constants;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.intellij.psi.tree.IElementType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.psi.JetEscapeStringTemplateEntry;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
import org.jetbrains.jet.lang.psi.JetLiteralStringTemplateEntry;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.psi.JetStringTemplateEntry;
|
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||||
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
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.checker.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
|
||||||
@@ -38,6 +40,37 @@ public class CompileTimeConstantResolver {
|
|||||||
this.builtIns = KotlinBuiltIns.getInstance();
|
this.builtIns = KotlinBuiltIns.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public CompileTimeConstant<?> getCompileTimeConstant(
|
||||||
|
@NotNull JetConstantExpression expression,
|
||||||
|
@NotNull JetType expectedType
|
||||||
|
) {
|
||||||
|
IElementType elementType = expression.getNode().getElementType();
|
||||||
|
String text = expression.getNode().getText();
|
||||||
|
|
||||||
|
CompileTimeConstant<?> value;
|
||||||
|
if (elementType == JetNodeTypes.INTEGER_CONSTANT) {
|
||||||
|
value = getIntegerValue(text, expectedType);
|
||||||
|
}
|
||||||
|
else if (elementType == JetNodeTypes.FLOAT_CONSTANT) {
|
||||||
|
value = getFloatValue(text, expectedType);
|
||||||
|
}
|
||||||
|
else if (elementType == JetNodeTypes.BOOLEAN_CONSTANT) {
|
||||||
|
value = getBooleanValue(text, expectedType);
|
||||||
|
}
|
||||||
|
else if (elementType == JetNodeTypes.CHARACTER_CONSTANT) {
|
||||||
|
value = getCharValue(text, expectedType);
|
||||||
|
}
|
||||||
|
else if (elementType == JetNodeTypes.NULL) {
|
||||||
|
value = getNullValue(expectedType);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new IllegalArgumentException("Unsupported constant: " + expression);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CompileTimeConstant<?> getIntegerValue(@NotNull String text, @NotNull JetType expectedType) {
|
public CompileTimeConstant<?> getIntegerValue(@NotNull String text, @NotNull JetType expectedType) {
|
||||||
return getIntegerValue(parseLongValue(text), expectedType);
|
return getIntegerValue(parseLongValue(text), expectedType);
|
||||||
|
|||||||
+8
-28
@@ -116,9 +116,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetTypeInfo visitConstantExpression(JetConstantExpression expression, ExpressionTypingContext context) {
|
public JetTypeInfo visitConstantExpression(JetConstantExpression expression, ExpressionTypingContext context) {
|
||||||
ASTNode node = expression.getNode();
|
IElementType elementType = expression.getNode().getElementType();
|
||||||
IElementType elementType = node.getElementType();
|
String text = expression.getNode().getText();
|
||||||
String text = node.getText();
|
|
||||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||||
CompileTimeConstantResolver compileTimeConstantResolver = context.getCompileTimeConstantResolver();
|
CompileTimeConstantResolver compileTimeConstantResolver = context.getCompileTimeConstantResolver();
|
||||||
|
|
||||||
@@ -137,34 +136,15 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompileTimeConstant<?> value;
|
CompileTimeConstant<?> value = compileTimeConstantResolver.getCompileTimeConstant(expression, context.expectedType);
|
||||||
if (elementType == JetNodeTypes.INTEGER_CONSTANT) {
|
|
||||||
value = compileTimeConstantResolver.getIntegerValue(text, context.expectedType);
|
|
||||||
}
|
|
||||||
else if (elementType == JetNodeTypes.FLOAT_CONSTANT) {
|
|
||||||
value = compileTimeConstantResolver.getFloatValue(text, context.expectedType);
|
|
||||||
}
|
|
||||||
else if (elementType == JetNodeTypes.BOOLEAN_CONSTANT) {
|
|
||||||
value = compileTimeConstantResolver.getBooleanValue(text, context.expectedType);
|
|
||||||
}
|
|
||||||
else if (elementType == JetNodeTypes.CHARACTER_CONSTANT) {
|
|
||||||
value = compileTimeConstantResolver.getCharValue(text, context.expectedType);
|
|
||||||
}
|
|
||||||
else if (elementType == JetNodeTypes.NULL) {
|
|
||||||
value = compileTimeConstantResolver.getNullValue(context.expectedType);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalArgumentException("Unsupported constant: " + expression);
|
|
||||||
}
|
|
||||||
if (value instanceof ErrorValue) {
|
if (value instanceof ErrorValue) {
|
||||||
ErrorValue errorValue = (ErrorValue) value;
|
if (context.expectedType != UNKNOWN_EXPECTED_TYPE) {
|
||||||
context.trace.report(ERROR_COMPILE_TIME_VALUE.on(node.getPsi(), errorValue.getMessage()));
|
context.trace.report(ERROR_COMPILE_TIME_VALUE.on(expression, ((ErrorValue) value).getMessage()));
|
||||||
|
}
|
||||||
return JetTypeInfo.create(getDefaultType(elementType), context.dataFlowInfo);
|
return JetTypeInfo.create(getDefaultType(elementType), context.dataFlowInfo);
|
||||||
}
|
}
|
||||||
else {
|
context.trace.record(BindingContext.COMPILE_TIME_VALUE, expression, value);
|
||||||
context.trace.record(BindingContext.COMPILE_TIME_VALUE, expression, value);
|
return DataFlowUtils.checkType(value.getType(builtIns), expression, context, context.dataFlowInfo);
|
||||||
return DataFlowUtils.checkType(value.getType(builtIns), expression, context, context.dataFlowInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ fun test() {
|
|||||||
|
|
||||||
bar(z = "")
|
bar(z = "")
|
||||||
bar(<!NO_VALUE_FOR_PARAMETER!>)<!>
|
bar(<!NO_VALUE_FOR_PARAMETER!>)<!>
|
||||||
bar(""<!NO_VALUE_FOR_PARAMETER!>)<!>
|
bar(<!TYPE_MISMATCH!>""<!><!NO_VALUE_FOR_PARAMETER!>)<!>
|
||||||
bar(1, 1, "")
|
bar(1, 1, "")
|
||||||
bar(1, 1, "")
|
bar(1, 1, "")
|
||||||
bar(1, z = "")
|
bar(1, z = "")
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ fun test() {
|
|||||||
|
|
||||||
val <!UNUSED_VARIABLE!>g<!>: Byte = <!TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>either<!>(1, 300)
|
val <!UNUSED_VARIABLE!>g<!>: Byte = <!TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>either<!>(1, 300)
|
||||||
|
|
||||||
other(<!TYPE_MISMATCH!>11<!>)
|
other(<!ERROR_COMPILE_TIME_VALUE!>11<!>)
|
||||||
|
|
||||||
<!TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH!>otherGeneric<!>(<!TYPE_MISMATCH!>1<!>)
|
<!TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH!>otherGeneric<!>(<!ERROR_COMPILE_TIME_VALUE!>1<!>)
|
||||||
|
|
||||||
val r = either(1, "")
|
val r = either(1, "")
|
||||||
<!TYPE_MISMATCH!>r<!>: Int
|
<!TYPE_MISMATCH!>r<!>: Int
|
||||||
|
|||||||
Reference in New Issue
Block a user