Propagate languageVersionSettings to resolution context

This commit is contained in:
Mikhail Zarechenskiy
2017-09-12 17:25:50 +03:00
parent 6336ad874b
commit b1d9abdf83
16 changed files with 116 additions and 74 deletions
@@ -304,7 +304,7 @@ class DelegatedPropertyResolver(
else
TypeUtils.NO_EXPECTED_TYPE
val context = ExpressionTypingContext.newContext(trace, delegateFunctionsScope, dataFlowInfo, expectedType)
val context = ExpressionTypingContext.newContext(trace, delegateFunctionsScope, dataFlowInfo, expectedType, languageVersionSettings)
val hasThis = propertyDescriptor.extensionReceiverParameter != null || propertyDescriptor.dispatchReceiverParameter != null
@@ -339,7 +339,7 @@ class DelegatedPropertyResolver(
initializerScope: LexicalScope,
dataFlowInfo: DataFlowInfo
): OverloadResolutionResults<FunctionDescriptor> {
val context = ExpressionTypingContext.newContext(trace, initializerScope, dataFlowInfo, NO_EXPECTED_TYPE)
val context = ExpressionTypingContext.newContext(trace, initializerScope, dataFlowInfo, NO_EXPECTED_TYPE, languageVersionSettings)
return getProvideDelegateMethod(propertyDescriptor, delegateExpression, delegateExpressionType, context)
}
@@ -537,7 +537,8 @@ class DelegatedPropertyResolver(
traceToResolveConventionMethods, false, delegateExpression, ContextDependency.DEPENDENT)
val contextForProvideDelegate = ExpressionTypingContext.newContext(traceToResolveConventionMethods, scopeForDelegate, delegateType.dataFlowInfo,
NO_EXPECTED_TYPE, ContextDependency.DEPENDENT, StatementFilter.NONE)
NO_EXPECTED_TYPE, ContextDependency.DEPENDENT, StatementFilter.NONE,
languageVersionSettings)
val provideDelegateResults = getProvideDelegateMethod(
variableDescriptor, delegateExpression, delegateType.type ?: return null, contextForProvideDelegate
@@ -337,7 +337,7 @@ public class DescriptorResolver {
scope,
destructuringDeclaration, new TransientReceiver(type), /* initializer = */ null,
ExpressionTypingContext.newContext(
trace, scopeForDestructuring, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE
trace, scopeForDestructuring, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE, languageVersionSettings
)
);
@@ -782,7 +782,7 @@ public class DescriptorResolver {
KtExpression initializer = destructuringDeclaration.getInitializer();
ExpressionTypingContext context = ExpressionTypingContext.newContext(
trace, scopeForDeclarationResolution, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE
trace, scopeForDeclarationResolution, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE, languageVersionSettings
);
ExpressionReceiver receiver = createReceiverForDestructuringDeclaration(destructuringDeclaration, context);
@@ -303,7 +303,7 @@ public class CallResolver {
return resolveFunctionCall(
BasicCallResolutionContext.create(
trace, scope, call, expectedType, dataFlowInfo, ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
isAnnotationContext
isAnnotationContext, languageVersionSettings
)
);
}
@@ -429,7 +429,8 @@ public class CallResolver {
CallMaker.makeCall(null, null, call),
NO_EXPECTED_TYPE,
dataFlowInfo, ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
false);
false,
languageVersionSettings);
if (call.getCalleeExpression() == null) return checkArgumentTypesAndFail(context);
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.context;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.psi.Call;
import org.jetbrains.kotlin.psi.KtExpression;
import org.jetbrains.kotlin.resolve.BindingTrace;
@@ -44,11 +45,12 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
boolean isDebuggerContext,
boolean collectAllCandidates,
@NotNull CallPosition callPosition,
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider,
@NotNull LanguageVersionSettings languageVersionSettings
) {
super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
dataFlowInfoForArguments, statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates,
callPosition, expressionContextProvider);
callPosition, expressionContextProvider, languageVersionSettings);
}
@NotNull
@@ -60,12 +62,13 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
@NotNull DataFlowInfo dataFlowInfo,
@NotNull ContextDependency contextDependency,
@NotNull CheckArgumentTypesMode checkArguments,
boolean isAnnotationContext
boolean isAnnotationContext,
@NotNull LanguageVersionSettings languageVersionSettings
) {
return new BasicCallResolutionContext(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
new ResolutionResultsCacheImpl(), null,
StatementFilter.NONE, isAnnotationContext, false, false,
CallPosition.Unknown.INSTANCE, DEFAULT_EXPRESSION_CONTEXT_PROVIDER);
CallPosition.Unknown.INSTANCE, DEFAULT_EXPRESSION_CONTEXT_PROVIDER, languageVersionSettings);
}
@NotNull
@@ -77,7 +80,7 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
context.trace, context.scope, call, context.expectedType, context.dataFlowInfo, context.contextDependency, checkArguments,
context.resolutionResultsCache, dataFlowInfoForArguments,
context.statementFilter, context.isAnnotationContext, context.isDebuggerContext, context.collectAllCandidates,
context.callPosition, context.expressionContextProvider);
context.callPosition, context.expressionContextProvider, context.languageVersionSettings);
}
@NotNull
@@ -98,12 +101,13 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
@NotNull StatementFilter statementFilter,
boolean collectAllCandidates,
@NotNull CallPosition callPosition,
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider,
@NotNull LanguageVersionSettings languageVersionSettings
) {
return new BasicCallResolutionContext(
trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
dataFlowInfoForArguments, statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates,
callPosition, expressionContextProvider);
callPosition, expressionContextProvider, languageVersionSettings);
}
@NotNull
@@ -111,6 +115,6 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
return new BasicCallResolutionContext(
trace, scope, newCall, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
dataFlowInfoForArguments, statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates,
callPosition, expressionContextProvider);
callPosition, expressionContextProvider, languageVersionSettings);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.context;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
import org.jetbrains.kotlin.psi.Call;
import org.jetbrains.kotlin.psi.KtExpression;
@@ -57,11 +58,12 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
boolean isDebuggerContext,
boolean collectAllCandidates,
@NotNull CallPosition callPosition,
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider,
@NotNull LanguageVersionSettings languageVersionSettings
) {
super(trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments, resolutionResultsCache,
dataFlowInfoForArguments, statementFilter, isAnnotationContext, isDebuggerContext,
collectAllCandidates, callPosition, expressionContextProvider);
collectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings);
this.candidateCall = candidateCall;
this.tracing = tracing;
this.candidateResolveMode = candidateResolveMode;
@@ -78,7 +80,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
context.resolutionResultsCache, context.dataFlowInfoForArguments,
context.statementFilter,
candidateResolveMode, context.isAnnotationContext, context.isDebuggerContext, context.collectAllCandidates,
context.callPosition, context.expressionContextProvider);
context.callPosition, context.expressionContextProvider, context.languageVersionSettings);
}
@NotNull
@@ -90,7 +92,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
context.dataFlowInfo, context.contextDependency, context.checkArguments, context.resolutionResultsCache,
context.dataFlowInfoForArguments, context.statementFilter,
CandidateResolveMode.FULLY, context.isAnnotationContext, context.isDebuggerContext, context.collectAllCandidates,
context.callPosition, context.expressionContextProvider);
context.callPosition, context.expressionContextProvider, context.languageVersionSettings);
}
@Override
@@ -104,11 +106,13 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
@NotNull StatementFilter statementFilter,
boolean collectAllCandidates,
@NotNull CallPosition callPosition,
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider,
@NotNull LanguageVersionSettings languageVersionSettings
) {
return new CallCandidateResolutionContext<>(
candidateCall, tracing, trace, scope, call, expectedType, dataFlowInfo, contextDependency, checkArguments,
resolutionResultsCache, dataFlowInfoForArguments, statementFilter,
candidateResolveMode, isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition, expressionContextProvider);
candidateResolveMode, isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition, expressionContextProvider,
languageVersionSettings);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.context;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.psi.Call;
import org.jetbrains.kotlin.psi.KtExpression;
import org.jetbrains.kotlin.resolve.BindingTrace;
@@ -53,10 +54,11 @@ public abstract class CallResolutionContext<Context extends CallResolutionContex
boolean isDebuggerContext,
boolean collectAllCandidates,
@NotNull CallPosition callPosition,
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider,
@NotNull LanguageVersionSettings languageVersionSettings
) {
super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache,
statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition, expressionContextProvider);
statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings);
this.call = call;
this.checkArguments = checkArguments;
if (dataFlowInfoForArguments != null) {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiFile;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.psi.KtExpression;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.StatementFilter;
@@ -60,6 +61,9 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
@NotNull
public final CallPosition callPosition;
@NotNull
public final LanguageVersionSettings languageVersionSettings;
/**
* Used for analyzing expression in the given context.
* Should be used for going through parents to find containing function, loop etc.
@@ -84,7 +88,8 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
boolean isDebuggerContext,
boolean collectAllCandidates,
@NotNull CallPosition callPosition,
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider,
@NotNull LanguageVersionSettings languageVersionSettings
) {
this.trace = trace;
this.scope = scope;
@@ -98,6 +103,7 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
this.collectAllCandidates = collectAllCandidates;
this.callPosition = callPosition;
this.expressionContextProvider = expressionContextProvider;
this.languageVersionSettings = languageVersionSettings;
}
protected abstract Context create(
@@ -110,7 +116,8 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
@NotNull StatementFilter statementFilter,
boolean collectAllCandidates,
@NotNull CallPosition callPosition,
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider,
@NotNull LanguageVersionSettings languageVersionSettings
);
@NotNull
@@ -123,14 +130,14 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
public Context replaceBindingTrace(@NotNull BindingTrace trace) {
if (this.trace == trace) return self();
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, callPosition, expressionContextProvider);
collectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings);
}
@NotNull
public Context replaceDataFlowInfo(@NotNull DataFlowInfo newDataFlowInfo) {
if (newDataFlowInfo == dataFlowInfo) return self();
return create(trace, scope, newDataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, callPosition, expressionContextProvider);
collectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings);
}
@NotNull
@@ -138,28 +145,28 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
if (expectedType == newExpectedType) return self();
return create(trace, scope, dataFlowInfo, newExpectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, callPosition, expressionContextProvider);
collectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings);
}
@NotNull
public Context replaceScope(@NotNull LexicalScope newScope) {
if (newScope == scope) return self();
return create(trace, newScope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, callPosition, expressionContextProvider);
collectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings);
}
@NotNull
public Context replaceContextDependency(@NotNull ContextDependency newContextDependency) {
if (newContextDependency == contextDependency) return self();
return create(trace, scope, dataFlowInfo, expectedType, newContextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, callPosition, expressionContextProvider);
collectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings);
}
@NotNull
public Context replaceResolutionResultsCache(@NotNull ResolutionResultsCache newResolutionResultsCache) {
if (newResolutionResultsCache == resolutionResultsCache) return self();
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, newResolutionResultsCache, statementFilter,
collectAllCandidates, callPosition, expressionContextProvider);
collectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings);
}
@NotNull
@@ -170,25 +177,25 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
@NotNull
public Context replaceCollectAllCandidates(boolean newCollectAllCandidates) {
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
newCollectAllCandidates, callPosition, expressionContextProvider);
newCollectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings);
}
@NotNull
public Context replaceStatementFilter(@NotNull StatementFilter statementFilter) {
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, callPosition, expressionContextProvider);
collectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings);
}
@NotNull
public Context replaceCallPosition(@NotNull CallPosition callPosition) {
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, callPosition, expressionContextProvider);
collectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings);
}
@NotNull
public Context replaceExpressionContextProvider(@NotNull Function1<KtExpression, KtExpression> expressionContextProvider) {
return create(trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, callPosition, expressionContextProvider);
collectAllCandidates, callPosition, expressionContextProvider, languageVersionSettings);
}
@Nullable
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.types.expressions;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.psi.KtExpression;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.StatementFilter;
@@ -33,9 +34,10 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull BindingTrace trace,
@NotNull LexicalScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull KotlinType expectedType
@NotNull KotlinType expectedType,
@NotNull LanguageVersionSettings languageVersionSettings
) {
return newContext(trace, scope, dataFlowInfo, expectedType, ContextDependency.INDEPENDENT, StatementFilter.NONE);
return newContext(trace, scope, dataFlowInfo, expectedType, ContextDependency.INDEPENDENT, StatementFilter.NONE, languageVersionSettings);
}
@NotNull
@@ -45,10 +47,11 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull DataFlowInfo dataFlowInfo,
@NotNull KotlinType expectedType,
@NotNull ContextDependency contextDependency,
@NotNull StatementFilter statementFilter
@NotNull StatementFilter statementFilter,
@NotNull LanguageVersionSettings languageVersionSettings
) {
return newContext(trace, scope, dataFlowInfo, expectedType, contextDependency,
new ResolutionResultsCacheImpl(), statementFilter, false);
new ResolutionResultsCacheImpl(), statementFilter, false, languageVersionSettings);
}
@NotNull
@@ -58,7 +61,7 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
context.contextDependency, context.resolutionResultsCache,
context.statementFilter,
context.isAnnotationContext, context.isDebuggerContext, context.collectAllCandidates,
context.callPosition, context.expressionContextProvider);
context.callPosition, context.expressionContextProvider, context.languageVersionSettings);
}
@NotNull
@@ -68,7 +71,8 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
context.contextDependency, context.resolutionResultsCache,
context.statementFilter,
context.isAnnotationContext, isDebuggerContext, context.collectAllCandidates,
context.callPosition, context.expressionContextProvider);
context.callPosition, context.expressionContextProvider,
context.languageVersionSettings);
}
@NotNull
@@ -80,11 +84,13 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull ContextDependency contextDependency,
@NotNull ResolutionResultsCache resolutionResultsCache,
@NotNull StatementFilter statementFilter,
boolean isAnnotationContext
boolean isAnnotationContext,
@NotNull LanguageVersionSettings languageVersionSettings
) {
return new ExpressionTypingContext(
trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache,
statementFilter, isAnnotationContext, false, false, CallPosition.Unknown.INSTANCE, DEFAULT_EXPRESSION_CONTEXT_PROVIDER);
statementFilter, isAnnotationContext, false, false,
CallPosition.Unknown.INSTANCE, DEFAULT_EXPRESSION_CONTEXT_PROVIDER, languageVersionSettings);
}
private ExpressionTypingContext(
@@ -99,10 +105,12 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
boolean isDebuggerContext,
boolean collectAllCandidates,
@NotNull CallPosition callPosition,
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider,
@NotNull LanguageVersionSettings languageVersionSettings
) {
super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache,
statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition, expressionContextProvider);
statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition, expressionContextProvider,
languageVersionSettings);
}
@Override
@@ -116,11 +124,13 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull StatementFilter statementFilter,
boolean collectAllCandidates,
@NotNull CallPosition callPosition,
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider
@NotNull Function1<KtExpression, KtExpression> expressionContextProvider,
@NotNull LanguageVersionSettings languageVersionSettings
) {
return new ExpressionTypingContext(trace, scope, dataFlowInfo,
expectedType, contextDependency, resolutionResultsCache,
statementFilter, isAnnotationContext, isDebuggerContext,
collectAllCandidates, callPosition, expressionContextProvider);
collectAllCandidates, callPosition, expressionContextProvider,
languageVersionSettings);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -114,7 +114,7 @@ public class ExpressionTypingServices {
@NotNull ContextDependency contextDependency
) {
ExpressionTypingContext context = ExpressionTypingContext.newContext(
trace, scope, dataFlowInfo, expectedType, contextDependency, statementFilter
trace, scope, dataFlowInfo, expectedType, contextDependency, statementFilter, getLanguageVersionSettings()
);
if (contextExpression != expression) {
context = context.replaceExpressionContextProvider(arg -> arg == expression ? contextExpression : null);
@@ -156,7 +156,7 @@ public class ExpressionTypingServices {
}
checkFunctionReturnType(function, ExpressionTypingContext.newContext(
trace,
functionInnerScope, dataFlowInfo, expectedReturnType != null ? expectedReturnType : NO_EXPECTED_TYPE
functionInnerScope, dataFlowInfo, expectedReturnType != null ? expectedReturnType : NO_EXPECTED_TYPE, getLanguageVersionSettings()
));
}
@@ -224,7 +224,7 @@ public class ExpressionTypingServices {
expressionTypingComponents.overloadChecker);
ExpressionTypingContext context = ExpressionTypingContext.newContext(
trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE
trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE, getLanguageVersionSettings()
);
KotlinTypeInfo typeInfo = expressionTypingFacade.getTypeInfo(bodyExpression, context, function.hasBlockBody());
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.types.expressions
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.KtParameter
@@ -32,7 +33,8 @@ import org.jetbrains.kotlin.types.TypeUtils
class ValueParameterResolver(
private val expressionTypingServices: ExpressionTypingServices,
private val constantExpressionEvaluator: ConstantExpressionEvaluator
private val constantExpressionEvaluator: ConstantExpressionEvaluator,
private val languageVersionSettings: LanguageVersionSettings
) {
fun resolveValueParameters(
@@ -44,7 +46,8 @@ class ValueParameterResolver(
) {
val scopeForDefaultValue = LexicalScopeImpl(declaringScope, declaringScope.ownerDescriptor, false, null, LexicalScopeKind.DEFAULT_VALUE)
val contextForDefaultValue = ExpressionTypingContext.newContext(trace, scopeForDefaultValue, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE)
val contextForDefaultValue = ExpressionTypingContext.newContext(trace, scopeForDefaultValue, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE,
languageVersionSettings)
for ((descriptor, parameter) in valueParameterDescriptors.zip(valueParameters)) {
ForceResolveUtil.forceResolveAllContents(descriptor.annotations)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -22,6 +22,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.builtins.DefaultBuiltIns;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
import org.jetbrains.kotlin.config.CommonConfigurationKeysKt;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
@@ -60,12 +62,14 @@ public class ExpectedResolveDataUtil {
KotlinBuiltIns builtIns = DefaultBuiltIns.getInstance();
Map<String, DeclarationDescriptor> nameToDescriptor = new HashMap<>();
nameToDescriptor.put("kotlin::Int.plus(Int)", standardFunction(builtIns.getInt(), "plus", project, builtIns.getIntType()));
FunctionDescriptor descriptorForGet = standardFunction(builtIns.getArray(), "get", project, builtIns.getIntType());
nameToDescriptor.put("kotlin::Int.plus(Int)", standardFunction(builtIns.getInt(), "plus", project, environment, builtIns.getIntType()));
FunctionDescriptor descriptorForGet = standardFunction(builtIns.getArray(), "get", project, environment, builtIns.getIntType());
nameToDescriptor.put("kotlin::Array.get(Int)", descriptorForGet.getOriginal());
nameToDescriptor.put("kotlin::Int.compareTo(Double)", standardFunction(builtIns.getInt(), "compareTo", project, builtIns.getDoubleType()));
nameToDescriptor.put("kotlin::Int.compareTo(Double)",
standardFunction(builtIns.getInt(), "compareTo", project, environment, builtIns.getDoubleType()));
@NotNull
FunctionDescriptor descriptorForSet = standardFunction(builtIns.getArray(), "set", project, builtIns.getIntType(), builtIns.getIntType());
FunctionDescriptor descriptorForSet = standardFunction(builtIns.getArray(), "set", project, environment,
builtIns.getIntType(), builtIns.getIntType());
nameToDescriptor.put("kotlin::Array.set(Int, Int)", descriptorForSet.getOriginal());
return nameToDescriptor;
@@ -135,6 +139,7 @@ public class ExpectedResolveDataUtil {
ClassDescriptor classDescriptor,
String name,
Project project,
KotlinCoreEnvironment environment,
KotlinType... parameterTypes
) {
ModuleDescriptorImpl emptyModule = KotlinTestUtils.createEmptyModule();
@@ -146,9 +151,10 @@ public class ExpectedResolveDataUtil {
classDescriptor.getThisAsReceiverParameter(),
LexicalScopeKind.SYNTHETIC);
LanguageVersionSettings languageVersionSettings = CommonConfigurationKeysKt.getLanguageVersionSettings(environment.getConfiguration());
ExpressionTypingContext context = ExpressionTypingContext.newContext(
new BindingTraceContext(), lexicalScope,
DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE);
DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE, languageVersionSettings);
KtExpression callElement = KtPsiFactory(project).createExpression(name);
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.idea.resolve.frontendService
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DelegatingBindingTrace
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfoAfter
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfoBefore
import org.jetbrains.kotlin.resolve.calls.CallResolver
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
@@ -203,7 +202,7 @@ class ShadowedDeclarationsFilter(
val dataFlowInfo = bindingContext.getDataFlowInfoBefore(context)
val context = BasicCallResolutionContext.create(bindingTrace, scope, newCall, TypeUtils.NO_EXPECTED_TYPE, dataFlowInfo,
ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
false)
false, resolutionFacade.frontendService())
val callResolver = resolutionFacade.frontendService<CallResolver>()
val results = if (isFunction) callResolver.resolveFunctionCall(context) else callResolver.resolveSimpleProperty(context)
val resultingDescriptors = results.resultingCalls.map { it.resultingDescriptor }
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.lightClasses.IDELightClassConstr
import org.jetbrains.kotlin.idea.compiler.IDELanguageSettingsProvider
import org.jetbrains.kotlin.idea.project.IdeaEnvironment
import org.jetbrains.kotlin.idea.project.ResolveElementCache
import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.idea.stubindex.KotlinOverridableInternalMembersShortNameIndex
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
@@ -364,7 +365,7 @@ object IDELightClassContexts {
BasicCallResolutionContext.create(
trace, scope, CallMaker.makeCall(null, null, annotationEntry), TypeUtils.NO_EXPECTED_TYPE,
DataFlowInfoFactory.EMPTY, ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
true
true, annotationEntry.languageVersionSettings
),
annotationEntry.calleeExpression!!.constructorReferenceExpression!!,
annotationConstructor.returnType
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.core
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.idea.util.FuzzyType
import org.jetbrains.kotlin.idea.util.toFuzzyType
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
@@ -75,7 +76,8 @@ class IterableTypesDetection(
if (!canBeIterable(type)) return null
val expression = KtPsiFactory(project).createExpression("fake")
val context = ExpressionTypingContext.newContext(BindingTraceContext(), scope, DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE)
val context = ExpressionTypingContext.newContext(
BindingTraceContext(), scope, DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE, expression.languageVersionSettings)
val expressionReceiver = ExpressionReceiver.create(expression, type.type, context.trace.bindingContext)
val elementType = forLoopConventionsChecker.checkIterableConvention(expressionReceiver, context)
return elementType?.let { it.toFuzzyType(type.freeParameters) }
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.idea.analysis.computeTypeInContext
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.resolve.frontendService
@@ -121,7 +122,7 @@ fun Call.resolveCandidates(
val callResolutionContext = BasicCallResolutionContext.create(
bindingTrace, resolutionScope, this, expectedType, dataFlowInfo,
ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
false
false, callElement.languageVersionSettings
).replaceCollectAllCandidates(true)
val callResolver = resolutionFacade.frontendService<CallResolver>()
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.idea.core.NotPropertiesService
import org.jetbrains.kotlin.idea.core.copied
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.resolve.frontendService
import org.jetbrains.kotlin.idea.util.getResolutionScope
@@ -205,7 +206,7 @@ class UsePropertyAccessSyntaxIntention : SelfTargetingOffsetIndependentIntention
val bindingTrace = DelegatingBindingTrace(bindingContext, "Temporary trace")
val context = BasicCallResolutionContext.create(bindingTrace, resolutionScope, newCall, expectedType, dataFlowInfo,
ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
false)
false, resolvedCall.call.callElement.languageVersionSettings)
val callResolver = facade.frontendService<CallResolver>()
val result = callResolver.resolveSimpleProperty(context)
return result.isSuccess && result.resultingDescriptor.original == property