Data flow info always taken into account in safeGetType()
The dangerous method removed
This commit is contained in:
@@ -212,7 +212,7 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
else if (calleeExpression != null) {
|
else if (calleeExpression != null) {
|
||||||
// Here we handle the case where the callee expression must be something of type function, e.g. (foo.bar())(1, 2)
|
// Here we handle the case where the callee expression must be something of type function, e.g. (foo.bar())(1, 2)
|
||||||
JetType calleeType = expressionTypingServices.safeGetType(context.scope, calleeExpression, NO_EXPECTED_TYPE, context.trace); // We are actually expecting a function, but there seems to be no easy way of expressing this
|
JetType calleeType = expressionTypingServices.safeGetType(context.scope, calleeExpression, NO_EXPECTED_TYPE, context.dataFlowInfo, context.trace); // We are actually expecting a function, but there seems to be no easy way of expressing this
|
||||||
|
|
||||||
if (!JetStandardClasses.isFunctionType(calleeType)) {
|
if (!JetStandardClasses.isFunctionType(calleeType)) {
|
||||||
// checkTypesWithNoCallee(trace, scope, call);
|
// checkTypesWithNoCallee(trace, scope, call);
|
||||||
|
|||||||
+1
-1
@@ -350,7 +350,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
List<JetExpression> entries = expression.getEntries();
|
List<JetExpression> entries = expression.getEntries();
|
||||||
List<JetType> types = new ArrayList<JetType>();
|
List<JetType> types = new ArrayList<JetType>();
|
||||||
for (JetExpression entry : entries) {
|
for (JetExpression entry : entries) {
|
||||||
types.add(context.expressionTypingServices.safeGetType(context.scope, entry, NO_EXPECTED_TYPE, context.trace)); // TODO
|
types.add(context.expressionTypingServices.safeGetType(context.scope, entry, NO_EXPECTED_TYPE, context.dataFlowInfo, context.trace)); // TODO
|
||||||
}
|
}
|
||||||
if (context.expectedType != NO_EXPECTED_TYPE && JetStandardClasses.isTupleType(context.expectedType)) {
|
if (context.expectedType != NO_EXPECTED_TYPE && JetStandardClasses.isTupleType(context.expectedType)) {
|
||||||
List<JetType> enrichedTypes = checkArgumentTypes(types, entries, context.expectedType.getArguments(), context);
|
List<JetType> enrichedTypes = checkArgumentTypes(types, entries, context.expectedType.getArguments(), context);
|
||||||
|
|||||||
-5
@@ -107,11 +107,6 @@ public class ExpressionTypingServices {
|
|||||||
this.typeResolver = typeResolver;
|
this.typeResolver = typeResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public JetType safeGetType(@NotNull JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, BindingTrace trace) {
|
|
||||||
return safeGetType(scope, expression, expectedType, DataFlowInfo.EMPTY, trace);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JetType safeGetType(@NotNull JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo, BindingTrace trace) {
|
public JetType safeGetType(@NotNull JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo, BindingTrace trace) {
|
||||||
JetType type = getType(scope, expression, expectedType, dataFlowInfo, trace);
|
JetType type = getType(scope, expression, expectedType, dataFlowInfo, trace);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
|
|||||||
+3
-1
@@ -77,7 +77,9 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
// TODO :change scope according to the bound value in the when header
|
// TODO :change scope according to the bound value in the when header
|
||||||
final JetExpression subjectExpression = expression.getSubjectExpression();
|
final JetExpression subjectExpression = expression.getSubjectExpression();
|
||||||
|
|
||||||
final JetType subjectType = subjectExpression != null ? context.expressionTypingServices.safeGetType(context.scope, subjectExpression, TypeUtils.NO_EXPECTED_TYPE, context.trace) : ErrorUtils.createErrorType("Unknown type");
|
final JetType subjectType = subjectExpression != null
|
||||||
|
? context.expressionTypingServices.safeGetType(context.scope, subjectExpression, TypeUtils.NO_EXPECTED_TYPE, context.dataFlowInfo, context.trace)
|
||||||
|
: ErrorUtils.createErrorType("Unknown type");
|
||||||
final DataFlowValue variableDescriptor = subjectExpression != null ? DataFlowValueFactory.INSTANCE.createDataFlowValue(subjectExpression, subjectType, context.trace.getBindingContext()) : DataFlowValue.NULL;
|
final DataFlowValue variableDescriptor = subjectExpression != null ? DataFlowValueFactory.INSTANCE.createDataFlowValue(subjectExpression, subjectType, context.trace.getBindingContext()) : DataFlowValue.NULL;
|
||||||
|
|
||||||
// TODO : exhaustive patterns
|
// TODO : exhaustive patterns
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
class C(val f : () -> Unit)
|
||||||
|
|
||||||
|
fun test(e : Any) {
|
||||||
|
if (e is C) {
|
||||||
|
(e.f)()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
class C(val f : Int)
|
||||||
|
|
||||||
|
fun test(e : Any) {
|
||||||
|
if (e is C) {
|
||||||
|
#(e.f)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
trait Expr
|
||||||
|
class BinOp(val operator : String) : Expr
|
||||||
|
|
||||||
|
fun test(e : Expr) {
|
||||||
|
if (e is BinOp) {
|
||||||
|
when (e.operator) {
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
|||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.*;
|
import org.jetbrains.jet.lang.resolve.*;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||||
import org.jetbrains.jet.lang.resolve.java.*;
|
import org.jetbrains.jet.lang.resolve.java.*;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||||
@@ -557,7 +558,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
private void assertErrorType(String expression) {
|
private void assertErrorType(String expression) {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
||||||
JetType type = expressionTypingServices.safeGetType(scopeWithImports, jetExpression, TypeUtils.NO_EXPECTED_TYPE, JetTestUtils.DUMMY_TRACE);
|
JetType type = expressionTypingServices.safeGetType(scopeWithImports, jetExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, JetTestUtils.DUMMY_TRACE);
|
||||||
assertTrue("Error type expected but " + type + " returned", ErrorUtils.isErrorType(type));
|
assertTrue("Error type expected but " + type + " returned", ErrorUtils.isErrorType(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user