Use type from compile time value for binary expression

This commit is contained in:
Natalia Ukhorskaya
2013-12-04 18:10:37 +04:00
parent 6331dd2308
commit 53a5264aaf
42 changed files with 685 additions and 42 deletions
@@ -99,7 +99,12 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
override fun visitParenthesizedExpression(expression: JetParenthesizedExpression, expectedType: JetType?): CompileTimeConstant<*>? {
val deparenthesizedExpression = JetPsiUtil.deparenthesize(expression)
if (deparenthesizedExpression != null && deparenthesizedExpression != expression) {
return evaluate(deparenthesizedExpression, expectedType)
val compileTimeConstant = evaluate(deparenthesizedExpression, expectedType)
val isDeparentesizedPure = trace.get(BindingContext.IS_PURE_CONSTANT_EXPRESSION, deparenthesizedExpression)
if (isDeparentesizedPure != null && isDeparentesizedPure!!) {
trace.record(BindingContext.IS_PURE_CONSTANT_EXPRESSION, expression, true)
}
return compileTimeConstant
}
return null
}
@@ -359,7 +359,7 @@ public class CandidateResolver {
return;
}
if (storedContextForArgument == null) {
JetType type = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, expression);
JetType type = ArgumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, expression);
checkResultArgumentType(type, argument, context);
return;
}
@@ -372,7 +372,13 @@ public class CandidateResolver {
}
else {
completeNestedCallsInference(contextForArgument);
type = contextForArgument.candidateCall.getResultingDescriptor().getReturnType();
JetType recordedType = context.trace.get(BindingContext.EXPRESSION_TYPE, expression);
if (recordedType != null && !recordedType.getConstructor().isDenotable()) {
type = ArgumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, expression);
}
else {
type = contextForArgument.candidateCall.getResultingDescriptor().getReturnType();
}
checkValueArgumentTypes(contextForArgument);
}
JetType result = BindingContextUtils.updateRecordedType(
@@ -855,6 +855,11 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
context.trace.report(UNSUPPORTED.on(operationSign, "Unknown operation"));
result = JetTypeInfo.create(null, context.dataFlowInfo);
}
CompileTimeConstant<?> value = ConstantExpressionEvaluator.object$.
evaluate(expression, contextWithExpectedType.trace, contextWithExpectedType.expectedType);
if (value != null) {
return createCompileTimeConstantTypeInfo(value, expression, contextWithExpectedType);
}
return DataFlowUtils.checkType(result, expression, contextWithExpectedType);
}