replaced namespaceAllowed flag with ExpressionPosition enum

This commit is contained in:
Svetlana Isakova
2013-02-19 15:24:57 +04:00
parent 8206af0834
commit 6e51b83afc
15 changed files with 92 additions and 67 deletions
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor; import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
import org.jetbrains.jet.lang.psi.JetScript; import org.jetbrains.jet.lang.psi.JetScript;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; 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.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
@@ -73,7 +74,7 @@ public class ScriptBodyResolver {
scope, scope,
DataFlowInfo.EMPTY, DataFlowInfo.EMPTY,
NO_EXPECTED_TYPE, NO_EXPECTED_TYPE,
false); ExpressionPosition.FREE);
JetType returnType = expressionTypingServices.getBlockReturnedType(scope, declaration.getBlockExpression(), CoercionStrategy.NO_COERCION, context, trace).getType(); JetType returnType = expressionTypingServices.getBlockReturnedType(scope, declaration.getBlockExpression(), CoercionStrategy.NO_COERCION, context, trace).getType();
if (returnType == null) { if (returnType == null) {
returnType = ErrorUtils.createErrorType("getBlockReturnedType returned null"); returnType = ErrorUtils.createErrorType("getBlockReturnedType returned null");
@@ -25,9 +25,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace; import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; 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.*;
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.model.ResolvedCall; 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.results.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker; 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.BindingContext.*;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getStaticNestedClassesScope; 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; import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
public class CallExpressionResolver { public class CallExpressionResolver {
@@ -71,12 +68,12 @@ public class CallExpressionResolver {
if (classObjectType != null) { if (classObjectType != null) {
context.trace.record(REFERENCE_TARGET, expression, classifier); context.trace.record(REFERENCE_TARGET, expression, classifier);
JetType result; 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(), JetScope scope = new ChainedScope(classifier, classObjectType.getMemberScope(),
getStaticNestedClassesScope((ClassDescriptor) classifier)); getStaticNestedClassesScope((ClassDescriptor) classifier));
result = new NamespaceType(referencedName, scope); result = new NamespaceType(referencedName, scope);
} }
else if (context.namespacesAllowed || classifier.isClassObjectAValue()) { else if (context.expressionPosition == ExpressionPosition.LHS_OF_DOT || classifier.isClassObjectAValue()) {
result = classObjectType; result = classObjectType;
} }
else { else {
@@ -95,7 +92,7 @@ public class CallExpressionResolver {
} }
// To report NO_CLASS_OBJECT when no namespace found // To report NO_CLASS_OBJECT when no namespace found
if (classifier != null) { if (classifier != null) {
if (!context.namespacesAllowed) { if (context.expressionPosition == ExpressionPosition.FREE) {
context.trace.report(NO_CLASS_OBJECT.on(expression, classifier)); context.trace.report(NO_CLASS_OBJECT.on(expression, classifier));
} }
context.trace.record(REFERENCE_TARGET, expression, classifier); context.trace.record(REFERENCE_TARGET, expression, classifier);
@@ -117,7 +114,7 @@ public class CallExpressionResolver {
if (namespaceType == null) { if (namespaceType == null) {
return false; return false;
} }
if (context.namespacesAllowed) { if (context.expressionPosition == ExpressionPosition.LHS_OF_DOT) {
result[0] = namespaceType; result[0] = namespaceType;
return true; return true;
} }
@@ -218,7 +215,7 @@ public class CallExpressionResolver {
JetType type = getVariableType(nameExpression, receiver, callOperationNode, context.replaceBindingTrace(traceForVariable), result); JetType type = getVariableType(nameExpression, receiver, callOperationNode, context.replaceBindingTrace(traceForVariable), result);
if (result[0]) { if (result[0]) {
traceForVariable.commit(); traceForVariable.commit();
if (type instanceof NamespaceType && !context.namespacesAllowed) { if (type instanceof NamespaceType && context.expressionPosition == ExpressionPosition.FREE) {
type = null; type = null;
} }
return JetTypeInfo.create(type, context.dataFlowInfo); 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.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext; 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.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.context.ResolveMode;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallImpl; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallImpl;
@@ -128,7 +129,7 @@ public class CallResolver {
@NotNull JetType expectedType, @NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo @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 @NotNull
@@ -490,7 +491,7 @@ public class CallResolver {
public List<JetExpression> getFunctionLiteralArguments() { public List<JetExpression> getFunctionLiteralArguments() {
return Collections.emptyList(); 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); OverloadResolutionResultsImpl<F> resultsWithFunctionLiteralsStripped = performResolution(newTask, callTransformer, traceForResolutionCache);
if (resultsWithFunctionLiteralsStripped.isSuccess() || resultsWithFunctionLiteralsStripped.isAmbiguity()) { if (resultsWithFunctionLiteralsStripped.isSuccess() || resultsWithFunctionLiteralsStripped.isAmbiguity()) {
task.tracing.danglingFunctionLiteralArgumentSuspected(task.trace, task.call.getFunctionLiteralArguments()); 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(); final DelegatingBindingTrace variableCallTrace = context.candidateCall.getTrace();
BasicCallResolutionContext basicCallResolutionContext = BasicCallResolutionContext.create( 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 // 'invoke' call resolve
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithGivenName(basicCallResolutionContext, task.reference, Name.identifier("invoke")); OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithGivenName(basicCallResolutionContext, task.reference, Name.identifier("invoke"));
@@ -32,19 +32,20 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
@NotNull JetType expectedType, @NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull ResolveMode resolveMode, @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 @NotNull
public static BasicCallResolutionContext create(@NotNull ResolutionContext context, @NotNull Call call, @NotNull ResolveMode resolveMode) { 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( 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 @Override
@@ -53,9 +54,9 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
@NotNull JetScope scope, @NotNull JetScope scope,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType, @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 @Override
@@ -42,9 +42,9 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
@NotNull JetType expectedType, @NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull ResolveMode resolveMode, @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.candidateCall = candidateCall;
this.tracing = tracing; this.tracing = tracing;
} }
@@ -54,7 +54,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
@NotNull TracingStrategy tracing, @NotNull Call call) { @NotNull TracingStrategy tracing, @NotNull Call call) {
candidateCall.setInitialDataFlowInfo(context.dataFlowInfo); candidateCall.setInitialDataFlowInfo(context.dataFlowInfo);
return new CallCandidateResolutionContext<D>(candidateCall, tracing, trace, context.scope, call, context.expectedType, 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( 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 @NotNull ResolveMode resolveMode, @NotNull TracingStrategy tracing
) { ) {
return new CallCandidateResolutionContext<D>(candidateCall, tracing, context.trace, context.scope, call, 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 @Override
@@ -83,10 +83,10 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
@NotNull JetScope scope, @NotNull JetScope scope,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType, @NotNull JetType expectedType,
boolean namespacesAllowed ExpressionPosition expressionPosition
) { ) {
return new CallCandidateResolutionContext<D>( return new CallCandidateResolutionContext<D>(
candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, resolveMode, namespacesAllowed); candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, resolveMode, expressionPosition);
} }
@Override @Override
@@ -98,6 +98,6 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
public CallCandidateResolutionContext<D> replaceResolveMode(@NotNull ResolveMode newResolveMode) { public CallCandidateResolutionContext<D> replaceResolveMode(@NotNull ResolveMode newResolveMode) {
if (newResolveMode == resolveMode) return this; if (newResolveMode == resolveMode) return this;
return new CallCandidateResolutionContext<D>( return new CallCandidateResolutionContext<D>(
candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, newResolveMode, namespacesAllowed); candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, newResolveMode, expressionPosition);
} }
} }
@@ -33,14 +33,14 @@ public abstract class CallResolutionContext<Context extends CallResolutionContex
JetType expectedType, JetType expectedType,
DataFlowInfo dataFlowInfo, DataFlowInfo dataFlowInfo,
ResolveMode resolveMode, ResolveMode resolveMode,
boolean namespacesAllowed ExpressionPosition expressionPosition
) { ) {
super(trace, scope, expectedType, dataFlowInfo, namespacesAllowed); super(trace, scope, expectedType, dataFlowInfo, expressionPosition);
this.call = call; this.call = call;
this.resolveMode = resolveMode; this.resolveMode = resolveMode;
} }
public BasicCallResolutionContext toBasic() { public BasicCallResolutionContext toBasic() {
return BasicCallResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo, resolveMode, namespacesAllowed); return BasicCallResolutionContext.create(trace, scope, call, expectedType, dataFlowInfo, resolveMode, expressionPosition);
} }
} }
@@ -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.
}
@@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.resolve.calls.context;
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.Call;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; 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 JetScope scope;
public final JetType expectedType; public final JetType expectedType;
public final DataFlowInfo dataFlowInfo; public final DataFlowInfo dataFlowInfo;
// true for positions on the lhs of a '.', i.e. allows namespace results and 'super' public final ExpressionPosition expressionPosition;
public final boolean namespacesAllowed;
protected ResolutionContext( protected ResolutionContext(
BindingTrace trace, BindingTrace trace,
JetScope scope, JetScope scope,
JetType expectedType, JetType expectedType,
DataFlowInfo dataFlowInfo, DataFlowInfo dataFlowInfo,
boolean namespacesAllowed ExpressionPosition expressionPosition
) { ) {
this.trace = trace; this.trace = trace;
this.scope = scope; this.scope = scope;
this.expectedType = expectedType; this.expectedType = expectedType;
this.dataFlowInfo = dataFlowInfo; this.dataFlowInfo = dataFlowInfo;
this.namespacesAllowed = namespacesAllowed; this.expressionPosition = expressionPosition;
} }
protected abstract Context create( protected abstract Context create(
@@ -52,38 +50,38 @@ public abstract class ResolutionContext<Context extends ResolutionContext> {
@NotNull JetScope scope, @NotNull JetScope scope,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType, @NotNull JetType expectedType,
boolean namespacesAllowed ExpressionPosition expressionPosition
); );
protected abstract Context self(); protected abstract Context self();
public Context replaceBindingTrace(@NotNull BindingTrace trace) { public Context replaceBindingTrace(@NotNull BindingTrace trace) {
if (this.trace == trace) return self(); if (this.trace == trace) return self();
return create(trace, scope, dataFlowInfo, expectedType, namespacesAllowed); return create(trace, scope, dataFlowInfo, expectedType, expressionPosition);
} }
@NotNull @NotNull
public Context replaceNamespacesAllowed(boolean namespacesAllowed) { public Context replaceExpressionPosition(@NotNull ExpressionPosition expressionPosition) {
if (namespacesAllowed == this.namespacesAllowed) return self(); if (expressionPosition == this.expressionPosition) return self();
return create(trace, scope, dataFlowInfo, expectedType, namespacesAllowed); return create(trace, scope, dataFlowInfo, expectedType, expressionPosition);
} }
@NotNull @NotNull
public Context replaceDataFlowInfo(DataFlowInfo newDataFlowInfo) { public Context replaceDataFlowInfo(@NotNull DataFlowInfo newDataFlowInfo) {
if (newDataFlowInfo == dataFlowInfo) return self(); if (newDataFlowInfo == dataFlowInfo) return self();
return create(trace, scope, newDataFlowInfo, expectedType, namespacesAllowed); return create(trace, scope, newDataFlowInfo, expectedType, expressionPosition);
} }
@NotNull @NotNull
public Context replaceExpectedType(@Nullable JetType newExpectedType) { public Context replaceExpectedType(@Nullable JetType newExpectedType) {
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE); if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
if (expectedType == newExpectedType) return self(); if (expectedType == newExpectedType) return self();
return create(trace, scope, dataFlowInfo, newExpectedType, namespacesAllowed); return create(trace, scope, dataFlowInfo, newExpectedType, expressionPosition);
} }
@NotNull @NotNull
public Context replaceScope(@NotNull JetScope newScope) { public Context replaceScope(@NotNull JetScope newScope) {
if (newScope == scope) return self(); if (newScope == scope) return self();
return create(trace, newScope, dataFlowInfo, expectedType, namespacesAllowed); return create(trace, newScope, dataFlowInfo, expectedType, expressionPosition);
} }
} }
@@ -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.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext; 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.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.context.ResolveMode;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallWithTrace; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallWithTrace;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; 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( public ResolutionTask(
@NotNull Collection<ResolutionCandidate<D>> candidates, @NotNull JetReferenceExpression reference, @NotNull TracingStrategy tracing, @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) { 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);
this.candidates = candidates; this.candidates = candidates;
this.reference = reference; this.reference = reference;
this.tracing = tracing; this.tracing = tracing;
} }
public ResolutionTask(@NotNull Collection<ResolutionCandidate<D>> candidates, @NotNull JetReferenceExpression reference, @NotNull BasicCallResolutionContext context) { 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 @NotNull
@@ -83,9 +84,9 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
@NotNull JetScope scope, @NotNull JetScope scope,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType, @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); newTask.setCheckingStrategy(checkingStrategy);
return newTask; return newTask;
} }
@@ -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.DataFlowValue;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory; 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.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.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsUtil; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsUtil;
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker; 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.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.NO_EXPECTED_TYPE;
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.*; import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.*;
import static org.jetbrains.jet.lang.types.expressions.OperatorConventions.*;
@SuppressWarnings("SuspiciousMethodCalls") @SuppressWarnings("SuspiciousMethodCalls")
public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
@@ -421,7 +421,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
public JetTypeInfo visitSuperExpression(JetSuperExpression expression, ExpressionTypingContext context) { public JetTypeInfo visitSuperExpression(JetSuperExpression expression, ExpressionTypingContext context) {
LabelResolver.LabeledReceiverResolutionResult resolutionResult = resolveToReceiver(expression, context, true); 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())); context.trace.report(SUPER_IS_NOT_AN_EXPRESSION.on(expression, expression.getText()));
return errorInSuper(expression, context); return errorInSuper(expression, context);
} }
@@ -1036,7 +1036,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
@Override @Override
public JetTypeInfo visitRootNamespaceExpression(JetRootNamespaceExpression expression, ExpressionTypingContext context) { 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); return DataFlowUtils.checkType(JetModuleUtil.getRootNamespaceType(expression), expression, context, context.dataFlowInfo);
} }
context.trace.report(NAMESPACE_IS_NOT_AN_EXPRESSION.on(expression)); context.trace.report(NAMESPACE_IS_NOT_AN_EXPRESSION.on(expression));
@@ -23,6 +23,7 @@ import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; 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.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.ResolutionContext;
import org.jetbrains.jet.lang.resolve.calls.context.ResolveMode; import org.jetbrains.jet.lang.resolve.calls.context.ResolveMode;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
@@ -40,8 +41,8 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull JetScope scope, @NotNull JetScope scope,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType, @NotNull JetType expectedType,
boolean namespacesAllowed) { ExpressionPosition expressionPosition) {
return newContext(expressionTypingServices, new LabelResolver(), trace, scope, dataFlowInfo, expectedType, namespacesAllowed); return newContext(expressionTypingServices, new LabelResolver(), trace, scope, dataFlowInfo, expectedType, expressionPosition);
} }
@NotNull @NotNull
@@ -52,9 +53,9 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull JetScope scope, @NotNull JetScope scope,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType, @NotNull JetType expectedType,
boolean namespacesAllowed) { ExpressionPosition expressionPosition) {
return new ExpressionTypingContext(expressionTypingServices, return new ExpressionTypingContext(expressionTypingServices,
labelResolver, trace, scope, dataFlowInfo, expectedType, namespacesAllowed); labelResolver, trace, scope, dataFlowInfo, expectedType, expressionPosition);
} }
public final ExpressionTypingServices expressionTypingServices; public final ExpressionTypingServices expressionTypingServices;
@@ -70,8 +71,8 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull JetScope scope, @NotNull JetScope scope,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType, @NotNull JetType expectedType,
boolean namespacesAllowed) { ExpressionPosition expressionPosition) {
super(trace, scope, expectedType, dataFlowInfo, namespacesAllowed); super(trace, scope, expectedType, dataFlowInfo, expressionPosition);
this.expressionTypingServices = expressionTypingServices; this.expressionTypingServices = expressionTypingServices;
this.labelResolver = labelResolver; this.labelResolver = labelResolver;
} }
@@ -82,9 +83,9 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull JetScope scope, @NotNull JetScope scope,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType, @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 @Override
@@ -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.CallExpressionResolver;
import org.jetbrains.jet.lang.resolve.calls.CallResolver; import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; 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.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl; import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
@@ -129,7 +130,7 @@ public class ExpressionTypingServices {
@NotNull @NotNull
public JetTypeInfo getTypeInfo(@NotNull final JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo, @NotNull BindingTrace trace) { public JetTypeInfo getTypeInfo(@NotNull final JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo, @NotNull BindingTrace trace) {
ExpressionTypingContext context = ExpressionTypingContext.newContext( ExpressionTypingContext context = ExpressionTypingContext.newContext(
this, trace, scope, dataFlowInfo, expectedType, false this, trace, scope, dataFlowInfo, expectedType, ExpressionPosition.FREE
); );
return expressionTypingFacade.getTypeInfo(expression, context); 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) { public JetTypeInfo getTypeInfoWithNamespaces(@NotNull JetExpression expression, @NotNull JetScope scope, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo, @NotNull BindingTrace trace) {
ExpressionTypingContext context = ExpressionTypingContext.newContext( ExpressionTypingContext context = ExpressionTypingContext.newContext(
this, trace, scope, dataFlowInfo, expectedType, true); this, trace, scope, dataFlowInfo, expectedType, ExpressionPosition.LHS_OF_DOT);
return expressionTypingFacade.getTypeInfo(expression, context); return expressionTypingFacade.getTypeInfo(expression, context);
} }
@@ -165,7 +166,7 @@ public class ExpressionTypingServices {
} }
} }
checkFunctionReturnType(function, ExpressionTypingContext.newContext( 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); ), trace);
} }
@@ -232,7 +233,7 @@ public class ExpressionTypingServices {
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace); JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace);
expressionTypingFacade.getTypeInfo(bodyExpression, ExpressionTypingContext.newContext( expressionTypingFacade.getTypeInfo(bodyExpression, ExpressionTypingContext.newContext(
this, 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 //todo function literals
final Collection<JetExpression> returnedExpressions = Lists.newArrayList(); final Collection<JetExpression> returnedExpressions = Lists.newArrayList();
if (function.hasBlockBody()) { if (function.hasBlockBody()) {
@@ -363,7 +364,7 @@ public class ExpressionTypingServices {
private ExpressionTypingContext createContext(ExpressionTypingContext oldContext, BindingTrace trace, WritableScope scope, DataFlowInfo dataFlowInfo, JetType expectedType) { private ExpressionTypingContext createContext(ExpressionTypingContext oldContext, BindingTrace trace, WritableScope scope, DataFlowInfo dataFlowInfo, JetType expectedType) {
return ExpressionTypingContext.newContext( return ExpressionTypingContext.newContext(
this, oldContext.labelResolver, trace, scope, dataFlowInfo, expectedType, oldContext.namespacesAllowed); this, oldContext.labelResolver, trace, scope, dataFlowInfo, expectedType, oldContext.expressionPosition);
} }
@Nullable @Nullable
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.Errors;
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.context.ExpressionPosition;
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker; 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.results.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
@@ -166,7 +167,7 @@ public class ExpressionTypingUtils {
scope, scope,
DataFlowInfo.EMPTY, DataFlowInfo.EMPTY,
TypeUtils.NO_EXPECTED_TYPE, TypeUtils.NO_EXPECTED_TYPE,
false ExpressionPosition.FREE
); );
return ControlStructureTypingVisitor.checkIterableConvention(expressionReceiver, context) != null; 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.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.resolve.BindingTraceContext; import org.jetbrains.jet.lang.resolve.BindingTraceContext;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; 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.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.java.PsiClassFinder; import org.jetbrains.jet.lang.resolve.java.PsiClassFinder;
@@ -132,7 +133,7 @@ public class JetExpectedResolveDataUtil {
ExpressionTypingContext context = ExpressionTypingContext.newContext( ExpressionTypingContext context = ExpressionTypingContext.newContext(
expressionTypingServices, new BindingTraceContext(), classDescriptor.getDefaultType().getMemberScope(), 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( OverloadResolutionResults<FunctionDescriptor> functions = resolveFakeCall(
context, ReceiverValue.NO_RECEIVER, Name.identifier(name), parameterTypes); context, ReceiverValue.NO_RECEIVER, Name.identifier(name), parameterTypes);