Propagate 'CompilerConfiguration' to frontend checkers
This commit is contained in:
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.CompilerEnvironment
|
||||
import org.jetbrains.kotlin.resolve.MultiTargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.TargetEnvironment
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.utils.DescriptionAware
|
||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||
import java.util.*
|
||||
|
||||
@@ -257,14 +258,18 @@ private class DelegatingPackageFragmentProvider(
|
||||
}
|
||||
}
|
||||
|
||||
interface LanguageVersionSettingsProvider {
|
||||
interface LanguageSettingsProvider {
|
||||
fun getLanguageVersionSettings(moduleInfo: ModuleInfo): LanguageVersionSettings
|
||||
|
||||
object Default : LanguageVersionSettingsProvider {
|
||||
fun getTargetPlatform(moduleInfo: ModuleInfo): DescriptionAware
|
||||
|
||||
object Default : LanguageSettingsProvider {
|
||||
override fun getLanguageVersionSettings(moduleInfo: ModuleInfo) = LanguageVersionSettingsImpl.DEFAULT
|
||||
|
||||
override fun getTargetPlatform(moduleInfo: ModuleInfo): DescriptionAware = DescriptionAware.NoVersion
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getInstance(project: Project) = ServiceManager.getService(project, LanguageVersionSettingsProvider::class.java) ?: Default
|
||||
fun getInstance(project: Project) = ServiceManager.getService(project, LanguageSettingsProvider::class.java) ?: Default
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.frontend.di
|
||||
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.container.StorageComponentContainer
|
||||
import org.jetbrains.kotlin.container.get
|
||||
@@ -142,6 +143,8 @@ fun createContainerForLazyResolve(
|
||||
useInstance(declarationProviderFactory)
|
||||
useInstance(LookupTracker.DO_NOTHING)
|
||||
useInstance(languageVersionSettings)
|
||||
//TODO: need to propagate full CompilerConfiguration to frontend
|
||||
useInstance(CompilerConfiguration.EMPTY)
|
||||
|
||||
useImpl<FileScopeProviderImpl>()
|
||||
useImpl<CompilerDeserializationConfiguration>()
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.calls
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -61,7 +62,8 @@ class CallCompleter(
|
||||
private val callCheckers: Iterable<CallChecker>,
|
||||
private val builtIns: KotlinBuiltIns,
|
||||
private val fakeCallResolver: FakeCallResolver,
|
||||
private val languageVersionSettings: LanguageVersionSettings
|
||||
private val languageVersionSettings: LanguageVersionSettings,
|
||||
private val compilerConfiguration: CompilerConfiguration
|
||||
) {
|
||||
fun <D : CallableDescriptor> completeCall(
|
||||
context: BasicCallResolutionContext,
|
||||
@@ -93,7 +95,7 @@ class CallCompleter(
|
||||
else resolvedCall.call.callElement
|
||||
|
||||
if (context.trace.wantsDiagnostics()) {
|
||||
val callCheckerContext = CallCheckerContext(context, languageVersionSettings)
|
||||
val callCheckerContext = CallCheckerContext(context, languageVersionSettings, compilerConfiguration)
|
||||
for (callChecker in callCheckers) {
|
||||
callChecker.check(resolvedCall, reportOn, callCheckerContext)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||
@@ -37,7 +38,8 @@ interface CallChecker {
|
||||
class CallCheckerContext(
|
||||
val resolutionContext: ResolutionContext<*>,
|
||||
val trace: BindingTrace,
|
||||
val languageVersionSettings: LanguageVersionSettings
|
||||
val languageVersionSettings: LanguageVersionSettings,
|
||||
val compilerConfiguration: CompilerConfiguration
|
||||
) {
|
||||
val scope: LexicalScope
|
||||
get() = resolutionContext.scope
|
||||
@@ -48,7 +50,7 @@ class CallCheckerContext(
|
||||
val isAnnotationContext: Boolean
|
||||
get() = resolutionContext.isAnnotationContext
|
||||
|
||||
constructor(c: ResolutionContext<*>, languageVersionSettings: LanguageVersionSettings) : this(c, c.trace, languageVersionSettings)
|
||||
constructor(c: ResolutionContext<*>, languageVersionSettings: LanguageVersionSettings, configuration: CompilerConfiguration) : this(c, c.trace, languageVersionSettings, configuration)
|
||||
}
|
||||
|
||||
// Use this utility to avoid premature computation of deferred return type of a resolved callable descriptor.
|
||||
|
||||
+6
-3
@@ -672,7 +672,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
trace.record(CALL, expression, call);
|
||||
|
||||
if (context.trace.wantsDiagnostics()) {
|
||||
CallCheckerContext callCheckerContext = new CallCheckerContext(context, components.languageVersionSettings);
|
||||
CallCheckerContext callCheckerContext =
|
||||
new CallCheckerContext(context, components.languageVersionSettings, components.compilerConfiguration);
|
||||
for (CallChecker checker : components.callCheckers) {
|
||||
checker.check(resolvedCall, expression, callCheckerContext);
|
||||
}
|
||||
@@ -977,7 +978,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (resolvedCall != null && trace.wantsDiagnostics()) {
|
||||
// Call must be validated with the actual, not temporary trace in order to report operator diagnostic
|
||||
// Only unary assignment expressions (++, --) and +=/... must be checked, normal assignments have the proper trace
|
||||
CallCheckerContext callCheckerContext = new CallCheckerContext(context, trace, components.languageVersionSettings);
|
||||
CallCheckerContext callCheckerContext =
|
||||
new CallCheckerContext(context, trace, components.languageVersionSettings, components.compilerConfiguration);
|
||||
for (CallChecker checker : components.callCheckers) {
|
||||
checker.check(resolvedCall, expression, callCheckerContext);
|
||||
}
|
||||
@@ -1044,7 +1046,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
resolvedCall.markCallAsCompleted();
|
||||
|
||||
if (context.trace.wantsDiagnostics()) {
|
||||
CallCheckerContext callCheckerContext = new CallCheckerContext(context, components.languageVersionSettings);
|
||||
CallCheckerContext callCheckerContext =
|
||||
new CallCheckerContext(context, components.languageVersionSettings, components.compilerConfiguration);
|
||||
for (CallChecker checker : components.callCheckers) {
|
||||
checker.check(resolvedCall, expression, callCheckerContext);
|
||||
}
|
||||
|
||||
+7
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.types.expressions;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings;
|
||||
import org.jetbrains.kotlin.context.GlobalContext;
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker;
|
||||
@@ -60,6 +61,7 @@ public class ExpressionTypingComponents {
|
||||
/*package*/ OverloadChecker overloadChecker;
|
||||
/*package*/ LanguageVersionSettings languageVersionSettings;
|
||||
/*package*/ Iterable<RttiExpressionChecker> rttiExpressionCheckers;
|
||||
/*package*/ CompilerConfiguration compilerConfiguration;
|
||||
|
||||
@Inject
|
||||
public void setGlobalContext(@NotNull GlobalContext globalContext) {
|
||||
@@ -200,4 +202,9 @@ public class ExpressionTypingComponents {
|
||||
public void setRttiExpressionCheckers(@NotNull Iterable<RttiExpressionChecker> rttiExpressionCheckers) {
|
||||
this.rttiExpressionCheckers = rttiExpressionCheckers;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setCompilerConfiguration(CompilerConfiguration compilerConfiguration) {
|
||||
this.compilerConfiguration = compilerConfiguration;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user