[NI] Disable capturing/approximation type in TypeSubstitutor with enabled NI
There is added a new service named `SubstitutingScopeProvider`, that provides factory that creates captured types and approximator for them. In OI they are the same as before commit, for NI they are empty, because that approximation interferes with NI algorithm That service is injected into function descriptors and property descriptors and used for creating `SubstitutingScope` with correct services Also there is changed time when we approximate captured types in NI (after all call checkers) #KT-25290 Fixed
This commit is contained in:
+20
@@ -8086,6 +8086,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedTypeInInputPosition.kt")
|
||||
public void testCapturedTypeInInputPosition() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/capturedTypeInInputPosition.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("commonSupertypeContravariant.kt")
|
||||
public void testCommonSupertypeContravariant() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt");
|
||||
@@ -8925,6 +8930,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("setterProjectedOutAssignFromJava.kt")
|
||||
public void testSetterProjectedOutAssignFromJava() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssignFromJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("setterProjectedOutNoPlusAssign.kt")
|
||||
public void testSetterProjectedOutNoPlusAssign() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.kt");
|
||||
@@ -17363,6 +17373,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/HiddenDeclarations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitAndExplicitThis.kt")
|
||||
public void testImplicitAndExplicitThis() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/implicitAndExplicitThis.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitReceiverProperty.kt")
|
||||
public void testImplicitReceiverProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.kt");
|
||||
@@ -18080,6 +18095,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt25290.kt")
|
||||
public void testKt25290() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/kt25290.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("OverloadPriority.kt")
|
||||
public void testOverloadPriority() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/OverloadPriority.kt");
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProviderImpl
|
||||
|
||||
private fun StorageComponentContainer.configureJavaTopDownAnalysis(
|
||||
moduleContentScope: GlobalSearchScope,
|
||||
@@ -126,6 +127,7 @@ fun createContainerForLazyResolveWithJava(
|
||||
|
||||
useImpl<ContractDeserializerImpl>()
|
||||
useImpl<FilesByFacadeFqNameIndexer>()
|
||||
useImpl<SubstitutingScopeProviderImpl>()
|
||||
}.apply {
|
||||
get<AbstractJavaClassFinder>().initialize(bindingTrace, get<KotlinCodeAnalyzer>())
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService
|
||||
import org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragmentProvider
|
||||
import org.jetbrains.kotlin.serialization.deserialization.MetadataPartProvider
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProviderImpl
|
||||
|
||||
class CommonAnalysisParameters(
|
||||
val metadataPartProviderFactory: (ModuleContent<*>) -> MetadataPartProvider
|
||||
@@ -166,6 +167,7 @@ object CommonAnalyzerFacade : ResolverForModuleFactory() {
|
||||
useInstance(declarationProviderFactory)
|
||||
useImpl<MetadataPackageFragmentProvider>()
|
||||
useImpl<ContractDeserializerImpl>()
|
||||
useImpl<SubstitutingScopeProviderImpl>()
|
||||
|
||||
val metadataFinderFactory = ServiceManager.getService(moduleContext.project, MetadataFinderFactory::class.java)
|
||||
?: error("No MetadataFinderFactory in project")
|
||||
|
||||
+1
-2
@@ -81,8 +81,7 @@ public class LocalVariableDescriptor extends VariableDescriptorWithInitializerIm
|
||||
@NotNull
|
||||
@Override
|
||||
public LocalVariableDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
if (substitutor.isEmpty()) return this;
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.wrapWithCapturingSubstitutio
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProvider
|
||||
import org.jetbrains.kotlin.types.TypeConstructorSubstitution
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny
|
||||
@@ -77,7 +78,9 @@ fun ResolutionContext<*>.reportTypeMismatchDueToTypeProjection(
|
||||
TypeConstructorSubstitution
|
||||
.create(receiverType)
|
||||
.wrapWithCapturingSubstitution(needApproximation = false)
|
||||
.buildSubstitutor().let { callableDescriptor.substitute(it) } ?: return false
|
||||
.buildSubstitutor().apply {
|
||||
setSubstitutingScopeProvider(SubstitutingScopeProvider.DEFAULT)
|
||||
}.let { callableDescriptor.substitute(it) } ?: return false
|
||||
|
||||
val nonApproximatedExpectedType = correspondingNotApproximatedTypeByDescriptor(substitutedDescriptor) ?: return false
|
||||
if (!TypeUtils.contains(nonApproximatedExpectedType) { it.isCaptured() }) return false
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker
|
||||
import org.jetbrains.kotlin.resolve.lazy.*
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProviderImpl
|
||||
import org.jetbrains.kotlin.types.expressions.DeclarationScopeProviderForLocalClassifierAnalyzer
|
||||
import org.jetbrains.kotlin.types.expressions.LocalClassDescriptorHolder
|
||||
import org.jetbrains.kotlin.types.expressions.LocalLazyDeclarationResolver
|
||||
@@ -103,6 +104,7 @@ fun createContainerForBodyResolve(
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
|
||||
useImpl<BodyResolver>()
|
||||
useImpl<SubstitutingScopeProviderImpl>()
|
||||
}
|
||||
|
||||
fun createContainerForLazyBodyResolve(
|
||||
@@ -123,6 +125,7 @@ fun createContainerForLazyBodyResolve(
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
useImpl<LazyTopDownAnalyzer>()
|
||||
useImpl<BasicAbsentDescriptorHandler>()
|
||||
useImpl<SubstitutingScopeProviderImpl>()
|
||||
}
|
||||
|
||||
fun createContainerForLazyLocalClassifierAnalyzer(
|
||||
@@ -154,6 +157,7 @@ fun createContainerForLazyLocalClassifierAnalyzer(
|
||||
useImpl<LocalLazyDeclarationResolver>()
|
||||
|
||||
useInstance(languageVersionSettings)
|
||||
useImpl<SubstitutingScopeProviderImpl>()
|
||||
useInstance(statementFilter)
|
||||
}
|
||||
|
||||
@@ -177,6 +181,7 @@ fun createContainerForLazyResolve(
|
||||
|
||||
useImpl<ResolveSession>()
|
||||
useImpl<LazyTopDownAnalyzer>()
|
||||
useImpl<SubstitutingScopeProviderImpl>()
|
||||
}
|
||||
|
||||
fun createLazyResolveSession(moduleContext: ModuleContext, files: Collection<KtFile>): ResolveSession =
|
||||
|
||||
@@ -911,7 +911,8 @@ public class DescriptorResolver {
|
||||
container instanceof ClassDescriptor && ((ClassDescriptor) container).isExpect(),
|
||||
modifierList != null && PsiUtilsKt.hasActualModifier(modifierList),
|
||||
modifierList != null && modifierList.hasModifier(KtTokens.EXTERNAL_KEYWORD),
|
||||
propertyInfo.getHasDelegate()
|
||||
propertyInfo.getHasDelegate(),
|
||||
new SubstitutingScopeProviderImpl(languageVersionSettings)
|
||||
);
|
||||
|
||||
List<TypeParameterDescriptorImpl> typeParameterDescriptors;
|
||||
|
||||
+68
-21
@@ -8,6 +8,8 @@ package org.jetbrains.kotlin.resolve.calls.tower
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertySetterDescriptorImpl
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -23,12 +25,13 @@ import org.jetbrains.kotlin.resolve.calls.components.AdditionalDiagnosticReporte
|
||||
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.context.CallPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.approximateCapturedTypes
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.buildResultingSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.substitute
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.substituteAndApproximateCapturedTypes
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.substituteAndApproximateIntegerLiteralTypes
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.makeNullableTypeIfSafeReceiver
|
||||
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus
|
||||
@@ -38,14 +41,13 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
|
||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.CastImplicitClassReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.NewCapturedType
|
||||
import org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer
|
||||
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
@@ -293,15 +295,14 @@ class KotlinToResolvedCallTransformer(
|
||||
// todo external argument
|
||||
|
||||
val argumentExpression = valueArgument.getArgumentExpression() ?: continue
|
||||
updateRecordedType(argumentExpression, parameter, newContext, resolvedCall.isReallySuccess())
|
||||
updateRecordedType(argumentExpression, parameter, newContext)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateRecordedType(
|
||||
expression: KtExpression,
|
||||
parameter: ValueParameterDescriptor?,
|
||||
context: BasicCallResolutionContext,
|
||||
reportErrorForTypeMismatch: Boolean
|
||||
context: BasicCallResolutionContext
|
||||
): KotlinType? {
|
||||
val deparenthesized = expression.let {
|
||||
KtPsiUtil.getLastElementDeparenthesized(it, context.statementFilter)
|
||||
@@ -318,9 +319,6 @@ class KotlinToResolvedCallTransformer(
|
||||
updatedType = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, deparenthesized) ?: updatedType
|
||||
}
|
||||
|
||||
|
||||
var reportErrorDuringTypeCheck = reportErrorForTypeMismatch
|
||||
|
||||
if (parameter != null && ImplicitIntegerCoercion.isEnabledForParameter(parameter)) {
|
||||
val argumentCompileTimeValue = context.trace[BindingContext.COMPILE_TIME_VALUE, deparenthesized]
|
||||
if (argumentCompileTimeValue != null && argumentCompileTimeValue.parameters.isConvertableConstVal) {
|
||||
@@ -329,7 +327,6 @@ class KotlinToResolvedCallTransformer(
|
||||
updatedType = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable(
|
||||
context.trace, context.statementFilter, context.expectedType, generalNumberType, expression
|
||||
)
|
||||
reportErrorDuringTypeCheck = true
|
||||
}
|
||||
|
||||
}
|
||||
@@ -337,7 +334,7 @@ class KotlinToResolvedCallTransformer(
|
||||
|
||||
updatedType = updateRecordedTypeForArgument(updatedType, recordedType, expression, context)
|
||||
|
||||
dataFlowAnalyzer.checkType(updatedType, deparenthesized, context, reportErrorDuringTypeCheck)
|
||||
dataFlowAnalyzer.checkType(updatedType, deparenthesized, context, false)
|
||||
|
||||
return updatedType
|
||||
}
|
||||
@@ -690,32 +687,44 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
resultingDescriptor = run {
|
||||
val candidateDescriptor = resolvedCallAtom.candidateDescriptor
|
||||
val containsCapturedTypes = resolvedCallAtom.candidateDescriptor.returnType?.contains { it is NewCapturedType } ?: false
|
||||
val containsIntegerLiteralTypes = resolvedCallAtom.candidateDescriptor.returnType?.contains { it.constructor is IntegerLiteralTypeConstructor } ?: false
|
||||
val containsIntegerLiteralTypes = resolvedCallAtom.candidateDescriptor.returnType?.contains {
|
||||
it.constructor is IntegerLiteralTypeConstructor
|
||||
} ?: false
|
||||
|
||||
when {
|
||||
candidateDescriptor is FunctionDescriptor ||
|
||||
(candidateDescriptor is PropertyDescriptor && (candidateDescriptor.typeParameters.isNotEmpty() || containsCapturedTypes || containsIntegerLiteralTypes)) ->
|
||||
(candidateDescriptor is PropertyDescriptor && candidateDescriptor.typeParameters.isNotEmpty() || containsIntegerLiteralTypes) ->
|
||||
// this code is very suspicious. Now it is very useful for BE, because they cannot do nothing with captured types,
|
||||
// but it seems like temporary solution.
|
||||
candidateDescriptor.substitute(resolvedCallAtom.substitutor).substituteAndApproximateCapturedTypes(
|
||||
substitutor ?: FreshVariableNewTypeSubstitutor.Empty
|
||||
)
|
||||
candidateDescriptor.substituteAndApproximateIntegerLiteralTypes(resolvedCallAtom.substitutor).let {
|
||||
if (substitutor != null) {
|
||||
it.substitute(substitutor)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
|
||||
else ->
|
||||
candidateDescriptor
|
||||
}
|
||||
} as D
|
||||
|
||||
typeArguments = resolvedCallAtom.substitutor.freshVariables.map {
|
||||
val substituted = (substitutor ?: FreshVariableNewTypeSubstitutor.Empty).safeSubstitute(it.defaultType)
|
||||
TypeApproximator(substituted.constructor.builtIns)
|
||||
.approximateToSuperType(substituted, TypeApproximatorConfiguration.IntegerLiteralsTypesApproximation)
|
||||
?: substituted
|
||||
(substitutor ?: FreshVariableNewTypeSubstitutor.Empty).safeSubstitute(it.defaultType)
|
||||
}
|
||||
|
||||
calculateExpectedTypeForSamConvertedArgumentMap(substitutor)
|
||||
}
|
||||
|
||||
fun approximateCapturedTypesAndHackSetters() {
|
||||
val approximator = TypeApproximator(resultingDescriptor.builtIns)
|
||||
resultingDescriptor = resultingDescriptor.hackSettersAccordingToCapturedOutTypes()
|
||||
resultingDescriptor = resultingDescriptor.approximateCapturedTypes()
|
||||
typeArguments = typeArguments.map {
|
||||
approximator.approximateToSuperType(it, TypeApproximatorConfiguration.CapturedAndIntegerLiteralsTypesApproximation) ?: it
|
||||
}
|
||||
}
|
||||
|
||||
fun getExpectedTypeForSamConvertedArgument(valueArgument: ValueArgument): UnwrappedType? =
|
||||
expedtedTypeForSamConvertedArgumentMap?.get(valueArgument)
|
||||
|
||||
@@ -808,3 +817,41 @@ fun NewResolvedCallImpl<*>.hasInferredReturnType(): Boolean {
|
||||
val returnType = this.resultingDescriptor.returnType ?: return false
|
||||
return !returnType.contains { ErrorUtils.isUninferredParameter(it) }
|
||||
}
|
||||
|
||||
fun ResolvedCall<*>.approximateCapturedTypesAndHackSetters() {
|
||||
when (this) {
|
||||
is NewResolvedCallImpl<*> -> approximateCapturedTypesAndHackSetters()
|
||||
is NewVariableAsFunctionResolvedCallImpl -> {
|
||||
functionCall.approximateCapturedTypesAndHackSetters()
|
||||
variableCall.approximateCapturedTypesAndHackSetters()
|
||||
}
|
||||
else -> throw UnsupportedOperationException("Illegal resolved call: $this")
|
||||
}
|
||||
}
|
||||
|
||||
fun <D : CallableDescriptor> D.hackSettersAccordingToCapturedOutTypes(): D {
|
||||
return when (this) {
|
||||
is PropertyDescriptorImpl -> hackSettersAccordingToCapturedOutTypes() as D
|
||||
else -> this
|
||||
}
|
||||
}
|
||||
|
||||
private fun PropertyDescriptorImpl.hackSettersAccordingToCapturedOutTypes(): PropertyDescriptor {
|
||||
val setter = setter ?: return this
|
||||
val valueParameter = setter.valueParameters.first()
|
||||
val inputType = valueParameter.type
|
||||
val approximatedType = TypeApproximator(builtIns).approximateToSubType(
|
||||
inputType.unwrap(),
|
||||
TypeApproximatorConfiguration.CapturedAndIntegerLiteralsTypesApproximation
|
||||
) ?: return this
|
||||
|
||||
val newProperty = newCopyBuilder().build() as PropertyDescriptorImpl
|
||||
|
||||
val newSetter = with(setter) {
|
||||
PropertySetterDescriptorImpl(newProperty, annotations, modality, visibility, isDefault, isExternal, isInline, kind, original, source)
|
||||
}
|
||||
newSetter.initialize(PropertySetterDescriptorImpl.createSetterParameter(newSetter, approximatedType, setter.annotations))
|
||||
newProperty.initialize(getter, newSetter, backingField, delegateField)
|
||||
newProperty.isSetterProjectedOut = true
|
||||
return newProperty
|
||||
}
|
||||
@@ -382,6 +382,7 @@ class PSICallResolver(
|
||||
|
||||
return cache.getOrPut(implicitReceiver) {
|
||||
context.transformToReceiverWithSmartCastInfo(implicitReceiver.value)
|
||||
.prepareReceiverRegardingCaptureTypes()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -110,6 +110,7 @@ class ResolvedAtomCompleter(
|
||||
|
||||
kotlinToResolvedCallTransformer.reportDiagnostics(topLevelCallContext, topLevelTrace, resolvedCall, diagnostics)
|
||||
|
||||
resolvedCall.approximateCapturedTypesAndHackSetters()
|
||||
return resolvedCall
|
||||
}
|
||||
|
||||
@@ -155,9 +156,7 @@ class ResolvedAtomCompleter(
|
||||
.replaceBindingTrace(topLevelTrace)
|
||||
|
||||
val argumentExpression = resultValueArgument.valueArgument.getArgumentExpression() ?: continue
|
||||
kotlinToResolvedCallTransformer.updateRecordedType(
|
||||
argumentExpression, parameter = null, context = newContext, reportErrorForTypeMismatch = true
|
||||
)
|
||||
kotlinToResolvedCallTransformer.updateRecordedType(argumentExpression, parameter = null, context = newContext)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,12 @@ import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProvider
|
||||
import org.jetbrains.kotlin.types.WrappedTypeFactory
|
||||
|
||||
interface LazyClassContext {
|
||||
val declarationScopeProvider: DeclarationScopeProvider
|
||||
val substitutingScopeProvider: SubstitutingScopeProvider
|
||||
|
||||
val storageManager: StorageManager
|
||||
val trace: BindingTrace
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
import org.jetbrains.kotlin.storage.*;
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProvider;
|
||||
import org.jetbrains.kotlin.types.WrappedTypeFactory;
|
||||
import org.jetbrains.kotlin.utils.SmartList;
|
||||
|
||||
@@ -81,6 +82,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
private DelegationFilter delegationFilter;
|
||||
private WrappedTypeFactory wrappedTypeFactory;
|
||||
private PlatformDiagnosticSuppressor platformDiagnosticSuppressor;
|
||||
private SubstitutingScopeProvider substitutingScopeProvider;
|
||||
|
||||
private final SyntheticResolveExtension syntheticResolveExtension;
|
||||
|
||||
@@ -146,6 +148,17 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
this.platformDiagnosticSuppressor = platformDiagnosticSuppressor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SubstitutingScopeProvider getSubstitutingScopeProvider() {
|
||||
return substitutingScopeProvider;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setSubstitutingScopeProvider(SubstitutingScopeProvider substitutingScopeProvider) {
|
||||
this.substitutingScopeProvider = substitutingScopeProvider;
|
||||
}
|
||||
|
||||
// Only calls from injectors expected
|
||||
@Deprecated
|
||||
public ResolveSession(
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
) {
|
||||
super(c.getStorageManager(), containingDeclaration, name,
|
||||
KotlinSourceElementKt.toSourceElement(classLikeInfo.getCorrespondingClassOrObject()),
|
||||
isExternal
|
||||
isExternal, c.getSubstitutingScopeProvider()
|
||||
);
|
||||
this.c = c;
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.OldCapturedTypeCreator
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.SubstitutingScope
|
||||
import org.jetbrains.kotlin.types.typesApproximation.OldCaptureTypeApproximator
|
||||
|
||||
class SubstitutingScopeProviderImpl(private val languageVersionSettings: LanguageVersionSettings) : SubstitutingScopeProvider {
|
||||
override val isNewInferenceEnabled: Boolean get() = languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
|
||||
|
||||
override fun createSubstitutingScope(workerScope: MemberScope, givenSubstitutor: TypeSubstitutor): SubstitutingScope {
|
||||
return SubstitutingScope(workerScope, givenSubstitutor, this)
|
||||
}
|
||||
|
||||
override fun provideApproximator(): CapturedTypeApproximator {
|
||||
return if (isNewInferenceEnabled) {
|
||||
NoCapturedTypeApproximator
|
||||
} else {
|
||||
OldCaptureTypeApproximator()
|
||||
}
|
||||
}
|
||||
|
||||
override fun provideCapturedTypeCreator(): CapturedTypeCreator {
|
||||
return if (isNewInferenceEnabled) {
|
||||
NoCapturedTypeCreator
|
||||
} else {
|
||||
OldCapturedTypeCreator
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object NoCapturedTypeCreator : CapturedTypeCreator {
|
||||
override fun createCapturedType(typeProjection: TypeProjection): TypeProjection {
|
||||
return typeProjection
|
||||
}
|
||||
}
|
||||
|
||||
object NoCapturedTypeApproximator : CapturedTypeApproximator {
|
||||
override fun approximateCapturedTypes(typeProjection: TypeProjection?, approximateContravariant: Boolean): TypeProjection? {
|
||||
return typeProjection
|
||||
}
|
||||
}
|
||||
+8
-2
@@ -958,6 +958,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
|
||||
boolean result = true;
|
||||
KtExpression reportOn = expression != null ? expression : expressionWithParenthesis;
|
||||
KtExpression originalReportOn = reportOn;
|
||||
if (reportOn instanceof KtQualifiedExpression) {
|
||||
KtExpression selector = ((KtQualifiedExpression) reportOn).getSelectorExpression();
|
||||
if (selector != null)
|
||||
@@ -968,14 +969,19 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) variable;
|
||||
PropertySetterDescriptor setter = propertyDescriptor.getSetter();
|
||||
if (propertyDescriptor.isSetterProjectedOut()) {
|
||||
trace.report(SETTER_PROJECTED_OUT.on(reportOn, propertyDescriptor));
|
||||
trace.report(SETTER_PROJECTED_OUT.on(originalReportOn, propertyDescriptor));
|
||||
result = false;
|
||||
}
|
||||
else if (setter != null) {
|
||||
ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(expressionWithParenthesis, context.trace.getBindingContext());
|
||||
assert resolvedCall != null
|
||||
: "Call is not resolved for property setter: " + PsiUtilsKt.getElementTextWithContext(expressionWithParenthesis);
|
||||
checkPropertySetterCall(context.replaceBindingTrace(trace), setter, resolvedCall, reportOn);
|
||||
if (((PropertyDescriptor)resolvedCall.getResultingDescriptor()).isSetterProjectedOut()) {
|
||||
trace.report(SETTER_PROJECTED_OUT.on(originalReportOn, propertyDescriptor));
|
||||
result = false;
|
||||
} else {
|
||||
checkPropertySetterCall(context.replaceBindingTrace(trace), setter, resolvedCall, reportOn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-3
@@ -50,6 +50,7 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProvider
|
||||
import org.jetbrains.kotlin.types.WrappedTypeFactory
|
||||
|
||||
class LocalClassifierAnalyzer(
|
||||
@@ -65,7 +66,8 @@ class LocalClassifierAnalyzer(
|
||||
private val targetPlatformVersion: TargetPlatformVersion,
|
||||
private val languageVersionSettings: LanguageVersionSettings,
|
||||
private val delegationFilter: DelegationFilter,
|
||||
private val wrappedTypeFactory: WrappedTypeFactory
|
||||
private val wrappedTypeFactory: WrappedTypeFactory,
|
||||
private val substitutingScopeProvider: SubstitutingScopeProvider
|
||||
) {
|
||||
fun processClassOrObject(
|
||||
scope: LexicalWritableScope?,
|
||||
@@ -99,7 +101,8 @@ class LocalClassifierAnalyzer(
|
||||
languageVersionSettings,
|
||||
SyntheticResolveExtension.getInstance(project),
|
||||
delegationFilter,
|
||||
wrappedTypeFactory
|
||||
wrappedTypeFactory,
|
||||
substitutingScopeProvider
|
||||
)
|
||||
)
|
||||
|
||||
@@ -126,7 +129,8 @@ class LocalClassDescriptorHolder(
|
||||
val languageVersionSettings: LanguageVersionSettings,
|
||||
val syntheticResolveExtension: SyntheticResolveExtension,
|
||||
val delegationFilter: DelegationFilter,
|
||||
val wrappedTypeFactory: WrappedTypeFactory
|
||||
val wrappedTypeFactory: WrappedTypeFactory,
|
||||
val substitutingScopeProvider: SubstitutingScopeProvider
|
||||
) {
|
||||
// We do not need to synchronize here, because this code is used strictly from one thread
|
||||
private var classDescriptor: ClassDescriptor? = null
|
||||
@@ -166,6 +170,7 @@ class LocalClassDescriptorHolder(
|
||||
override val syntheticResolveExtension = this@LocalClassDescriptorHolder.syntheticResolveExtension
|
||||
override val delegationFilter: DelegationFilter = this@LocalClassDescriptorHolder.delegationFilter
|
||||
override val wrappedTypeFactory: WrappedTypeFactory = this@LocalClassDescriptorHolder.wrappedTypeFactory
|
||||
override val substitutingScopeProvider: SubstitutingScopeProvider = this@LocalClassDescriptorHolder.substitutingScopeProvider
|
||||
},
|
||||
containingDeclaration,
|
||||
classOrObject.nameAsSafeName,
|
||||
|
||||
+28
-7
@@ -60,6 +60,20 @@ val CallableDescriptor.returnTypeOrNothing: UnwrappedType
|
||||
|
||||
fun TypeSubstitutor.substitute(type: UnwrappedType): UnwrappedType = safeSubstitute(type, Variance.INVARIANT).unwrap()
|
||||
|
||||
fun CallableDescriptor.substituteAndApproximateIntegerLiteralTypes(substitutor: NewTypeSubstitutor): CallableDescriptor {
|
||||
val wrappedSubstitution = object : TypeSubstitution() {
|
||||
override fun get(key: KotlinType): TypeProjection? = null
|
||||
|
||||
override fun prepareTopLevelType(topLevelType: KotlinType, position: Variance) =
|
||||
substitutor.safeSubstitute(topLevelType.unwrap()).let { substitutedType ->
|
||||
TypeApproximator(builtIns).approximateToSuperType(substitutedType, TypeApproximatorConfiguration.IntegerLiteralsTypesApproximation)
|
||||
?: substitutedType
|
||||
}
|
||||
}
|
||||
|
||||
return substitute(TypeSubstitutor.create(wrappedSubstitution))
|
||||
}
|
||||
|
||||
fun CallableDescriptor.substitute(substitutor: NewTypeSubstitutor): CallableDescriptor {
|
||||
val wrappedSubstitution = object : TypeSubstitution() {
|
||||
override fun get(key: KotlinType): TypeProjection? = null
|
||||
@@ -68,18 +82,25 @@ fun CallableDescriptor.substitute(substitutor: NewTypeSubstitutor): CallableDesc
|
||||
return substitute(TypeSubstitutor.create(wrappedSubstitution))
|
||||
}
|
||||
|
||||
fun CallableDescriptor.substituteAndApproximateCapturedTypes(substitutor: NewTypeSubstitutor): CallableDescriptor {
|
||||
fun <D: CallableDescriptor> D.approximateCapturedTypes(): D {
|
||||
val approximator = TypeApproximator(builtIns)
|
||||
var anyChanges = false
|
||||
val wrappedSubstitution = object : TypeSubstitution() {
|
||||
override fun get(key: KotlinType): TypeProjection? = null
|
||||
|
||||
override fun prepareTopLevelType(topLevelType: KotlinType, position: Variance) =
|
||||
substitutor.safeSubstitute(topLevelType.unwrap()).let { substitutedType ->
|
||||
TypeApproximator(builtIns).approximateToSuperType(substitutedType, TypeApproximatorConfiguration.CapturedAndIntegerLiteralsTypesApproximation)
|
||||
?: substitutedType
|
||||
override fun prepareTopLevelType(topLevelType: KotlinType, position: Variance): KotlinType {
|
||||
val type = topLevelType.unwrap()
|
||||
val approximatedType =
|
||||
approximator.approximateToSuperType(type, TypeApproximatorConfiguration.CapturedAndIntegerLiteralsTypesApproximation)
|
||||
if (approximatedType != null) {
|
||||
anyChanges = true
|
||||
}
|
||||
return approximatedType as? KotlinType ?: type
|
||||
}
|
||||
}
|
||||
|
||||
return substitute(TypeSubstitutor.create(wrappedSubstitution))
|
||||
val substitutedDescriptor = substitute(TypeSubstitutor.create(wrappedSubstitution)) as D
|
||||
return if (anyChanges) substitutedDescriptor else this
|
||||
}
|
||||
|
||||
internal fun <E> MutableList<E>.trimToSize(newSize: Int) = subList(newSize, size).clear()
|
||||
internal fun <E> MutableList<E>.trimToSize(newSize: Int) = subList(newSize, size).clear()
|
||||
@@ -21,14 +21,10 @@ import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
|
||||
import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextForCS
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
|
||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration.IntersectionStrategy.*
|
||||
import org.jetbrains.kotlin.types.checker.NewCapturedType
|
||||
import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.types.model.CaptureStatus.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
|
||||
open class TypeApproximatorConfiguration {
|
||||
@@ -424,6 +420,8 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon
|
||||
if (argument.isStarProjection()) continue
|
||||
|
||||
val argumentType = argument.getType()//.unwrap()
|
||||
val argumentTypeIsNullable = argumentType.asSimpleType()?.isMarkedNullable() ?: false
|
||||
|
||||
val effectiveVariance = AbstractTypeChecker.effectiveVariance(parameter.getVariance(), argument.getVariance())
|
||||
when (effectiveVariance) {
|
||||
null -> {
|
||||
@@ -487,7 +485,7 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon
|
||||
*/
|
||||
if (argumentType.typeConstructor() is NewCapturedTypeConstructor) {
|
||||
val subType = approximateToSubType(argumentType, conf, depth) ?: continue@loop
|
||||
if (!subType.isTrivialSub()) {
|
||||
if (!subType.isTrivialSub(argumentTypeIsNullable)) {
|
||||
newArguments[index] = createTypeArgument(subType, TypeVariance.IN)
|
||||
continue@loop
|
||||
}
|
||||
@@ -498,7 +496,7 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon
|
||||
if (approximatedSuperType.isTrivialSuper()) {
|
||||
val approximatedSubType =
|
||||
approximateToSubType(argumentType, conf, depth) ?: continue@loop // seems like this is never null
|
||||
if (!approximatedSubType.isTrivialSub()) {
|
||||
if (!approximatedSubType.isTrivialSub(argumentTypeIsNullable)) {
|
||||
newArguments[index] = createTypeArgument(approximatedSubType, TypeVariance.IN)
|
||||
continue@loop
|
||||
}
|
||||
@@ -527,7 +525,12 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon
|
||||
private fun KotlinTypeMarker.isTrivialSuper() = upperBoundIfFlexible().isNullableAny()
|
||||
|
||||
// Nothing or Nothing!
|
||||
private fun KotlinTypeMarker.isTrivialSub() = lowerBoundIfFlexible().isNothing()
|
||||
private fun KotlinTypeMarker.isTrivialSub(originalIsNullable: Boolean) = lowerBoundIfFlexible().let {
|
||||
if (originalIsNullable)
|
||||
it.isNothing() || it.isNullableNothing()
|
||||
else
|
||||
it.isNothing()
|
||||
}
|
||||
}
|
||||
//
|
||||
//internal fun KotlinTypeMarker.typeDepth() =
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// FILE: test/GenericSam.java
|
||||
// !WITH_NEW_INFERENCE
|
||||
// NI_EXPECTED_FILE
|
||||
|
||||
package test;
|
||||
|
||||
@@ -16,7 +18,7 @@ fun f3() = java.lang.Runnable::class
|
||||
fun f4() = java.lang.Runnable::run
|
||||
|
||||
fun f5() = GenericSam::class
|
||||
fun f6() = GenericSam<*>::invoke
|
||||
fun f6() = GenericSam<*>::<!NI;DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>invoke<!>
|
||||
fun f7() = test.GenericSam::class
|
||||
fun f8() = test.GenericSam<String>::invoke
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package
|
||||
|
||||
public fun f1(): kotlin.reflect.KClass<java.lang.Runnable>
|
||||
public fun f2(): kotlin.reflect.KFunction1<java.lang.Runnable, kotlin.Unit>
|
||||
public fun f3(): kotlin.reflect.KClass<java.lang.Runnable>
|
||||
public fun f4(): kotlin.reflect.KFunction1<java.lang.Runnable, kotlin.Unit>
|
||||
public fun f5(): kotlin.reflect.KClass<test.GenericSam<*>>
|
||||
public fun f6(): kotlin.reflect.KFunction0<[ERROR : <ERROR FUNCTION RETURN TYPE>]>
|
||||
public fun f7(): kotlin.reflect.KClass<test.GenericSam<*>>
|
||||
public fun f8(): kotlin.reflect.KFunction2<test.GenericSam<kotlin.String>, @kotlin.ParameterName(name = "t") kotlin.String!, kotlin.Unit>
|
||||
public fun g1(): kotlin.reflect.KClass<out java.lang.Runnable>
|
||||
public fun g2(): kotlin.reflect.KFunction0<kotlin.Unit>
|
||||
public fun g3(): kotlin.reflect.KClass<out java.lang.Runnable>
|
||||
public fun g4(): kotlin.reflect.KFunction0<kotlin.Unit>
|
||||
public fun g5(): kotlin.reflect.KClass<out test.GenericSam<kotlin.String>>
|
||||
public fun g6(): kotlin.reflect.KFunction1<@kotlin.ParameterName(name = "t") kotlin.String!, kotlin.Unit>
|
||||
public fun g7(): kotlin.reflect.KClass<out test.GenericSam<kotlin.String>>
|
||||
public fun g8(): kotlin.reflect.KFunction1<@kotlin.ParameterName(name = "t") kotlin.String!, kotlin.Unit>
|
||||
|
||||
package test {
|
||||
|
||||
public interface GenericSam</*0*/ T : kotlin.Any!> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public abstract operator fun invoke(/*0*/ t: T!): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -37,5 +37,5 @@ annotation class AnnArray(val a: Array<String>)
|
||||
@AnnArray(<!OI;NON_VARARG_SPREAD!>*<!>["/"])
|
||||
fun testArray() {}
|
||||
|
||||
@Ann1(<!NI;TYPE_MISMATCH, OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, TYPE_MISMATCH!>[""]<!>)
|
||||
@Ann1(<!OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, TYPE_MISMATCH!>[""]<!>)
|
||||
fun testVararg() {}
|
||||
+1
-1
@@ -34,6 +34,6 @@ val bbb = null ?: ( l() <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>)
|
||||
val bbbb = ( l() <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>) ?: ( l() <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>)
|
||||
|
||||
fun f(x : Long?): Long {
|
||||
var a = x ?: (<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>fun() {}<!> <!USELESS_ELVIS!>?: <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>fun() {}<!><!>)
|
||||
var a = x ?: (<!TYPE_MISMATCH!>fun() {}<!> <!USELESS_ELVIS!>?: <!TYPE_MISMATCH!>fun() {}<!><!>)
|
||||
return <!OI;DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>a<!>
|
||||
}
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@ fun testImplicitCoercion() {
|
||||
val <!UNUSED_VARIABLE!>h<!> = if (false) <!IMPLICIT_CAST_TO_ANY!>4<!> else <!IMPLICIT_CAST_TO_ANY!>{}<!>
|
||||
|
||||
bar(<!NI;TYPE_MISMATCH!>if (true) {
|
||||
<!CONSTANT_EXPECTED_TYPE_MISMATCH, NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>4<!>
|
||||
<!OI;CONSTANT_EXPECTED_TYPE_MISMATCH!>4<!>
|
||||
}
|
||||
else {
|
||||
<!UNUSED_VALUE!>z =<!> 342
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ fun test1() {
|
||||
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!UNUSED_ANONYMOUS_PARAMETER!>x<!>, <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_ANONYMOUS_PARAMETER!>y<!><!> -> ""
|
||||
}<!>
|
||||
foo1 <!NI;TYPE_MISMATCH!>{
|
||||
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!>-> <!CONSTANT_EXPECTED_TYPE_MISMATCH, NI;CONSTANT_EXPECTED_TYPE_MISMATCH, NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
|
||||
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!>-> <!CONSTANT_EXPECTED_TYPE_MISMATCH, NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
|
||||
}<!>
|
||||
|
||||
|
||||
@@ -40,6 +40,6 @@ fun test1() {
|
||||
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH, UNUSED_ANONYMOUS_PARAMETER!>x<!> -> ""
|
||||
}<!>
|
||||
foo2 <!NI;TYPE_MISMATCH!>{
|
||||
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!>-> <!CONSTANT_EXPECTED_TYPE_MISMATCH, NI;CONSTANT_EXPECTED_TYPE_MISMATCH, NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
|
||||
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!>-> <!CONSTANT_EXPECTED_TYPE_MISMATCH, NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>
|
||||
}<!>
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,10 +1,10 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
fun test(a: Int) {
|
||||
run<Int>f@{
|
||||
if (a > 0) return@f <!NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!>
|
||||
if (a > 0) return@f <!TYPE_MISMATCH!>""<!>
|
||||
return@f 1
|
||||
}
|
||||
|
||||
run<Int>{ <!NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!> }
|
||||
run<Int>{ <!TYPE_MISMATCH!>""<!> }
|
||||
run<Int>{ 1 }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
||||
|
||||
interface Inv<T1>
|
||||
class InvImpl<T2> : Inv<T2>
|
||||
open class OpenInv<T>
|
||||
|
||||
class A<T> {
|
||||
fun <F : OpenInv<T>> foo(x: F) = 1
|
||||
|
||||
}
|
||||
class B<T> {
|
||||
fun <F : Inv<T>> foo(x: F) = 1
|
||||
|
||||
}
|
||||
|
||||
fun test(a: A<out CharSequence>, b: B<out CharSequence>) {
|
||||
a.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>foo<!>(<!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>OpenInv<!>())
|
||||
b.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>foo<!>(<!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>InvImpl<!>())
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package
|
||||
|
||||
public fun test(/*0*/ a: A<out kotlin.CharSequence>, /*1*/ b: B<out kotlin.CharSequence>): kotlin.Unit
|
||||
|
||||
public final class A</*0*/ T> {
|
||||
public constructor A</*0*/ T>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun </*0*/ F : OpenInv<T>> foo(/*0*/ x: F): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class B</*0*/ T> {
|
||||
public constructor B</*0*/ T>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun </*0*/ F : Inv<T>> foo(/*0*/ x: F): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface Inv</*0*/ T1> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class InvImpl</*0*/ T2> : Inv<T2> {
|
||||
public constructor InvImpl</*0*/ T2>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class OpenInv</*0*/ T> {
|
||||
public constructor OpenInv</*0*/ T>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+1
-1
@@ -20,7 +20,7 @@ class Outer<E> {
|
||||
}
|
||||
|
||||
if (y is Outer<*>.Inner<*>) {
|
||||
<!DEBUG_INFO_SMARTCAST!>y<!>.prop.checkType { _<Any?>() }
|
||||
<!OI;DEBUG_INFO_SMARTCAST!>y<!>.prop.checkType { _<Any?>() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ fun foo(x: Any?, y: C<*>) {
|
||||
y.<!OI;MEMBER_PROJECTED_OUT!>bindTo<!>(<!NI;TYPE_MISMATCH!>""<!>)
|
||||
|
||||
if (x is C<*>) {
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.<!OI;MEMBER_PROJECTED_OUT!>bindTo<!>(<!NI;TYPE_MISMATCH!>""<!>)
|
||||
<!OI;DEBUG_INFO_SMARTCAST!>x<!>.<!OI;MEMBER_PROJECTED_OUT!>bindTo<!>(<!NI;TYPE_MISMATCH!>""<!>)
|
||||
with(<!DEBUG_INFO_SMARTCAST!>x<!>) {
|
||||
<!OI;MEMBER_PROJECTED_OUT!>bindTo<!>(<!NI;TYPE_MISMATCH!>""<!>)
|
||||
}
|
||||
@@ -17,7 +17,7 @@ fun foo(x: Any?, y: C<*>) {
|
||||
|
||||
with(x) {
|
||||
if (this is C<*>) {
|
||||
<!DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST, OI;MEMBER_PROJECTED_OUT!>bindTo<!>(<!NI;TYPE_MISMATCH!>""<!>)
|
||||
<!OI;DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST, OI;MEMBER_PROJECTED_OUT!>bindTo<!>(<!NI;TYPE_MISMATCH!>""<!>)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -5,5 +5,6 @@ interface A<T : A<T?>?> {
|
||||
fun foo(): T?
|
||||
}
|
||||
fun testA(a: A<*>) {
|
||||
a.foo() checkType { _<A<*>?>() }
|
||||
// in new inference here we have A<A<A<*>>>
|
||||
a.foo() checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><A<*>?>() }
|
||||
}
|
||||
|
||||
+5
-5
@@ -14,14 +14,14 @@ class A<E> {
|
||||
fun test(a: A<out CharSequence>, z: Out<CharSequence>) {
|
||||
a.foo {
|
||||
val x: String = <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!> // Should be no TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS
|
||||
<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!>
|
||||
<!NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!>
|
||||
}
|
||||
a.bar { <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>Out<CharSequence>()<!> }
|
||||
a.bar { <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>Out<CharSequence>()<!> }
|
||||
a.bar { Out() }
|
||||
a.bar { <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>z.id()<!> }
|
||||
a.bar { <!NI;TYPE_MISMATCH, TYPE_MISMATCH!>z.id()<!> }
|
||||
|
||||
a.foo {
|
||||
z.foobar(if (1 > 2) return@foo <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!> else "")
|
||||
<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!>
|
||||
z.foobar(if (1 > 2) return@foo <!TYPE_MISMATCH!>""<!> else "")
|
||||
<!NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!>
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -14,14 +14,14 @@ class A<T> {
|
||||
|
||||
fun foo2(a: A<out CharSequence>, b: A<in CharSequence>) {
|
||||
a.<!OI;TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>foo1<!>(<!NI;TYPE_MISMATCH!>Out<CharSequence>()<!>)
|
||||
a.foo1<<!UPPER_BOUND_VIOLATED!>Out<CharSequence><!>>(<!NI;TYPE_MISMATCH!>Out()<!>)
|
||||
a.foo1<<!UPPER_BOUND_VIOLATED!>Out<CharSequence><!>>(Out())
|
||||
|
||||
a.foo1(Out())
|
||||
a.foo1(Out<Nothing>())
|
||||
|
||||
a.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>foo2<!>(<!NI;TYPE_MISMATCH!><!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>Inv<!>()<!>)
|
||||
a.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>foo2<!>(<!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>Inv<!>())
|
||||
a.<!OI;TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>foo2<!>(<!NI;TYPE_MISMATCH!>Inv<CharSequence>()<!>)
|
||||
a.foo2<<!UPPER_BOUND_VIOLATED!>Inv<CharSequence><!>>(<!NI;TYPE_MISMATCH!>Inv()<!>)
|
||||
a.foo2<<!UPPER_BOUND_VIOLATED!>Inv<CharSequence><!>>(<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH!>Inv()<!>)
|
||||
|
||||
a.foo3(In())
|
||||
a.foo3(In<CharSequence>())
|
||||
@@ -31,13 +31,13 @@ fun foo2(a: A<out CharSequence>, b: A<in CharSequence>) {
|
||||
b.foo1(Out<CharSequence>())
|
||||
b.foo1<Out<CharSequence>>(Out())
|
||||
|
||||
b.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>foo2<!>(<!NI;TYPE_MISMATCH!><!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>Inv<!>()<!>)
|
||||
b.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>foo2<!>(<!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>Inv<!>())
|
||||
b.<!OI;TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>foo2<!>(<!NI;TYPE_MISMATCH!>Inv<CharSequence>()<!>)
|
||||
b.foo2<<!UPPER_BOUND_VIOLATED!>Inv<CharSequence><!>>(<!NI;TYPE_MISMATCH!>Inv()<!>)
|
||||
b.foo2<<!UPPER_BOUND_VIOLATED!>Inv<CharSequence><!>>(<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH!>Inv()<!>)
|
||||
|
||||
|
||||
b.<!OI;TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>foo3<!>(<!NI;TYPE_MISMATCH!>In<CharSequence>()<!>)
|
||||
b.foo3<<!UPPER_BOUND_VIOLATED!>In<CharSequence><!>>(<!NI;TYPE_MISMATCH!>In()<!>)
|
||||
b.foo3<<!UPPER_BOUND_VIOLATED!>In<CharSequence><!>>(In())
|
||||
|
||||
b.foo3(In<Any?>())
|
||||
b.foo3(In())
|
||||
|
||||
@@ -13,8 +13,8 @@ class Inv2<<!FINITE_BOUNDS_VIOLATION!>T : Inv2<in T><!>>(val x: T)
|
||||
fun main(a: A<*>, j: JavaClass<*>, i2: Inv2<*>) {
|
||||
// Probably it's too restrictive to suppose star projection type here as Any?,
|
||||
// but looks like we can refine it later
|
||||
a.foo() checkType { _<Any?>() }
|
||||
j.foo() checkType { _<Any?>() }
|
||||
a.foo() checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
|
||||
j.foo() checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
|
||||
i2.x checkType { _<Any?>() }
|
||||
|
||||
j.bar(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!>, <!NI;TYPE_MISMATCH, OI;TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS!>Any()<!>)
|
||||
|
||||
+1
-1
@@ -5,6 +5,6 @@ interface Tr<T> {
|
||||
}
|
||||
|
||||
fun test(t: Tr<*>) {
|
||||
<!SETTER_PROJECTED_OUT!>t.v<!> = t
|
||||
<!SETTER_PROJECTED_OUT!>t.v<!> = <!NI;TYPE_MISMATCH!>t<!>
|
||||
t.v checkType { _<Tr<*>>() }
|
||||
}
|
||||
+4
-3
@@ -7,8 +7,9 @@ interface Tr<T> {
|
||||
}
|
||||
|
||||
fun test(t: Tr<*>) {
|
||||
t.v = null!!
|
||||
<!SETTER_PROJECTED_OUT!>t.v<!> = ""
|
||||
<!SETTER_PROJECTED_OUT!>t.v<!> = null
|
||||
<!NI;SETTER_PROJECTED_OUT!>t.v<!> = null!!
|
||||
<!SETTER_PROJECTED_OUT!>t.v<!> = <!NI;TYPE_MISMATCH!>""<!>
|
||||
<!SETTER_PROJECTED_OUT!>t.v<!> = <!NI;NULL_FOR_NONNULL_TYPE!>null<!>
|
||||
|
||||
t.v checkType { _<Any?>() }
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// Issue: KT-31594
|
||||
|
||||
// FILE: Tr.java
|
||||
|
||||
public class Tr<T> {
|
||||
public T getV() { return null; }
|
||||
public void setV(T value) {}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun test(t: Tr<*>) {
|
||||
<!NI;SETTER_PROJECTED_OUT!>t.v<!> = null
|
||||
<!NI;SETTER_PROJECTED_OUT!>t.v<!> = <!NI;TYPE_MISMATCH!>""<!>
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
public fun test(/*0*/ t: Tr<*>): kotlin.Unit
|
||||
|
||||
public open class Tr</*0*/ T : kotlin.Any!> {
|
||||
public constructor Tr</*0*/ T : kotlin.Any!>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open fun getV(): T!
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open fun setV(/*0*/ value: T!): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Vendored
+1
-1
@@ -7,5 +7,5 @@ interface Tr<T> {
|
||||
fun test(t: Tr<out String>) {
|
||||
// resolved as t.v = t.v + null!!, where type of right operand is String,
|
||||
// so TYPE_MISMATCH: String is not <: of Captured(out String)
|
||||
<!SETTER_PROJECTED_OUT!>t.v<!> += null!!
|
||||
<!NI;TYPE_MISMATCH!><!SETTER_PROJECTED_OUT!>t.v<!> += null!!<!>
|
||||
}
|
||||
+6
-6
@@ -5,15 +5,15 @@
|
||||
fun <T: Any> bar(a: Array<T>): Array<T?> = null!!
|
||||
|
||||
fun test1(a: Array<out Int>) {
|
||||
val r: Array<out Int?> = <!NI;TYPE_MISMATCH!><!NI;UNSUPPORTED!>bar<!>(a)<!>
|
||||
val t = <!NI;UNSUPPORTED!>bar<!>(a)
|
||||
<!NI;UNSUPPORTED!>t<!> checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Array<out Int?>>() }
|
||||
val r: Array<out Int?> = bar(a)
|
||||
val t = bar(a)
|
||||
t checkType { _<Array<out Int?>>() }
|
||||
}
|
||||
|
||||
fun <T: Any> foo(l: Array<T>): Array<Array<T?>> = null!!
|
||||
|
||||
fun test2(a: Array<out Int>) {
|
||||
val r: Array<out Array<out Int?>> = <!NI;TYPE_MISMATCH!><!NI;UNSUPPORTED!>foo<!>(a)<!>
|
||||
val t = <!NI;UNSUPPORTED!>foo<!>(a)
|
||||
<!NI;UNSUPPORTED!>t<!> checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Array<out Array<out Int?>>>() }
|
||||
val r: Array<out Array<out Int?>> = foo(a)
|
||||
val t = foo(a)
|
||||
t checkType { _<Array<out Array<out Int?>>>() }
|
||||
}
|
||||
+1
-1
@@ -16,5 +16,5 @@ fun <S> test1(a: ParameterizedChild<S>?, b: Child): Base<S> = myRun {
|
||||
}
|
||||
|
||||
fun <S> test2(a: S?, b: S): S = myRun {
|
||||
<!TYPE_MISMATCH, TYPE_MISMATCH!>select(a, b)<!>
|
||||
<!TYPE_MISMATCH!>select(a, b)<!>
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ fun <A, B> Foo<A>.map(<!UNUSED_PARAMETER!>f<!>: (A) -> B): Foo<B> = object : Foo
|
||||
|
||||
fun foo() {
|
||||
val l: Foo<String> = object : Foo<String> {}
|
||||
val <!UNUSED_VARIABLE!>m<!>: Foo<String> = l.<!OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>map { <!UNUSED_ANONYMOUS_PARAMETER!>ppp<!> -> <!NI;CONSTANT_EXPECTED_TYPE_MISMATCH, NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!> }<!>
|
||||
val <!UNUSED_VARIABLE!>m<!>: Foo<String> = l.<!OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>map { <!UNUSED_ANONYMOUS_PARAMETER!>ppp<!> -> <!NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!> }<!>
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ public interface J2 extends J {
|
||||
fun main() {
|
||||
J <!NI;TYPE_MISMATCH!>{ <!EXPECTED_PARAMETER_TYPE_MISMATCH!>s: String<!> -> s}<!> // should be prohibited, because SAM value parameter has nullable type
|
||||
J { "" + it<!UNSAFE_CALL!>.<!>length }
|
||||
J { <!NI;NULL_FOR_NONNULL_TYPE, NI;NULL_FOR_NONNULL_TYPE, NULL_FOR_NONNULL_TYPE!>null<!> }
|
||||
J { <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>it?.length?.toString()<!> }
|
||||
J { <!NI;NULL_FOR_NONNULL_TYPE, NULL_FOR_NONNULL_TYPE!>null<!> }
|
||||
J { <!NI;TYPE_MISMATCH, TYPE_MISMATCH!>it?.length?.toString()<!> }
|
||||
|
||||
J2 <!NI;TYPE_MISMATCH!>{ <!EXPECTED_PARAMETER_TYPE_MISMATCH!>s: String<!> -> s}<!>
|
||||
J2 { "" + it<!UNSAFE_CALL!>.<!>length }
|
||||
J2 { <!NI;NULL_FOR_NONNULL_TYPE, NI;NULL_FOR_NONNULL_TYPE, NULL_FOR_NONNULL_TYPE!>null<!> }
|
||||
J2 { <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>it?.length?.toString()<!> }
|
||||
J2 { <!NI;NULL_FOR_NONNULL_TYPE, NULL_FOR_NONNULL_TYPE!>null<!> }
|
||||
J2 { <!NI;TYPE_MISMATCH, TYPE_MISMATCH!>it?.length?.toString()<!> }
|
||||
}
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ fun main() {
|
||||
}
|
||||
|
||||
A.baz {
|
||||
x -> <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>x.hashCode()<!>
|
||||
x -> <!NI;TYPE_MISMATCH, TYPE_MISMATCH!>x.hashCode()<!>
|
||||
}
|
||||
|
||||
val block: (String) -> Any? = {
|
||||
|
||||
+1
-1
@@ -14,5 +14,5 @@ class Owner<in T> {
|
||||
fun getT() = u
|
||||
}
|
||||
|
||||
fun foo(arg: Inner<*>) = arg.getT()
|
||||
<!NI;TYPE_VARIANCE_CONFLICT!>fun foo(arg: Inner<*>)<!> = arg.getT()
|
||||
}
|
||||
+2
-2
@@ -3,7 +3,7 @@ package
|
||||
public final class Owner</*0*/ in T> {
|
||||
public constructor Owner</*0*/ in T>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(/*0*/ arg: Owner<T>.Inner<*>): kotlin.Any?
|
||||
public final fun foo(/*0*/ arg: Owner<T>.Inner<*>): T
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface Rec</*0*/ T : Rec<T>> {
|
||||
|
||||
public interface Super</*0*/ out U> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open fun foo(/*0*/ p: Rec<*>): Rec<*>
|
||||
public open fun foo(/*0*/ p: Rec<*>): Rec<out Rec<out Rec<out Rec<out Rec<out Rec<out kotlin.Any?>>>>>>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
Vendored
+4
-4
@@ -29,9 +29,9 @@ class WithMod {
|
||||
<!FORBIDDEN_BINARY_MOD!>operator<!> fun mod(other: WithMod) = this
|
||||
|
||||
fun test() {
|
||||
val a = this <!OI;FORBIDDEN_BINARY_MOD_AS_REM!>%<!> <!NI;TYPE_MISMATCH!>this<!>
|
||||
val a = this <!OI;FORBIDDEN_BINARY_MOD_AS_REM!>%<!> this
|
||||
var b = this.mod(this)
|
||||
<!NI;TYPE_MISMATCH!>b <!OI;FORBIDDEN_BINARY_MOD_AS_REM!>%=<!> <!NI;TYPE_MISMATCH!>this<!><!>
|
||||
<!NI;TYPE_MISMATCH!>b <!OI;FORBIDDEN_BINARY_MOD_AS_REM!>%=<!> this<!>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,6 @@ fun builtIns(b: Byte, s: Short) {
|
||||
var a = 1 % 2
|
||||
a <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE!>%=<!> 3
|
||||
1.mod(2)
|
||||
b % <!NI;TYPE_MISMATCH!>s<!>
|
||||
1.0 % <!NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>2.0<!>
|
||||
b % s
|
||||
1.0 % 2.0
|
||||
}
|
||||
Vendored
+4
-4
@@ -29,9 +29,9 @@ class WithMod {
|
||||
<!DEPRECATED_BINARY_MOD!>operator<!> fun mod(other: WithMod) = this
|
||||
|
||||
fun test() {
|
||||
val a = this <!OI;DEPRECATED_BINARY_MOD_AS_REM!>%<!> <!NI;TYPE_MISMATCH!>this<!>
|
||||
val a = this <!OI;DEPRECATED_BINARY_MOD_AS_REM!>%<!> this
|
||||
var b = this.mod(this)
|
||||
<!NI;TYPE_MISMATCH!>b <!OI;DEPRECATED_BINARY_MOD_AS_REM!>%=<!> <!NI;TYPE_MISMATCH!>this<!><!>
|
||||
<!NI;TYPE_MISMATCH!>b <!OI;DEPRECATED_BINARY_MOD_AS_REM!>%=<!> this<!>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,6 @@ fun builtIns(b: Byte, s: Short) {
|
||||
var a = 1 % 2
|
||||
a <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE!>%=<!> 3
|
||||
1.mod(2)
|
||||
b % <!NI;TYPE_MISMATCH!>s<!>
|
||||
1.0 % <!NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>2.0<!>
|
||||
b % s
|
||||
1.0 % 2.0
|
||||
}
|
||||
Vendored
+7
-3
@@ -11,9 +11,13 @@ public class A {
|
||||
// FILE: k.kt
|
||||
|
||||
fun test() {
|
||||
A.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>bar<!>(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")
|
||||
A.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>bar<!>(<!OI;NULL_FOR_NONNULL_TYPE!>null<!>, "")
|
||||
|
||||
A.bar<String>(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")
|
||||
A.bar<String?>(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")
|
||||
A.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>bar<!>(<!NULL_FOR_NONNULL_TYPE!>null<!>, A.platformString())
|
||||
A.bar<String?>(<!OI;NULL_FOR_NONNULL_TYPE!>null<!>, "")
|
||||
A.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>bar<!>(<!OI;NULL_FOR_NONNULL_TYPE!>null<!>, A.platformString())
|
||||
|
||||
val x: String? = null
|
||||
A.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>bar<!>(<!OI;TYPE_MISMATCH!>x<!>, "")
|
||||
A.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>bar<!>(<!OI;NULL_FOR_NONNULL_TYPE!>null<!>, "")
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun test(a: Int, b: Boolean) {
|
||||
<!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar<!>(a.<!OI;TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>foo<!>(<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>b<!>))
|
||||
<!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar<!>(a.<!OI;TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>foo<!>(<!NI;TYPE_MISMATCH, TYPE_MISMATCH!>b<!>))
|
||||
}
|
||||
|
||||
fun <T, R> T.foo(l: (T) -> R): R = TODO()
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// !LANGUAGE: -NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
abstract class A<Context : A<Context>> {
|
||||
val x: X = TODO()
|
||||
|
||||
fun getGetX(): X = TODO()
|
||||
}
|
||||
|
||||
class B<D> : A<B<D>>()
|
||||
|
||||
class C : A<C>()
|
||||
|
||||
interface X {
|
||||
fun foo()
|
||||
}
|
||||
|
||||
fun B<*>.checkValueArguments() {
|
||||
this.x.foo()
|
||||
x.foo()
|
||||
|
||||
this.getGetX().foo()
|
||||
getGetX().foo()
|
||||
}
|
||||
|
||||
fun C.test() {
|
||||
x.foo()
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package
|
||||
|
||||
public fun B<*>.checkValueArguments(): kotlin.Unit
|
||||
public fun C.test(): kotlin.Unit
|
||||
|
||||
public abstract class A</*0*/ Context : A<Context>> {
|
||||
public constructor A</*0*/ Context : A<Context>>()
|
||||
public final val x: X
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun getGetX(): X
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class B</*0*/ D> : A<B<D>> {
|
||||
public constructor B</*0*/ D>()
|
||||
public final override /*1*/ /*fake_override*/ val x: X
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final override /*1*/ /*fake_override*/ fun getGetX(): X
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class C : A<C> {
|
||||
public constructor C()
|
||||
public final override /*1*/ /*fake_override*/ val x: X
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final override /*1*/ /*fake_override*/ fun getGetX(): X
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface X {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ fun test() {
|
||||
<!OI;CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!>
|
||||
}<!>)
|
||||
|
||||
bar(<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH!><!CONSTANT_EXPECTED_TYPE_MISMATCH, NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!> ?: <!CONSTANT_EXPECTED_TYPE_MISMATCH, NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!><!>)
|
||||
bar(<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH!><!OI;CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!> ?: <!OI;CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!><!>)
|
||||
}
|
||||
|
||||
fun bar(s: String) = s
|
||||
@@ -0,0 +1,29 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
// FILE: JavaFace.java
|
||||
public interface JavaFace<T> {
|
||||
void singleMethod();
|
||||
}
|
||||
|
||||
// FILE: JavaFaceUser.java
|
||||
public class JavaFaceUser<T> {
|
||||
public <X> void use1(JavaFace<X> face) {}
|
||||
public void use2(JavaFace<T> face) {}
|
||||
}
|
||||
|
||||
// FILE: KotlinSamUser.kt
|
||||
fun JavaFaceUser<out Any>.useOut() {
|
||||
use1<Any> {}
|
||||
use2 {}
|
||||
}
|
||||
|
||||
fun JavaFaceUser<in Any>.useIn() {
|
||||
use1<Any> {}
|
||||
use2 {}
|
||||
}
|
||||
|
||||
fun JavaFaceUser<Any>.useInv() {
|
||||
use1<Any> {}
|
||||
use2 {}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package
|
||||
|
||||
public fun JavaFaceUser<in kotlin.Any>.useIn(): kotlin.Unit
|
||||
public fun JavaFaceUser<kotlin.Any>.useInv(): kotlin.Unit
|
||||
public fun JavaFaceUser<out kotlin.Any>.useOut(): kotlin.Unit
|
||||
|
||||
public interface JavaFace</*0*/ T : kotlin.Any!> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public abstract fun singleMethod(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class JavaFaceUser</*0*/ T : kotlin.Any!> {
|
||||
public constructor JavaFaceUser</*0*/ T : kotlin.Any!>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
public open fun </*0*/ X : kotlin.Any!> use1(/*0*/ face: JavaFace<X!>!): kotlin.Unit
|
||||
public open fun use2(/*0*/ face: JavaFace<T!>!): kotlin.Unit
|
||||
}
|
||||
@@ -17,9 +17,9 @@ interface B<R, T: B<List<R>, <!UPPER_BOUND_VIOLATED!>T<!>>> {
|
||||
}
|
||||
|
||||
fun testB(b: B<*, *>) {
|
||||
<!OI;TYPE_MISMATCH!>b<!>.<!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>r<!>().<!NI;DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>checkType<!> { <!NI;UNRESOLVED_REFERENCE!>_<!><Any?>() }
|
||||
<!OI;TYPE_MISMATCH!>b<!>.<!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>t<!>().<!NI;DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>checkType<!> { <!NI;UNRESOLVED_REFERENCE!>_<!><B<List<*>, *>>() }
|
||||
<!OI;TYPE_MISMATCH!>b<!>.r().checkType { _<Any?>() }
|
||||
<!OI;TYPE_MISMATCH!>b<!>.t().checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><B<List<*>, *>>() }
|
||||
|
||||
<!OI;TYPE_MISMATCH!><!OI;TYPE_MISMATCH!>b<!>.<!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>t<!>()<!>.<!NI;DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>r<!>().<!NI;DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>size<!>
|
||||
<!OI;TYPE_MISMATCH!><!OI;TYPE_MISMATCH!>b<!>.t()<!>.r().size
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -21,21 +21,21 @@ fun test2() {}
|
||||
@Ann(s = <!NI;TYPE_MISMATCH, OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>arrayOf(1)<!>)
|
||||
fun test3() {}
|
||||
|
||||
@Ann(s = <!NI;TYPE_MISMATCH, OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, TYPE_MISMATCH!>["value"]<!>)
|
||||
@Ann(s = <!OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, TYPE_MISMATCH!>["value"]<!>)
|
||||
fun test5() {}
|
||||
|
||||
@JavaAnn(value = <!NI;TYPE_MISMATCH, OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>arrayOf("value")<!>)
|
||||
fun jTest1() {}
|
||||
|
||||
@JavaAnn(value = <!NI;TYPE_MISMATCH, OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, TYPE_MISMATCH!>["value"]<!>)
|
||||
@JavaAnn(value = <!OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, TYPE_MISMATCH!>["value"]<!>)
|
||||
fun jTest2() {}
|
||||
|
||||
@JavaAnn(value = <!NI;TYPE_MISMATCH, OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, TYPE_MISMATCH!>["value"]<!>, path = ["path"])
|
||||
@JavaAnn(value = <!OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, TYPE_MISMATCH!>["value"]<!>, path = ["path"])
|
||||
fun jTest3() {}
|
||||
|
||||
annotation class IntAnn(vararg val i: Int)
|
||||
|
||||
@IntAnn(i = <!NI;TYPE_MISMATCH, OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, TYPE_MISMATCH!>[1, 2]<!>)
|
||||
@IntAnn(i = <!OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, TYPE_MISMATCH!>[1, 2]<!>)
|
||||
fun foo1() {}
|
||||
|
||||
@IntAnn(i = <!TYPE_MISMATCH!>intArrayOf(0)<!>)
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.frontend.di.configureModule
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProviderImpl
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.types.expressions.FakeCallResolver
|
||||
|
||||
@@ -36,6 +37,7 @@ fun createContainerForTests(project: Project, module: ModuleDescriptor): Contain
|
||||
return ContainerForTests(createContainer("Tests", JvmPlatform) {
|
||||
configureModule(ModuleContext(module, project), JvmPlatform, JvmTarget.DEFAULT)
|
||||
useInstance(LanguageVersionSettingsImpl.DEFAULT)
|
||||
useImpl<SubstitutingScopeProviderImpl>()
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
useImpl<ExpressionTypingServices>()
|
||||
})
|
||||
|
||||
@@ -83,7 +83,7 @@ fun case_5(x: Any?) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!><!DEBUG_INFO_EXPRESSION_TYPE("ClassWithThreeTypeParameters<*, *, *> & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>x<!>.x<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!><!DEBUG_INFO_SMARTCAST!>x<!>.y<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!><!DEBUG_INFO_SMARTCAST!>x<!>.z<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters<*, *> & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>x<!>.ip2test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("ClassWithThreeTypeParameters<*, *, *> & InterfaceWithTwoTypeParameters<*, *> & kotlin.Any & kotlin.Any?")!>x<!>.ip2test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("ClassWithThreeTypeParameters<*, *, *> & InterfaceWithTwoTypeParameters<*, *> & kotlin.Any & kotlin.Any?")!>x<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!><!DEBUG_INFO_EXPRESSION_TYPE("ClassWithThreeTypeParameters<*, *, *> & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>x<!>.x<!>
|
||||
}
|
||||
|
||||
@@ -14,18 +14,18 @@
|
||||
// TESTCASE NUMBER: 1
|
||||
fun Any.case_1() {
|
||||
if (this is Inv<*>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<*>"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any"), DEBUG_INFO_SMARTCAST!>this<!>.test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!><!DEBUG_INFO_EXPRESSION_TYPE("Inv<*>"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any"), DEBUG_INFO_SMARTCAST!>this<!>.prop_4<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!><!DEBUG_INFO_EXPRESSION_TYPE("Inv<*>"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any"), DEBUG_INFO_SMARTCAST!>this<!>.prop_4<!>.inv()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int"), DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>prop_4<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int"), DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>prop_4<!>.inv()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<*> & kotlin.Any"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>this<!>.test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!><!DEBUG_INFO_EXPRESSION_TYPE("Inv<*> & kotlin.Any"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>this<!>.prop_4<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!><!DEBUG_INFO_EXPRESSION_TYPE("Inv<*> & kotlin.Any"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>this<!>.prop_4<!>.inv()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>prop_4<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>prop_4<!>.inv()
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
fun Any.case_2() {
|
||||
if (this is ClassWithSixTypeParameters<*, *, *, *, *, *>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("ClassWithSixTypeParameters<*, *, *, *, *, *>"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any"), DEBUG_INFO_SMARTCAST!>this<!>.test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("ClassWithSixTypeParameters<*, *, *, *, *, *> & kotlin.Any"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>this<!>.test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!><!DEBUG_INFO_EXPRESSION_TYPE("ClassWithSixTypeParameters<*, *, *, *, *, *>"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any"), DEBUG_INFO_SMARTCAST!>this<!>.x<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!><!DEBUG_INFO_EXPRESSION_TYPE("ClassWithSixTypeParameters<*, *, *, *, *, *>"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any"), DEBUG_INFO_SMARTCAST!>this<!>.y<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?"), DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>x<!>
|
||||
@@ -36,18 +36,18 @@ fun Any.case_2() {
|
||||
// TESTCASE NUMBER: 3
|
||||
fun <T> T.case_3() {
|
||||
if (this is Inv<*>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<*>"), DEBUG_INFO_EXPRESSION_TYPE("T"), DEBUG_INFO_SMARTCAST!>this<!>.test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!><!DEBUG_INFO_EXPRESSION_TYPE("Inv<*>"), DEBUG_INFO_EXPRESSION_TYPE("T"), DEBUG_INFO_SMARTCAST!>this<!>.prop_4<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!><!DEBUG_INFO_EXPRESSION_TYPE("Inv<*>"), DEBUG_INFO_EXPRESSION_TYPE("T"), DEBUG_INFO_SMARTCAST!>this<!>.prop_4<!>.inv()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int"), DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>prop_4<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int"), DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>prop_4<!>.inv()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<*> & T & T!!"), DEBUG_INFO_EXPRESSION_TYPE("T")!>this<!>.test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!><!DEBUG_INFO_EXPRESSION_TYPE("Inv<*> & T & T!!"), DEBUG_INFO_EXPRESSION_TYPE("T")!>this<!>.prop_4<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!><!DEBUG_INFO_EXPRESSION_TYPE("Inv<*> & T & T!!"), DEBUG_INFO_EXPRESSION_TYPE("T")!>this<!>.prop_4<!>.inv()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>prop_4<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>prop_4<!>.inv()
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 4
|
||||
fun <T> T?.case_4() {
|
||||
if (this is ClassWithSixTypeParameters<*, *, *, *, *, *>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("ClassWithSixTypeParameters<*, *, *, *, *, *>"), DEBUG_INFO_EXPRESSION_TYPE("T?"), DEBUG_INFO_SMARTCAST!>this<!>.test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("ClassWithSixTypeParameters<*, *, *, *, *, *> & T!! & T?"), DEBUG_INFO_EXPRESSION_TYPE("T?")!>this<!>.test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!><!DEBUG_INFO_EXPRESSION_TYPE("ClassWithSixTypeParameters<*, *, *, *, *, *>"), DEBUG_INFO_EXPRESSION_TYPE("T?"), DEBUG_INFO_SMARTCAST!>this<!>.x<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!><!DEBUG_INFO_EXPRESSION_TYPE("ClassWithSixTypeParameters<*, *, *, *, *, *>"), DEBUG_INFO_EXPRESSION_TYPE("T?"), DEBUG_INFO_SMARTCAST!>this<!>.y<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?"), DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>x<!>
|
||||
|
||||
@@ -8093,6 +8093,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedTypeInInputPosition.kt")
|
||||
public void testCapturedTypeInInputPosition() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/capturedTypeInInputPosition.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("commonSupertypeContravariant.kt")
|
||||
public void testCommonSupertypeContravariant() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt");
|
||||
@@ -8932,6 +8937,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("setterProjectedOutAssignFromJava.kt")
|
||||
public void testSetterProjectedOutAssignFromJava() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssignFromJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("setterProjectedOutNoPlusAssign.kt")
|
||||
public void testSetterProjectedOutNoPlusAssign() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.kt");
|
||||
@@ -17375,6 +17385,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/HiddenDeclarations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitAndExplicitThis.kt")
|
||||
public void testImplicitAndExplicitThis() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/implicitAndExplicitThis.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitReceiverProperty.kt")
|
||||
public void testImplicitReceiverProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.kt");
|
||||
@@ -18092,6 +18107,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt25290.kt")
|
||||
public void testKt25290() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/kt25290.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("OverloadPriority.kt")
|
||||
public void testOverloadPriority() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/OverloadPriority.kt");
|
||||
|
||||
Generated
+20
@@ -8088,6 +8088,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedTypeInInputPosition.kt")
|
||||
public void testCapturedTypeInInputPosition() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/capturedTypeInInputPosition.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("commonSupertypeContravariant.kt")
|
||||
public void testCommonSupertypeContravariant() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt");
|
||||
@@ -8927,6 +8932,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssign.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("setterProjectedOutAssignFromJava.kt")
|
||||
public void testSetterProjectedOutAssignFromJava() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutAssignFromJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("setterProjectedOutNoPlusAssign.kt")
|
||||
public void testSetterProjectedOutNoPlusAssign() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.kt");
|
||||
@@ -17365,6 +17375,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/HiddenDeclarations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitAndExplicitThis.kt")
|
||||
public void testImplicitAndExplicitThis() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/implicitAndExplicitThis.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitReceiverProperty.kt")
|
||||
public void testImplicitReceiverProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.kt");
|
||||
@@ -18082,6 +18097,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt25290.kt")
|
||||
public void testKt25290() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/kt25290.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("OverloadPriority.kt")
|
||||
public void testOverloadPriority() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/OverloadPriority.kt");
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.load.kotlin.KotlinClassFinder
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProvider
|
||||
import java.util.*
|
||||
|
||||
class JavaResolverComponents(
|
||||
@@ -64,7 +65,8 @@ class JavaResolverComponents(
|
||||
val annotationTypeQualifierResolver: AnnotationTypeQualifierResolver,
|
||||
val signatureEnhancement: SignatureEnhancement,
|
||||
val javaClassesTracker: JavaClassesTracker,
|
||||
val settings: JavaResolverSettings
|
||||
val settings: JavaResolverSettings,
|
||||
val substitutingScopeProvider: SubstitutingScopeProvider
|
||||
) {
|
||||
fun replace(
|
||||
javaResolverCache: JavaResolverCache = this.javaResolverCache
|
||||
@@ -73,7 +75,7 @@ class JavaResolverComponents(
|
||||
signaturePropagator, errorReporter, javaResolverCache,
|
||||
javaPropertyInitializerEvaluator, samConversionResolver, sourceElementFactory,
|
||||
moduleClassResolver, packagePartProvider, supertypeLoopChecker, lookupTracker, module, reflectionTypes,
|
||||
annotationTypeQualifierResolver, signatureEnhancement, javaClassesTracker, settings
|
||||
annotationTypeQualifierResolver, signatureEnhancement, javaClassesTracker, settings, substitutingScopeProvider
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -46,7 +46,8 @@ class LazyJavaClassDescriptor(
|
||||
) : ClassDescriptorBase(
|
||||
outerContext.storageManager, containingDeclaration, jClass.name,
|
||||
outerContext.components.sourceElementFactory.source(jClass),
|
||||
/* isExternal = */ false
|
||||
/* isExternal = */ false,
|
||||
outerContext.components.substitutingScopeProvider
|
||||
), JavaClassDescriptor {
|
||||
|
||||
companion object {
|
||||
|
||||
+2
-1
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.serialization.deserialization.ContractDeserializer
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationComponents
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProvider
|
||||
import org.jetbrains.kotlin.utils.Jsr305State
|
||||
|
||||
class RuntimeModuleData private constructor(
|
||||
@@ -70,7 +71,7 @@ class RuntimeModuleData private constructor(
|
||||
singleModuleClassResolver, PackagePartProvider.Empty, SupertypeLoopChecker.EMPTY, LookupTracker.DO_NOTHING, module,
|
||||
ReflectionTypes(module, notFoundClasses), annotationTypeQualifierResolver,
|
||||
SignatureEnhancement(annotationTypeQualifierResolver, Jsr305State.DISABLED),
|
||||
JavaClassesTracker.Default, JavaResolverSettings.Default
|
||||
JavaClassesTracker.Default, JavaResolverSettings.Default, SubstitutingScopeProvider.DEFAULT
|
||||
)
|
||||
|
||||
val lazyJavaPackageFragmentProvider = LazyJavaPackageFragmentProvider(javaResolverComponents)
|
||||
|
||||
+10
-5
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.scopes.InnerClassesScopeWrapper;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.SubstitutingScope;
|
||||
import org.jetbrains.kotlin.storage.NotNullLazyValue;
|
||||
import org.jetbrains.kotlin.storage.StorageManager;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
@@ -34,10 +33,11 @@ import java.util.List;
|
||||
public abstract class AbstractClassDescriptor implements ClassDescriptor {
|
||||
private final Name name;
|
||||
protected final NotNullLazyValue<SimpleType> defaultType;
|
||||
protected final SubstitutingScopeProvider substitutingScopeProvider;
|
||||
private final NotNullLazyValue<MemberScope> unsubstitutedInnerClassesScope;
|
||||
private final NotNullLazyValue<ReceiverParameterDescriptor> thisAsReceiverParameter;
|
||||
|
||||
public AbstractClassDescriptor(@NotNull StorageManager storageManager, @NotNull Name name) {
|
||||
public AbstractClassDescriptor(@NotNull StorageManager storageManager, @NotNull Name name, @NotNull SubstitutingScopeProvider substitutingScopeProvider) {
|
||||
this.name = name;
|
||||
this.defaultType = storageManager.createLazyValue(new Function0<SimpleType>() {
|
||||
@Override
|
||||
@@ -57,6 +57,11 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
|
||||
return new LazyClassReceiverParameterDescriptor(AbstractClassDescriptor.this);
|
||||
}
|
||||
});
|
||||
this.substitutingScopeProvider = substitutingScopeProvider;
|
||||
}
|
||||
|
||||
public AbstractClassDescriptor(@NotNull StorageManager storageManager, @NotNull Name name) {
|
||||
this(storageManager, name, SubstitutingScopeProvider.Companion.getDEFAULT());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -92,7 +97,7 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
|
||||
if (typeArguments.isEmpty()) return getUnsubstitutedMemberScope();
|
||||
|
||||
TypeSubstitutor substitutor = TypeConstructorSubstitution.create(getTypeConstructor(), typeArguments).buildSubstitutor();
|
||||
return new SubstitutingScope(getUnsubstitutedMemberScope(), substitutor);
|
||||
return substitutingScopeProvider.createSubstitutingScope(getUnsubstitutedMemberScope(), substitutor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -101,7 +106,7 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
|
||||
if (typeSubstitution.isEmpty()) return getUnsubstitutedMemberScope();
|
||||
|
||||
TypeSubstitutor substitutor = TypeSubstitutor.create(typeSubstitution);
|
||||
return new SubstitutingScope(getUnsubstitutedMemberScope(), substitutor);
|
||||
return substitutingScopeProvider.createSubstitutingScope(getUnsubstitutedMemberScope(), substitutor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -110,7 +115,7 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
|
||||
if (substitutor.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return new LazySubstitutingClassDescriptor(this, substitutor);
|
||||
return new LazySubstitutingClassDescriptor(this, substitutor, substitutingScopeProvider);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+13
-1
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.storage.StorageManager;
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProvider;
|
||||
|
||||
public abstract class ClassDescriptorBase extends AbstractClassDescriptor {
|
||||
|
||||
@@ -35,7 +36,18 @@ public abstract class ClassDescriptorBase extends AbstractClassDescriptor {
|
||||
@NotNull SourceElement source,
|
||||
boolean isExternal
|
||||
) {
|
||||
super(storageManager, name);
|
||||
this(storageManager, containingDeclaration, name, source, isExternal, SubstitutingScopeProvider.Companion.getDEFAULT());
|
||||
}
|
||||
|
||||
protected ClassDescriptorBase(
|
||||
@NotNull StorageManager storageManager,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull Name name,
|
||||
@NotNull SourceElement source,
|
||||
boolean isExternal,
|
||||
@NotNull SubstitutingScopeProvider substitutingScopeProvider
|
||||
) {
|
||||
super(storageManager, name, substitutingScopeProvider);
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
this.source = source;
|
||||
this.isExternal = isExternal;
|
||||
|
||||
+21
-2
@@ -324,11 +324,21 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public FunctionDescriptor substitute(@NotNull TypeSubstitutor originalSubstitutor) {
|
||||
return substitute(originalSubstitutor, SubstitutingScopeProvider.Companion.getDEFAULT());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FunctionDescriptor substitute(@NotNull TypeSubstitutor originalSubstitutor, SubstitutingScopeProvider substitutingScopeProvider) {
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return newCopyBuilder(originalSubstitutor).setOriginal(getOriginal()).setJustForTypeSubstitution(true).build();
|
||||
return newCopyBuilder(originalSubstitutor)
|
||||
.setOriginal(getOriginal())
|
||||
.setJustForTypeSubstitution(true)
|
||||
.setSubstitutingScopeProvider(substitutingScopeProvider)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -365,6 +375,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
private Map<UserDataKey<?>, Object> userDataMap = new LinkedHashMap<UserDataKey<?>, Object>();
|
||||
private Boolean newHasSynthesizedParameterNames = null;
|
||||
protected boolean justForTypeSubstitution = false;
|
||||
protected @NotNull SubstitutingScopeProvider substitutingScopeProvider;
|
||||
|
||||
public CopyConfiguration(
|
||||
@NotNull TypeSubstitution substitution,
|
||||
@@ -386,6 +397,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
this.newExtensionReceiverParameter = newExtensionReceiverParameter;
|
||||
this.newReturnType = newReturnType;
|
||||
this.name = name;
|
||||
substitutingScopeProvider = SubstitutingScopeProvider.Companion.getDEFAULT();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -554,6 +566,12 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
justForTypeSubstitution = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CopyConfiguration setSubstitutingScopeProvider(@NotNull SubstitutingScopeProvider substitutingScopeProvider) {
|
||||
this.substitutingScopeProvider = substitutingScopeProvider;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -591,7 +609,8 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters =
|
||||
new ArrayList<TypeParameterDescriptor>(unsubstitutedTypeParameters.size());
|
||||
final TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(
|
||||
unsubstitutedTypeParameters, configuration.substitution, substitutedDescriptor, substitutedTypeParameters, wereChanges
|
||||
unsubstitutedTypeParameters, configuration.substitution, substitutedDescriptor, substitutedTypeParameters,
|
||||
wereChanges, configuration.substitutingScopeProvider
|
||||
);
|
||||
if (substitutor == null) return null;
|
||||
|
||||
|
||||
+7
-5
@@ -28,10 +28,12 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
private List<TypeParameterDescriptor> typeConstructorParameters;
|
||||
private List<TypeParameterDescriptor> declaredTypeParameters;
|
||||
private TypeConstructor typeConstructor;
|
||||
private final SubstitutingScopeProvider substitutingScopeProvider;
|
||||
|
||||
public LazySubstitutingClassDescriptor(ClassDescriptor descriptor, TypeSubstitutor substitutor) {
|
||||
public LazySubstitutingClassDescriptor(ClassDescriptor descriptor, TypeSubstitutor substitutor, SubstitutingScopeProvider substitutingScopeProvider) {
|
||||
this.original = descriptor;
|
||||
this.originalSubstitutor = substitutor;
|
||||
this.substitutingScopeProvider = substitutingScopeProvider;
|
||||
}
|
||||
|
||||
private TypeSubstitutor getSubstitutor() {
|
||||
@@ -87,7 +89,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return memberScope;
|
||||
}
|
||||
return new SubstitutingScope(memberScope, getSubstitutor());
|
||||
return substitutingScopeProvider.createSubstitutingScope(memberScope, getSubstitutor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -97,7 +99,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return memberScope;
|
||||
}
|
||||
return new SubstitutingScope(memberScope, getSubstitutor());
|
||||
return substitutingScopeProvider.createSubstitutingScope(memberScope, getSubstitutor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -107,7 +109,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return memberScope;
|
||||
}
|
||||
return new SubstitutingScope(memberScope, getSubstitutor());
|
||||
return substitutingScopeProvider.createSubstitutingScope(memberScope, getSubstitutor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -175,7 +177,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
@Override
|
||||
public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
if (substitutor.isEmpty()) return this;
|
||||
return new LazySubstitutingClassDescriptor(this, TypeSubstitutor.createChainedSubstitutor(substitutor.getSubstitution(), getSubstitutor().getSubstitution()));
|
||||
return new LazySubstitutingClassDescriptor(this, TypeSubstitutor.createChainedSubstitutor(substitutor.getSubstitution(), getSubstitutor().getSubstitution()), substitutingScopeProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+66
-3
@@ -47,6 +47,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
private final boolean isExternal;
|
||||
private final boolean isDelegated;
|
||||
|
||||
private final SubstitutingScopeProvider substitutingScopeProvider;
|
||||
|
||||
private ReceiverParameterDescriptor dispatchReceiverParameter;
|
||||
private ReceiverParameterDescriptor extensionReceiverParameter;
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
@@ -72,6 +74,28 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
boolean isActual,
|
||||
boolean isExternal,
|
||||
boolean isDelegated
|
||||
) {
|
||||
this(containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, source,
|
||||
lateInit, isConst, isExpect, isActual, isExternal, isDelegated, SubstitutingScopeProvider.Companion.getDEFAULT());
|
||||
}
|
||||
|
||||
protected PropertyDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@Nullable PropertyDescriptor original,
|
||||
@NotNull Annotations annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind,
|
||||
@NotNull SourceElement source,
|
||||
boolean lateInit,
|
||||
boolean isConst,
|
||||
boolean isExpect,
|
||||
boolean isActual,
|
||||
boolean isExternal,
|
||||
boolean isDelegated,
|
||||
@NotNull SubstitutingScopeProvider substitutingScopeProvider
|
||||
) {
|
||||
super(containingDeclaration, annotations, name, null, isVar, source);
|
||||
this.modality = modality;
|
||||
@@ -84,6 +108,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
this.isActual = isActual;
|
||||
this.isExternal = isExternal;
|
||||
this.isDelegated = isDelegated;
|
||||
this.substitutingScopeProvider = substitutingScopeProvider;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -102,10 +127,39 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
boolean isActual,
|
||||
boolean isExternal,
|
||||
boolean isDelegated
|
||||
) {
|
||||
return create(containingDeclaration, annotations, modality, visibility, isVar, name, kind, source,
|
||||
lateInit, isConst, isExpect, isActual, isExternal, isDelegated, SubstitutingScopeProvider.Companion.getDEFAULT());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertyDescriptorImpl create(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull Annotations annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind,
|
||||
@NotNull SourceElement source,
|
||||
boolean lateInit,
|
||||
boolean isConst,
|
||||
boolean isExpect,
|
||||
boolean isActual,
|
||||
boolean isExternal,
|
||||
boolean isDelegated,
|
||||
@NotNull SubstitutingScopeProvider substitutingScopeProvider
|
||||
) {
|
||||
return new PropertyDescriptorImpl(containingDeclaration, null, annotations,
|
||||
modality, visibility, isVar, name, kind, source, lateInit, isConst,
|
||||
isExpect, isActual, isExternal, isDelegated);
|
||||
isExpect, isActual, isExternal, isDelegated, substitutingScopeProvider);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PropertyDescriptorImpl getCopy() {
|
||||
return new PropertyDescriptorImpl(getContainingDeclaration(), original, getAnnotations(),
|
||||
modality, visibility, isVar(), getName(), kind, getSource(), lateInit, isConst,
|
||||
isExpect, isActual, isExternal, isDelegated, substitutingScopeProvider);
|
||||
}
|
||||
|
||||
public void setType(
|
||||
@@ -258,6 +312,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
private ReceiverParameterDescriptor dispatchReceiverParameter = PropertyDescriptorImpl.this.dispatchReceiverParameter;
|
||||
private List<TypeParameterDescriptor> newTypeParameters = null;
|
||||
private Name name = getName();
|
||||
private boolean setterProjectedOut = PropertyDescriptorImpl.this.setterProjectedOut;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -364,6 +419,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(
|
||||
originalTypeParameters, copyConfiguration.substitution, substitutedDescriptor, substitutedTypeParameters
|
||||
);
|
||||
substitutor.setSubstitutingScopeProvider(substitutingScopeProvider);
|
||||
|
||||
KotlinType originalOutType = getType();
|
||||
KotlinType outType = substitutor.substitute(originalOutType, Variance.OUT_VARIANCE);
|
||||
@@ -460,6 +516,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
substitutedDescriptor.setCompileTimeInitializer(compileTimeInitializer);
|
||||
}
|
||||
|
||||
substitutedDescriptor.setterProjectedOut = copyConfiguration.setterProjectedOut;
|
||||
|
||||
return substitutedDescriptor;
|
||||
}
|
||||
|
||||
@@ -470,7 +528,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
return prev;
|
||||
}
|
||||
|
||||
private static FunctionDescriptor getSubstitutedInitialSignatureDescriptor(
|
||||
public static FunctionDescriptor getSubstitutedInitialSignatureDescriptor(
|
||||
@NotNull TypeSubstitutor substitutor,
|
||||
@NotNull PropertyAccessorDescriptor accessorDescriptor
|
||||
) {
|
||||
@@ -490,7 +548,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
) {
|
||||
return new PropertyDescriptorImpl(
|
||||
newOwner, original, getAnnotations(), newModality, newVisibility, isVar(), newName, kind, SourceElement.NO_SOURCE,
|
||||
isLateInit(), isConst(), isExpect(), isActual(), isExternal(), isDelegated()
|
||||
isLateInit(), isConst(), isExpect(), isActual(), isExternal(), isDelegated(), substitutingScopeProvider
|
||||
);
|
||||
}
|
||||
|
||||
@@ -564,4 +622,9 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
public <V> V getUserData(UserDataKey<V> key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SubstitutingScopeProvider getSubstitutingScopeProvider() {
|
||||
return substitutingScopeProvider;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.utils.join
|
||||
|
||||
open class ValueParameterDescriptorImpl(
|
||||
@@ -102,8 +103,7 @@ open class ValueParameterDescriptorImpl(
|
||||
override fun getOriginal() = if (original === this) this else original.original
|
||||
|
||||
override fun substitute(substitutor: TypeSubstitutor): ValueParameterDescriptor {
|
||||
if (substitutor.isEmpty) return this
|
||||
throw UnsupportedOperationException() // TODO
|
||||
return this
|
||||
}
|
||||
|
||||
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R {
|
||||
|
||||
+20
-5
@@ -100,16 +100,25 @@ class CapturedType(
|
||||
CapturedType(typeProjection, constructor, isMarkedNullable, newAnnotations)
|
||||
}
|
||||
|
||||
object OldCapturedTypeCreator : CapturedTypeCreator {
|
||||
override fun createCapturedType(typeProjection: TypeProjection): TypeProjection {
|
||||
return TypeProjectionImpl(CapturedType(typeProjection))
|
||||
}
|
||||
}
|
||||
|
||||
fun createCapturedType(typeProjection: TypeProjection): KotlinType = CapturedType(typeProjection)
|
||||
|
||||
fun KotlinType.isCaptured(): Boolean = constructor is CapturedTypeConstructor
|
||||
|
||||
fun TypeSubstitution.wrapWithCapturingSubstitution(needApproximation: Boolean = true): TypeSubstitution =
|
||||
fun TypeSubstitution.wrapWithCapturingSubstitution(
|
||||
capturedTypeCreator: CapturedTypeCreator = OldCapturedTypeCreator,
|
||||
needApproximation: Boolean = true
|
||||
): TypeSubstitution =
|
||||
if (this is IndexedParametersSubstitution)
|
||||
IndexedParametersSubstitution(
|
||||
this.parameters,
|
||||
this.arguments.zip(this.parameters).map {
|
||||
it.first.createCapturedIfNeeded(it.second)
|
||||
it.first.createCapturedIfNeeded(it.second, capturedTypeCreator)
|
||||
}.toTypedArray(),
|
||||
approximateCapturedTypes = needApproximation
|
||||
)
|
||||
@@ -117,10 +126,16 @@ fun TypeSubstitution.wrapWithCapturingSubstitution(needApproximation: Boolean =
|
||||
object : DelegatedTypeSubstitution(this@wrapWithCapturingSubstitution) {
|
||||
override fun approximateContravariantCapturedTypes() = needApproximation
|
||||
override fun get(key: KotlinType) =
|
||||
super.get(key)?.createCapturedIfNeeded(key.constructor.declarationDescriptor as? TypeParameterDescriptor)
|
||||
super.get(key)?.createCapturedIfNeeded(
|
||||
key.constructor.declarationDescriptor as? TypeParameterDescriptor,
|
||||
capturedTypeCreator
|
||||
)
|
||||
}
|
||||
|
||||
private fun TypeProjection.createCapturedIfNeeded(typeParameterDescriptor: TypeParameterDescriptor?): TypeProjection {
|
||||
private fun TypeProjection.createCapturedIfNeeded(
|
||||
typeParameterDescriptor: TypeParameterDescriptor?,
|
||||
capturedTypeCreator: CapturedTypeCreator
|
||||
): TypeProjection {
|
||||
if (typeParameterDescriptor == null || projectionKind == Variance.INVARIANT) return this
|
||||
|
||||
// Treat consistent projections as invariant
|
||||
@@ -134,5 +149,5 @@ private fun TypeProjection.createCapturedIfNeeded(typeParameterDescriptor: TypeP
|
||||
TypeProjectionImpl(this@createCapturedIfNeeded.type)
|
||||
}
|
||||
|
||||
return TypeProjectionImpl(createCapturedType(this))
|
||||
return capturedTypeCreator.createCapturedType(this)
|
||||
}
|
||||
|
||||
@@ -18,18 +18,24 @@ package org.jetbrains.kotlin.resolve.scopes
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Substitutable
|
||||
import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.wrapWithCapturingSubstitution
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProvider
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.newLinkedHashSetWithExpectedSize
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import java.util.*
|
||||
|
||||
class SubstitutingScope(private val workerScope: MemberScope, givenSubstitutor: TypeSubstitutor) : MemberScope {
|
||||
class SubstitutingScope(private val workerScope: MemberScope, givenSubstitutor: TypeSubstitutor, private val substitutingScopeProvider: SubstitutingScopeProvider) : MemberScope {
|
||||
|
||||
private val substitutor = givenSubstitutor.substitution.wrapWithCapturingSubstitution().buildSubstitutor()
|
||||
private val substitutor: TypeSubstitutor = givenSubstitutor.substitution
|
||||
.wrapWithCapturingSubstitution(capturedTypeCreator = substitutingScopeProvider.provideCapturedTypeCreator())
|
||||
.buildSubstitutor().also { it.setSubstitutingScopeProvider(substitutingScopeProvider) }
|
||||
|
||||
private var substitutedDescriptors: MutableMap<DeclarationDescriptor, DeclarationDescriptor>? = null
|
||||
|
||||
@@ -43,11 +49,44 @@ class SubstitutingScope(private val workerScope: MemberScope, givenSubstitutor:
|
||||
}
|
||||
|
||||
val substituted = substitutedDescriptors!!.getOrPut(descriptor) {
|
||||
val assertionMessage = {
|
||||
"We expect that no conflict should happen while substitution is guaranteed to generate invariant projection, " +
|
||||
"but $descriptor substitution fails"
|
||||
}
|
||||
when (descriptor) {
|
||||
is Substitutable<*> -> descriptor.substitute(substitutor).sure {
|
||||
"We expect that no conflict should happen while substitution is guaranteed to generate invariant projection, " +
|
||||
"but $descriptor substitution fails"
|
||||
/*
|
||||
* Here we can take null if NI enabled, because inside this place we have OI and NI collide. See following example:
|
||||
*
|
||||
* class Out<out T>
|
||||
*
|
||||
* class A<T> {
|
||||
* fun T.foo() {}
|
||||
* fun Out<T>.bar() {}
|
||||
* }
|
||||
*
|
||||
* fun test(x: A<out CharSequence>, y: Out<CharSequence>) {
|
||||
* with(x) {
|
||||
* "".foo() <-- problem is here
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Because of we don't capture type projections, in call "".foo() we have `out CharSequence` as substituted type `T`
|
||||
* (instead of `CapturedType(out CharSequence)`, and `in String` as type from receiver, so we have type variance error
|
||||
* and can not substitute descriptor.
|
||||
*
|
||||
* So, fix of it is hack
|
||||
*/
|
||||
is FunctionDescriptorImpl -> {
|
||||
val substitutedDescriptor = descriptor.substitute(substitutor, substitutingScopeProvider)
|
||||
if (substitutingScopeProvider.isNewInferenceEnabled) {
|
||||
substitutedDescriptor ?: ErrorUtils.createErrorScope("Cannot substitute functional descriptor")
|
||||
.getContributedFunctions(descriptor.name, NoLookupLocation.WHEN_RESOLVE_DECLARATION).first()
|
||||
} else {
|
||||
substitutedDescriptor.sure(assertionMessage)
|
||||
}
|
||||
}
|
||||
|
||||
is Substitutable<*> -> descriptor.substitute(substitutor).sure(assertionMessage)
|
||||
else -> error("Unknown descriptor in scope: $descriptor")
|
||||
}
|
||||
}
|
||||
@@ -72,7 +111,7 @@ class SubstitutingScope(private val workerScope: MemberScope, givenSubstitutor:
|
||||
override fun getContributedVariables(name: Name, location: LookupLocation) = substitute(workerScope.getContributedVariables(name, location))
|
||||
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation) =
|
||||
workerScope.getContributedClassifier(name, location)?.let { substitute(it) }
|
||||
workerScope.getContributedClassifier(name, location)?.let { substitute(it) }
|
||||
|
||||
override fun getContributedFunctions(name: Name, location: LookupLocation) = substitute(workerScope.getContributedFunctions(name, location))
|
||||
|
||||
|
||||
@@ -28,6 +28,12 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import java.util.*
|
||||
|
||||
class OldCaptureTypeApproximator : CapturedTypeApproximator {
|
||||
override fun approximateCapturedTypes(typeProjection: TypeProjection?, approximateContravariant: Boolean): TypeProjection? {
|
||||
return approximateCapturedTypesIfNecessary(typeProjection, approximateContravariant)
|
||||
}
|
||||
}
|
||||
|
||||
data class ApproximationBounds<out T>(
|
||||
val lower: T,
|
||||
val upper: T
|
||||
|
||||
@@ -40,7 +40,7 @@ public class DescriptorSubstitutor {
|
||||
@NotNull DeclarationDescriptor newContainingDeclaration,
|
||||
@NotNull @Mutable List<TypeParameterDescriptor> result
|
||||
) {
|
||||
TypeSubstitutor substitutor = substituteTypeParameters(typeParameters, originalSubstitution, newContainingDeclaration, result, null);
|
||||
TypeSubstitutor substitutor = substituteTypeParameters(typeParameters, originalSubstitution, newContainingDeclaration, result, null, SubstitutingScopeProvider.Companion.getDEFAULT());
|
||||
if (substitutor == null) throw new AssertionError("Substitution failed");
|
||||
return substitutor;
|
||||
}
|
||||
@@ -51,7 +51,8 @@ public class DescriptorSubstitutor {
|
||||
@NotNull TypeSubstitution originalSubstitution,
|
||||
@NotNull DeclarationDescriptor newContainingDeclaration,
|
||||
@NotNull @Mutable List<TypeParameterDescriptor> result,
|
||||
@Nullable boolean[] wereChanges
|
||||
@Nullable boolean[] wereChanges,
|
||||
@NotNull SubstitutingScopeProvider substitutingScopeProvider
|
||||
) {
|
||||
Map<TypeConstructor, TypeProjection> mutableSubstitution = new HashMap<TypeConstructor, TypeProjection>();
|
||||
|
||||
@@ -76,7 +77,7 @@ public class DescriptorSubstitutor {
|
||||
|
||||
TypeSubstitutor substitutor = TypeSubstitutor.createChainedSubstitutor(
|
||||
originalSubstitution, TypeConstructorSubstitution.createByConstructorsMap(mutableSubstitution)
|
||||
);
|
||||
).setSubstitutingScopeProvider(substitutingScopeProvider);
|
||||
|
||||
for (TypeParameterDescriptor descriptor : typeParameters) {
|
||||
TypeParameterDescriptorImpl substituted = substitutedMap.get(descriptor);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.OldCapturedTypeCreator
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.SubstitutingScope
|
||||
import org.jetbrains.kotlin.types.typesApproximation.OldCaptureTypeApproximator
|
||||
|
||||
interface SubstitutingScopeProvider {
|
||||
fun createSubstitutingScope(workerScope: MemberScope, givenSubstitutor: TypeSubstitutor): SubstitutingScope
|
||||
|
||||
fun provideCapturedTypeCreator(): CapturedTypeCreator
|
||||
|
||||
fun provideApproximator(): CapturedTypeApproximator
|
||||
|
||||
val isNewInferenceEnabled: Boolean
|
||||
|
||||
companion object {
|
||||
val DEFAULT: SubstitutingScopeProvider = object : SubstitutingScopeProvider {
|
||||
override fun createSubstitutingScope(workerScope: MemberScope, givenSubstitutor: TypeSubstitutor): SubstitutingScope {
|
||||
return SubstitutingScope(workerScope, givenSubstitutor, this)
|
||||
}
|
||||
|
||||
override fun provideCapturedTypeCreator(): CapturedTypeCreator {
|
||||
return OldCapturedTypeCreator
|
||||
}
|
||||
|
||||
override fun provideApproximator(): CapturedTypeApproximator {
|
||||
return OldCaptureTypeApproximator()
|
||||
}
|
||||
|
||||
override val isNewInferenceEnabled: Boolean get() = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface CapturedTypeCreator {
|
||||
fun createCapturedType(typeProjection: TypeProjection): TypeProjection
|
||||
}
|
||||
|
||||
interface CapturedTypeApproximator {
|
||||
fun approximateCapturedTypes(typeProjection: TypeProjection?, approximateContravariant: Boolean): TypeProjection?
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.CapturedTypeConstructorKt;
|
||||
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker;
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||
import org.jetbrains.kotlin.types.typesApproximation.CapturedTypeApproximationKt;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -47,6 +46,14 @@ public class TypeSubstitutor implements TypeSubstitutorMarker {
|
||||
}
|
||||
}
|
||||
|
||||
private @NotNull SubstitutingScopeProvider substitutingScopeProvider;
|
||||
|
||||
@NotNull
|
||||
public TypeSubstitutor setSubstitutingScopeProvider(@NotNull SubstitutingScopeProvider substitutingScopeProvider) {
|
||||
this.substitutingScopeProvider = substitutingScopeProvider;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TypeSubstitutor create(@NotNull TypeSubstitution substitution) {
|
||||
return new TypeSubstitutor(substitution);
|
||||
@@ -73,6 +80,7 @@ public class TypeSubstitutor implements TypeSubstitutorMarker {
|
||||
|
||||
protected TypeSubstitutor(@NotNull TypeSubstitution substitution) {
|
||||
this.substitution = substitution;
|
||||
this.substitutingScopeProvider = SubstitutingScopeProvider.Companion.getDEFAULT();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
@@ -110,8 +118,12 @@ public class TypeSubstitutor implements TypeSubstitutorMarker {
|
||||
if (!substitution.approximateCapturedTypes() && !substitution.approximateContravariantCapturedTypes()) {
|
||||
return substitutedTypeProjection;
|
||||
}
|
||||
return CapturedTypeApproximationKt.approximateCapturedTypesIfNecessary(
|
||||
substitutedTypeProjection, substitution.approximateContravariantCapturedTypes());
|
||||
|
||||
CapturedTypeApproximator approximator = substitutingScopeProvider.provideApproximator();
|
||||
return approximator.approximateCapturedTypes(
|
||||
substitutedTypeProjection,
|
||||
substitution.approximateContravariantCapturedTypes()
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -55,6 +55,11 @@ public class TypeUtils {
|
||||
throw new IllegalStateException(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMarkedNullable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -521,6 +521,10 @@ internal fun UnwrappedType.typeDepthInternal() =
|
||||
internal fun SimpleType.typeDepthInternal(): Int {
|
||||
if (this is TypeUtils.SpecialType) return 0
|
||||
|
||||
if (this is NewCapturedType) {
|
||||
return constructor.projection.type.unwrap().typeDepthInternal()
|
||||
}
|
||||
|
||||
val maxInArguments = arguments.asSequence().map {
|
||||
if (it.isStarProjection) 1 else it.type.unwrap().typeDepthInternal()
|
||||
}.max() ?: 0
|
||||
|
||||
+2
-5
@@ -71,10 +71,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProvid
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.WrappedTypeFactory
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
|
||||
|
||||
@@ -333,7 +330,7 @@ internal object IDELightClassContexts {
|
||||
})
|
||||
|
||||
IdeaEnvironment.configure(this)
|
||||
|
||||
useImpl<SubstitutingScopeProviderImpl>()
|
||||
useImpl<ResolveSession>()
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil
|
||||
import org.jetbrains.kotlin.serialization.js.PackagesWithHeaderMetadata
|
||||
import org.jetbrains.kotlin.types.SubstitutingScopeProviderImpl
|
||||
|
||||
fun createTopDownAnalyzerForJs(
|
||||
moduleContext: ModuleContext,
|
||||
@@ -59,6 +60,7 @@ fun createTopDownAnalyzerForJs(
|
||||
useInstance(languageVersionSettings)
|
||||
useImpl<ResolveSession>()
|
||||
useImpl<LazyTopDownAnalyzer>()
|
||||
useImpl<SubstitutingScopeProviderImpl>()
|
||||
}.apply {
|
||||
val packagePartProviders = mutableListOf(get<KotlinCodeAnalyzer>().packageFragmentProvider)
|
||||
val moduleDescriptor = get<ModuleDescriptorImpl>()
|
||||
|
||||
Reference in New Issue
Block a user