replaced namespaceAllowed flag with ExpressionPosition enum
This commit is contained in:
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetScript;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ExpressionPosition;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -73,7 +74,7 @@ public class ScriptBodyResolver {
|
||||
scope,
|
||||
DataFlowInfo.EMPTY,
|
||||
NO_EXPECTED_TYPE,
|
||||
false);
|
||||
ExpressionPosition.FREE);
|
||||
JetType returnType = expressionTypingServices.getBlockReturnedType(scope, declaration.getBlockExpression(), CoercionStrategy.NO_COERCION, context, trace).getType();
|
||||
if (returnType == null) {
|
||||
returnType = ErrorUtils.createErrorType("getBlockReturnedType returned null");
|
||||
|
||||
+6
-9
@@ -25,9 +25,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.TypeInfoForCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||
@@ -50,7 +48,6 @@ import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getStaticNestedClassesScope;
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ResolveMode;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
|
||||
public class CallExpressionResolver {
|
||||
@@ -71,12 +68,12 @@ public class CallExpressionResolver {
|
||||
if (classObjectType != null) {
|
||||
context.trace.record(REFERENCE_TARGET, expression, classifier);
|
||||
JetType result;
|
||||
if (context.namespacesAllowed && classifier instanceof ClassDescriptor) {
|
||||
if (context.expressionPosition == ExpressionPosition.LHS_OF_DOT && classifier instanceof ClassDescriptor) {
|
||||
JetScope scope = new ChainedScope(classifier, classObjectType.getMemberScope(),
|
||||
getStaticNestedClassesScope((ClassDescriptor) classifier));
|
||||
result = new NamespaceType(referencedName, scope);
|
||||
}
|
||||
else if (context.namespacesAllowed || classifier.isClassObjectAValue()) {
|
||||
else if (context.expressionPosition == ExpressionPosition.LHS_OF_DOT || classifier.isClassObjectAValue()) {
|
||||
result = classObjectType;
|
||||
}
|
||||
else {
|
||||
@@ -95,7 +92,7 @@ public class CallExpressionResolver {
|
||||
}
|
||||
// To report NO_CLASS_OBJECT when no namespace found
|
||||
if (classifier != null) {
|
||||
if (!context.namespacesAllowed) {
|
||||
if (context.expressionPosition == ExpressionPosition.FREE) {
|
||||
context.trace.report(NO_CLASS_OBJECT.on(expression, classifier));
|
||||
}
|
||||
context.trace.record(REFERENCE_TARGET, expression, classifier);
|
||||
@@ -117,7 +114,7 @@ public class CallExpressionResolver {
|
||||
if (namespaceType == null) {
|
||||
return false;
|
||||
}
|
||||
if (context.namespacesAllowed) {
|
||||
if (context.expressionPosition == ExpressionPosition.LHS_OF_DOT) {
|
||||
result[0] = namespaceType;
|
||||
return true;
|
||||
}
|
||||
@@ -218,7 +215,7 @@ public class CallExpressionResolver {
|
||||
JetType type = getVariableType(nameExpression, receiver, callOperationNode, context.replaceBindingTrace(traceForVariable), result);
|
||||
if (result[0]) {
|
||||
traceForVariable.commit();
|
||||
if (type instanceof NamespaceType && !context.namespacesAllowed) {
|
||||
if (type instanceof NamespaceType && context.expressionPosition == ExpressionPosition.FREE) {
|
||||
type = null;
|
||||
}
|
||||
return JetTypeInfo.create(type, context.dataFlowInfo);
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.CallCandidateResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ExpressionPosition;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ResolveMode;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallImpl;
|
||||
@@ -128,7 +129,7 @@ public class CallResolver {
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull DataFlowInfo dataFlowInfo
|
||||
) {
|
||||
return resolveFunctionCall(BasicCallResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo, ResolveMode.TOP_LEVEL_CALL, false));
|
||||
return resolveFunctionCall(BasicCallResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo, ResolveMode.TOP_LEVEL_CALL, ExpressionPosition.FREE));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -490,7 +491,7 @@ public class CallResolver {
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}, task.expectedType, task.dataFlowInfo, task.resolveMode, task.namespacesAllowed);
|
||||
}, task.expectedType, task.dataFlowInfo, task.resolveMode, task.expressionPosition);
|
||||
OverloadResolutionResultsImpl<F> resultsWithFunctionLiteralsStripped = performResolution(newTask, callTransformer, traceForResolutionCache);
|
||||
if (resultsWithFunctionLiteralsStripped.isSuccess() || resultsWithFunctionLiteralsStripped.isAmbiguity()) {
|
||||
task.tracing.danglingFunctionLiteralArgumentSuspected(task.trace, task.call.getFunctionLiteralArguments());
|
||||
|
||||
@@ -193,7 +193,7 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
|
||||
|
||||
final DelegatingBindingTrace variableCallTrace = context.candidateCall.getTrace();
|
||||
BasicCallResolutionContext basicCallResolutionContext = BasicCallResolutionContext.create(
|
||||
variableCallTrace, context.scope, functionCall, context.expectedType, context.dataFlowInfo, context.resolveMode, context.namespacesAllowed);
|
||||
variableCallTrace, context.scope, functionCall, context.expectedType, context.dataFlowInfo, context.resolveMode, context.expressionPosition);
|
||||
|
||||
// 'invoke' call resolve
|
||||
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithGivenName(basicCallResolutionContext, task.reference, Name.identifier("invoke"));
|
||||
|
||||
+8
-7
@@ -32,19 +32,20 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull ResolveMode resolveMode,
|
||||
boolean namespacesAllowed
|
||||
ExpressionPosition expressionPosition
|
||||
) {
|
||||
return new BasicCallResolutionContext(trace, scope, call, expectedType, dataFlowInfo, resolveMode, namespacesAllowed);
|
||||
return new BasicCallResolutionContext(trace, scope, call, expectedType, dataFlowInfo, resolveMode, expressionPosition);
|
||||
}
|
||||
@NotNull
|
||||
public static BasicCallResolutionContext create(@NotNull ResolutionContext context, @NotNull Call call, @NotNull ResolveMode resolveMode) {
|
||||
return create(context.trace, context.scope, call, context.expectedType, context.dataFlowInfo, resolveMode, context.namespacesAllowed);
|
||||
return create(context.trace, context.scope, call, context.expectedType, context.dataFlowInfo, resolveMode, context.expressionPosition);
|
||||
}
|
||||
|
||||
private BasicCallResolutionContext(
|
||||
BindingTrace trace, JetScope scope, Call call, JetType expectedType, DataFlowInfo dataFlowInfo, ResolveMode resolveMode, boolean namespacesAllowed
|
||||
BindingTrace trace, JetScope scope, Call call, JetType expectedType,
|
||||
DataFlowInfo dataFlowInfo, ResolveMode resolveMode, ExpressionPosition expressionPosition
|
||||
) {
|
||||
super(trace, scope, call, expectedType, dataFlowInfo, resolveMode, namespacesAllowed);
|
||||
super(trace, scope, call, expectedType, dataFlowInfo, resolveMode, expressionPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,9 +54,9 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed
|
||||
ExpressionPosition expressionPosition
|
||||
) {
|
||||
return create(trace, scope, call, expectedType, dataFlowInfo, resolveMode, namespacesAllowed);
|
||||
return create(trace, scope, call, expectedType, dataFlowInfo, resolveMode, expressionPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-7
@@ -42,9 +42,9 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull ResolveMode resolveMode,
|
||||
boolean namespacesAllowed
|
||||
ExpressionPosition expressionPosition
|
||||
) {
|
||||
super(trace, scope, call, expectedType, dataFlowInfo, resolveMode, namespacesAllowed);
|
||||
super(trace, scope, call, expectedType, dataFlowInfo, resolveMode, expressionPosition);
|
||||
this.candidateCall = candidateCall;
|
||||
this.tracing = tracing;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
|
||||
@NotNull TracingStrategy tracing, @NotNull Call call) {
|
||||
candidateCall.setInitialDataFlowInfo(context.dataFlowInfo);
|
||||
return new CallCandidateResolutionContext<D>(candidateCall, tracing, trace, context.scope, call, context.expectedType,
|
||||
context.dataFlowInfo, context.resolveMode, context.namespacesAllowed);
|
||||
context.dataFlowInfo, context.resolveMode, context.expressionPosition);
|
||||
}
|
||||
|
||||
public static <D extends CallableDescriptor> CallCandidateResolutionContext<D> create(
|
||||
@@ -74,7 +74,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
|
||||
@NotNull ResolveMode resolveMode, @NotNull TracingStrategy tracing
|
||||
) {
|
||||
return new CallCandidateResolutionContext<D>(candidateCall, tracing, context.trace, context.scope, call,
|
||||
context.expectedType, context.dataFlowInfo, resolveMode, context.namespacesAllowed);
|
||||
context.expectedType, context.dataFlowInfo, resolveMode, context.expressionPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,10 +83,10 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed
|
||||
ExpressionPosition expressionPosition
|
||||
) {
|
||||
return new CallCandidateResolutionContext<D>(
|
||||
candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, resolveMode, namespacesAllowed);
|
||||
candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, resolveMode, expressionPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,6 +98,6 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
|
||||
public CallCandidateResolutionContext<D> replaceResolveMode(@NotNull ResolveMode newResolveMode) {
|
||||
if (newResolveMode == resolveMode) return this;
|
||||
return new CallCandidateResolutionContext<D>(
|
||||
candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, newResolveMode, namespacesAllowed);
|
||||
candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, newResolveMode, expressionPosition);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -33,14 +33,14 @@ public abstract class CallResolutionContext<Context extends CallResolutionContex
|
||||
JetType expectedType,
|
||||
DataFlowInfo dataFlowInfo,
|
||||
ResolveMode resolveMode,
|
||||
boolean namespacesAllowed
|
||||
ExpressionPosition expressionPosition
|
||||
) {
|
||||
super(trace, scope, expectedType, dataFlowInfo, namespacesAllowed);
|
||||
super(trace, scope, expectedType, dataFlowInfo, expressionPosition);
|
||||
this.call = call;
|
||||
this.resolveMode = resolveMode;
|
||||
}
|
||||
|
||||
public BasicCallResolutionContext toBasic() {
|
||||
return BasicCallResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo, resolveMode, namespacesAllowed);
|
||||
return BasicCallResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo, resolveMode, expressionPosition);
|
||||
}
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.calls.context;
|
||||
|
||||
public enum ExpressionPosition {
|
||||
LHS_OF_DOT, // allows all free expressions and additionally packages, class objects, 'super', 'this'
|
||||
FREE // statements, function arguments, etc.
|
||||
}
|
||||
+12
-14
@@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.resolve.calls.context;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.Call;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -30,21 +29,20 @@ public abstract class ResolutionContext<Context extends ResolutionContext> {
|
||||
public final JetScope scope;
|
||||
public final JetType expectedType;
|
||||
public final DataFlowInfo dataFlowInfo;
|
||||
// true for positions on the lhs of a '.', i.e. allows namespace results and 'super'
|
||||
public final boolean namespacesAllowed;
|
||||
public final ExpressionPosition expressionPosition;
|
||||
|
||||
protected ResolutionContext(
|
||||
BindingTrace trace,
|
||||
JetScope scope,
|
||||
JetType expectedType,
|
||||
DataFlowInfo dataFlowInfo,
|
||||
boolean namespacesAllowed
|
||||
ExpressionPosition expressionPosition
|
||||
) {
|
||||
this.trace = trace;
|
||||
this.scope = scope;
|
||||
this.expectedType = expectedType;
|
||||
this.dataFlowInfo = dataFlowInfo;
|
||||
this.namespacesAllowed = namespacesAllowed;
|
||||
this.expressionPosition = expressionPosition;
|
||||
}
|
||||
|
||||
protected abstract Context create(
|
||||
@@ -52,38 +50,38 @@ public abstract class ResolutionContext<Context extends ResolutionContext> {
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed
|
||||
ExpressionPosition expressionPosition
|
||||
);
|
||||
|
||||
protected abstract Context self();
|
||||
|
||||
public Context replaceBindingTrace(@NotNull BindingTrace trace) {
|
||||
if (this.trace == trace) return self();
|
||||
return create(trace, scope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
return create(trace, scope, dataFlowInfo, expectedType, expressionPosition);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Context replaceNamespacesAllowed(boolean namespacesAllowed) {
|
||||
if (namespacesAllowed == this.namespacesAllowed) return self();
|
||||
return create(trace, scope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
public Context replaceExpressionPosition(@NotNull ExpressionPosition expressionPosition) {
|
||||
if (expressionPosition == this.expressionPosition) return self();
|
||||
return create(trace, scope, dataFlowInfo, expectedType, expressionPosition);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Context replaceDataFlowInfo(DataFlowInfo newDataFlowInfo) {
|
||||
public Context replaceDataFlowInfo(@NotNull DataFlowInfo newDataFlowInfo) {
|
||||
if (newDataFlowInfo == dataFlowInfo) return self();
|
||||
return create(trace, scope, newDataFlowInfo, expectedType, namespacesAllowed);
|
||||
return create(trace, scope, newDataFlowInfo, expectedType, expressionPosition);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Context replaceExpectedType(@Nullable JetType newExpectedType) {
|
||||
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
|
||||
if (expectedType == newExpectedType) return self();
|
||||
return create(trace, scope, dataFlowInfo, newExpectedType, namespacesAllowed);
|
||||
return create(trace, scope, dataFlowInfo, newExpectedType, expressionPosition);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Context replaceScope(@NotNull JetScope newScope) {
|
||||
if (newScope == scope) return self();
|
||||
return create(trace, newScope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
return create(trace, newScope, dataFlowInfo, expectedType, expressionPosition);
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.CallResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ExpressionPosition;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ResolveMode;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallWithTrace;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -45,15 +46,15 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
|
||||
|
||||
public ResolutionTask(
|
||||
@NotNull Collection<ResolutionCandidate<D>> candidates, @NotNull JetReferenceExpression reference, @NotNull TracingStrategy tracing,
|
||||
BindingTrace trace, JetScope scope, Call call, JetType expectedType, DataFlowInfo dataFlowInfo, ResolveMode resolveMode, boolean namespacesAllowed) {
|
||||
super(trace, scope, call, expectedType, dataFlowInfo, resolveMode, namespacesAllowed);
|
||||
BindingTrace trace, JetScope scope, Call call, JetType expectedType, DataFlowInfo dataFlowInfo, ResolveMode resolveMode, ExpressionPosition expressionPosition) {
|
||||
super(trace, scope, call, expectedType, dataFlowInfo, resolveMode, expressionPosition);
|
||||
this.candidates = candidates;
|
||||
this.reference = reference;
|
||||
this.tracing = tracing;
|
||||
}
|
||||
|
||||
public ResolutionTask(@NotNull Collection<ResolutionCandidate<D>> candidates, @NotNull JetReferenceExpression reference, @NotNull BasicCallResolutionContext context) {
|
||||
this(candidates, reference, TracingStrategyImpl.create(reference, context.call), context.trace, context.scope, context.call, context.expectedType, context.dataFlowInfo, context.resolveMode, context.namespacesAllowed);
|
||||
this(candidates, reference, TracingStrategyImpl.create(reference, context.call), context.trace, context.scope, context.call, context.expectedType, context.dataFlowInfo, context.resolveMode, context.expressionPosition);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -83,9 +84,9 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed
|
||||
ExpressionPosition expressionPosition
|
||||
) {
|
||||
ResolutionTask<D, F> newTask = new ResolutionTask<D, F>(candidates, reference, tracing, trace, scope, call, expectedType, dataFlowInfo, resolveMode, namespacesAllowed);
|
||||
ResolutionTask<D, F> newTask = new ResolutionTask<D, F>(candidates, reference, tracing, trace, scope, call, expectedType, dataFlowInfo, resolveMode, expressionPosition);
|
||||
newTask.setCheckingStrategy(checkingStrategy);
|
||||
return newTask;
|
||||
}
|
||||
|
||||
+3
-3
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ExpressionPosition;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsUtil;
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||
@@ -57,7 +58,6 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
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.expressions.ExpressionTypingUtils.*;
|
||||
import static org.jetbrains.jet.lang.types.expressions.OperatorConventions.*;
|
||||
|
||||
@SuppressWarnings("SuspiciousMethodCalls")
|
||||
public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
@@ -421,7 +421,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
public JetTypeInfo visitSuperExpression(JetSuperExpression expression, ExpressionTypingContext context) {
|
||||
LabelResolver.LabeledReceiverResolutionResult resolutionResult = resolveToReceiver(expression, context, true);
|
||||
|
||||
if (!context.namespacesAllowed) {
|
||||
if (context.expressionPosition == ExpressionPosition.FREE) {
|
||||
context.trace.report(SUPER_IS_NOT_AN_EXPRESSION.on(expression, expression.getText()));
|
||||
return errorInSuper(expression, context);
|
||||
}
|
||||
@@ -1036,7 +1036,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
|
||||
@Override
|
||||
public JetTypeInfo visitRootNamespaceExpression(JetRootNamespaceExpression expression, ExpressionTypingContext context) {
|
||||
if (context.namespacesAllowed) {
|
||||
if (context.expressionPosition == ExpressionPosition.LHS_OF_DOT) {
|
||||
return DataFlowUtils.checkType(JetModuleUtil.getRootNamespaceType(expression), expression, context, context.dataFlowInfo);
|
||||
}
|
||||
context.trace.report(NAMESPACE_IS_NOT_AN_EXPRESSION.on(expression));
|
||||
|
||||
+9
-8
@@ -23,6 +23,7 @@ import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ExpressionPosition;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ResolveMode;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
|
||||
@@ -40,8 +41,8 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed) {
|
||||
return newContext(expressionTypingServices, new LabelResolver(), trace, scope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
ExpressionPosition expressionPosition) {
|
||||
return newContext(expressionTypingServices, new LabelResolver(), trace, scope, dataFlowInfo, expectedType, expressionPosition);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -52,9 +53,9 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed) {
|
||||
ExpressionPosition expressionPosition) {
|
||||
return new ExpressionTypingContext(expressionTypingServices,
|
||||
labelResolver, trace, scope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
labelResolver, trace, scope, dataFlowInfo, expectedType, expressionPosition);
|
||||
}
|
||||
|
||||
public final ExpressionTypingServices expressionTypingServices;
|
||||
@@ -70,8 +71,8 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed) {
|
||||
super(trace, scope, expectedType, dataFlowInfo, namespacesAllowed);
|
||||
ExpressionPosition expressionPosition) {
|
||||
super(trace, scope, expectedType, dataFlowInfo, expressionPosition);
|
||||
this.expressionTypingServices = expressionTypingServices;
|
||||
this.labelResolver = labelResolver;
|
||||
}
|
||||
@@ -82,9 +83,9 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull JetType expectedType,
|
||||
boolean namespacesAllowed
|
||||
ExpressionPosition expressionPosition
|
||||
) {
|
||||
return new ExpressionTypingContext(expressionTypingServices, labelResolver, trace, scope, dataFlowInfo, expectedType, namespacesAllowed);
|
||||
return new ExpressionTypingContext(expressionTypingServices, labelResolver, trace, scope, dataFlowInfo, expectedType, expressionPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-5
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallExpressionResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ExpressionPosition;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
@@ -129,7 +130,7 @@ public class ExpressionTypingServices {
|
||||
@NotNull
|
||||
public JetTypeInfo getTypeInfo(@NotNull final JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo, @NotNull BindingTrace trace) {
|
||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||
this, trace, scope, dataFlowInfo, expectedType, false
|
||||
this, trace, scope, dataFlowInfo, expectedType, ExpressionPosition.FREE
|
||||
);
|
||||
return expressionTypingFacade.getTypeInfo(expression, context);
|
||||
}
|
||||
@@ -141,7 +142,7 @@ public class ExpressionTypingServices {
|
||||
|
||||
public JetTypeInfo getTypeInfoWithNamespaces(@NotNull JetExpression expression, @NotNull JetScope scope, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo, @NotNull BindingTrace trace) {
|
||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||
this, trace, scope, dataFlowInfo, expectedType, true);
|
||||
this, trace, scope, dataFlowInfo, expectedType, ExpressionPosition.LHS_OF_DOT);
|
||||
return expressionTypingFacade.getTypeInfo(expression, context);
|
||||
}
|
||||
|
||||
@@ -165,7 +166,7 @@ public class ExpressionTypingServices {
|
||||
}
|
||||
}
|
||||
checkFunctionReturnType(function, ExpressionTypingContext.newContext(
|
||||
this, trace, functionInnerScope, dataFlowInfo, expectedReturnType != null ? expectedReturnType : NO_EXPECTED_TYPE, false
|
||||
this, trace, functionInnerScope, dataFlowInfo, expectedReturnType != null ? expectedReturnType : NO_EXPECTED_TYPE, ExpressionPosition.FREE
|
||||
), trace);
|
||||
}
|
||||
|
||||
@@ -232,7 +233,7 @@ public class ExpressionTypingServices {
|
||||
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace);
|
||||
expressionTypingFacade.getTypeInfo(bodyExpression, ExpressionTypingContext.newContext(
|
||||
this,
|
||||
trace, functionInnerScope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, false), !function.hasBlockBody());
|
||||
trace, functionInnerScope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, ExpressionPosition.FREE), !function.hasBlockBody());
|
||||
//todo function literals
|
||||
final Collection<JetExpression> returnedExpressions = Lists.newArrayList();
|
||||
if (function.hasBlockBody()) {
|
||||
@@ -363,7 +364,7 @@ public class ExpressionTypingServices {
|
||||
|
||||
private ExpressionTypingContext createContext(ExpressionTypingContext oldContext, BindingTrace trace, WritableScope scope, DataFlowInfo dataFlowInfo, JetType expectedType) {
|
||||
return ExpressionTypingContext.newContext(
|
||||
this, oldContext.labelResolver, trace, scope, dataFlowInfo, expectedType, oldContext.namespacesAllowed);
|
||||
this, oldContext.labelResolver, trace, scope, dataFlowInfo, expectedType, oldContext.expressionPosition);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+2
-1
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ExpressionPosition;
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
@@ -166,7 +167,7 @@ public class ExpressionTypingUtils {
|
||||
scope,
|
||||
DataFlowInfo.EMPTY,
|
||||
TypeUtils.NO_EXPECTED_TYPE,
|
||||
false
|
||||
ExpressionPosition.FREE
|
||||
);
|
||||
return ControlStructureTypingVisitor.checkIterableConvention(expressionReceiver, context) != null;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ExpressionPosition;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
|
||||
import org.jetbrains.jet.lang.resolve.java.PsiClassFinder;
|
||||
@@ -132,7 +133,7 @@ public class JetExpectedResolveDataUtil {
|
||||
|
||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||
expressionTypingServices, new BindingTraceContext(), classDescriptor.getDefaultType().getMemberScope(),
|
||||
DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE, false);
|
||||
DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE, ExpressionPosition.FREE);
|
||||
|
||||
OverloadResolutionResults<FunctionDescriptor> functions = resolveFakeCall(
|
||||
context, ReceiverValue.NO_RECEIVER, Name.identifier(name), parameterTypes);
|
||||
|
||||
Reference in New Issue
Block a user