[NI] Disable capturing/approximation type in TypeSubstitutor with enabled NI

This commit is contained in:
Dmitriy Novozhilov
2019-05-29 10:35:46 +03:00
parent dad334ffcd
commit 7c4101e21c
80 changed files with 890 additions and 201 deletions
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService
import org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragmentProvider import org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragmentProvider
import org.jetbrains.kotlin.serialization.deserialization.MetadataPartProvider import org.jetbrains.kotlin.serialization.deserialization.MetadataPartProvider
import org.jetbrains.kotlin.types.SubstitutingScopeProviderImpl
class CommonAnalysisParameters( class CommonAnalysisParameters(
val metadataPartProviderFactory: (ModuleContent<*>) -> MetadataPartProvider val metadataPartProviderFactory: (ModuleContent<*>) -> MetadataPartProvider
@@ -170,6 +171,7 @@ private fun createContainerToResolveCommonCode(
configureCommonSpecificComponents() configureCommonSpecificComponents()
useInstance(metadataPartProvider) useInstance(metadataPartProvider)
useImpl<SubstitutingScopeProviderImpl>()
val metadataFinderFactory = ServiceManager.getService( val metadataFinderFactory = ServiceManager.getService(
moduleContext.project, moduleContext.project,
@@ -8086,6 +8086,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt"); 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") @TestMetadata("commonSupertypeContravariant.kt")
public void testCommonSupertypeContravariant() throws Exception { public void testCommonSupertypeContravariant() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt"); 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"); 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") @TestMetadata("setterProjectedOutNoPlusAssign.kt")
public void testSetterProjectedOutNoPlusAssign() throws Exception { public void testSetterProjectedOutNoPlusAssign() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.kt"); runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.kt");
@@ -17373,6 +17383,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
runTest("compiler/testData/diagnostics/tests/resolve/HiddenDeclarations.kt"); 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") @TestMetadata("implicitReceiverProperty.kt")
public void testImplicitReceiverProperty() throws Exception { public void testImplicitReceiverProperty() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.kt"); runTest("compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.kt");
@@ -18090,6 +18105,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.kt"); 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") @TestMetadata("OverloadPriority.kt")
public void testOverloadPriority() throws Exception { public void testOverloadPriority() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/OverloadPriority.kt"); runTest("compiler/testData/diagnostics/tests/samConversions/OverloadPriority.kt");
@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.types.SubstitutingScopeProviderImpl
fun createContainerForLazyResolveWithJava( fun createContainerForLazyResolveWithJava(
jvmPlatform: TargetPlatform, jvmPlatform: TargetPlatform,
@@ -127,6 +128,7 @@ fun StorageComponentContainer.configureJavaSpecificComponents(
) )
useImpl<FilesByFacadeFqNameIndexer>() useImpl<FilesByFacadeFqNameIndexer>()
useImpl<SubstitutingScopeProviderImpl>()
} }
fun ComponentProvider.initJvmBuiltInsForTopDownAnalysis() { fun ComponentProvider.initJvmBuiltInsForTopDownAnalysis() {
@@ -81,8 +81,7 @@ public class LocalVariableDescriptor extends VariableDescriptorWithInitializerIm
@NotNull @NotNull
@Override @Override
public LocalVariableDescriptor substitute(@NotNull TypeSubstitutor substitutor) { public LocalVariableDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
if (substitutor.isEmpty()) return this; return this;
throw new UnsupportedOperationException(); // TODO
} }
@Override @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.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.SubstitutingScopeProvider
import org.jetbrains.kotlin.types.TypeConstructorSubstitution import org.jetbrains.kotlin.types.TypeConstructorSubstitution
import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny
@@ -77,7 +78,9 @@ fun ResolutionContext<*>.reportTypeMismatchDueToTypeProjection(
TypeConstructorSubstitution TypeConstructorSubstitution
.create(receiverType) .create(receiverType)
.wrapWithCapturingSubstitution(needApproximation = false) .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 val nonApproximatedExpectedType = correspondingNotApproximatedTypeByDescriptor(substitutedDescriptor) ?: return false
if (!TypeUtils.contains(nonApproximatedExpectedType) { it.isCaptured() }) return false if (!TypeUtils.contains(nonApproximatedExpectedType) { it.isCaptured() }) return false
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.resolve.calls.tower.KotlinResolutionStatelessCallbac
import org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker import org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker
import org.jetbrains.kotlin.resolve.lazy.* import org.jetbrains.kotlin.resolve.lazy.*
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.types.SubstitutingScopeProviderImpl
import org.jetbrains.kotlin.types.expressions.DeclarationScopeProviderForLocalClassifierAnalyzer import org.jetbrains.kotlin.types.expressions.DeclarationScopeProviderForLocalClassifierAnalyzer
import org.jetbrains.kotlin.types.expressions.LocalClassDescriptorHolder import org.jetbrains.kotlin.types.expressions.LocalClassDescriptorHolder
import org.jetbrains.kotlin.types.expressions.LocalLazyDeclarationResolver import org.jetbrains.kotlin.types.expressions.LocalLazyDeclarationResolver
@@ -117,6 +118,7 @@ fun createContainerForBodyResolve(
useImpl<AnnotationResolverImpl>() useImpl<AnnotationResolverImpl>()
useImpl<BodyResolver>() useImpl<BodyResolver>()
useImpl<SubstitutingScopeProviderImpl>()
} }
fun createContainerForLazyBodyResolve( fun createContainerForLazyBodyResolve(
@@ -136,6 +138,7 @@ fun createContainerForLazyBodyResolve(
useImpl<AnnotationResolverImpl>() useImpl<AnnotationResolverImpl>()
useImpl<LazyTopDownAnalyzer>() useImpl<LazyTopDownAnalyzer>()
useImpl<BasicAbsentDescriptorHandler>() useImpl<BasicAbsentDescriptorHandler>()
useImpl<SubstitutingScopeProviderImpl>()
} }
fun createContainerForLazyLocalClassifierAnalyzer( fun createContainerForLazyLocalClassifierAnalyzer(
@@ -166,6 +169,7 @@ fun createContainerForLazyLocalClassifierAnalyzer(
useImpl<DeclarationScopeProviderForLocalClassifierAnalyzer>() useImpl<DeclarationScopeProviderForLocalClassifierAnalyzer>()
useImpl<LocalLazyDeclarationResolver>() useImpl<LocalLazyDeclarationResolver>()
useImpl<SubstitutingScopeProviderImpl>()
useInstance(statementFilter) useInstance(statementFilter)
} }
@@ -183,6 +187,7 @@ fun createContainerForLazyResolve(
configureStandardResolveComponents() configureStandardResolveComponents()
useInstance(declarationProviderFactory) useInstance(declarationProviderFactory)
useImpl<SubstitutingScopeProviderImpl>()
targetEnvironment.configure(this) targetEnvironment.configure(this)
@@ -911,7 +911,8 @@ public class DescriptorResolver {
container instanceof ClassDescriptor && ((ClassDescriptor) container).isExpect(), container instanceof ClassDescriptor && ((ClassDescriptor) container).isExpect(),
modifierList != null && PsiUtilsKt.hasActualModifier(modifierList), modifierList != null && PsiUtilsKt.hasActualModifier(modifierList),
modifierList != null && modifierList.hasModifier(KtTokens.EXTERNAL_KEYWORD), modifierList != null && modifierList.hasModifier(KtTokens.EXTERNAL_KEYWORD),
propertyInfo.getHasDelegate() propertyInfo.getHasDelegate(),
new SubstitutingScopeProviderImpl(languageVersionSettings)
); );
List<TypeParameterDescriptorImpl> typeParameterDescriptors; List<TypeParameterDescriptorImpl> typeParameterDescriptors;
@@ -8,6 +8,8 @@ package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations 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.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.* 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.components.isVararg
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
import org.jetbrains.kotlin.resolve.calls.context.CallPosition 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.buildResultingSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor 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.components.NewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.inference.model.*
import org.jetbrains.kotlin.resolve.calls.inference.substitute 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.model.*
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.makeNullableTypeIfSafeReceiver import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.makeNullableTypeIfSafeReceiver
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus 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.calls.tasks.TracingStrategy
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor 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.constants.evaluate.ConstantExpressionEvaluator
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver 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.CastImplicitClassReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.types.* 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.DataFlowAnalyzer
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
@@ -293,15 +295,14 @@ class KotlinToResolvedCallTransformer(
// todo external argument // todo external argument
val argumentExpression = valueArgument.getArgumentExpression() ?: continue val argumentExpression = valueArgument.getArgumentExpression() ?: continue
updateRecordedType(argumentExpression, parameter, newContext, resolvedCall.isReallySuccess()) updateRecordedType(argumentExpression, parameter, newContext)
} }
} }
fun updateRecordedType( fun updateRecordedType(
expression: KtExpression, expression: KtExpression,
parameter: ValueParameterDescriptor?, parameter: ValueParameterDescriptor?,
context: BasicCallResolutionContext, context: BasicCallResolutionContext
reportErrorForTypeMismatch: Boolean
): KotlinType? { ): KotlinType? {
val deparenthesized = expression.let { val deparenthesized = expression.let {
KtPsiUtil.getLastElementDeparenthesized(it, context.statementFilter) KtPsiUtil.getLastElementDeparenthesized(it, context.statementFilter)
@@ -318,9 +319,6 @@ class KotlinToResolvedCallTransformer(
updatedType = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, deparenthesized) ?: updatedType updatedType = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, deparenthesized) ?: updatedType
} }
var reportErrorDuringTypeCheck = reportErrorForTypeMismatch
if (parameter != null && ImplicitIntegerCoercion.isEnabledForParameter(parameter)) { if (parameter != null && ImplicitIntegerCoercion.isEnabledForParameter(parameter)) {
val argumentCompileTimeValue = context.trace[BindingContext.COMPILE_TIME_VALUE, deparenthesized] val argumentCompileTimeValue = context.trace[BindingContext.COMPILE_TIME_VALUE, deparenthesized]
if (argumentCompileTimeValue != null && argumentCompileTimeValue.parameters.isConvertableConstVal) { if (argumentCompileTimeValue != null && argumentCompileTimeValue.parameters.isConvertableConstVal) {
@@ -329,7 +327,6 @@ class KotlinToResolvedCallTransformer(
updatedType = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable( updatedType = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable(
context.trace, context.statementFilter, context.expectedType, generalNumberType, expression context.trace, context.statementFilter, context.expectedType, generalNumberType, expression
) )
reportErrorDuringTypeCheck = true
} }
} }
@@ -337,7 +334,7 @@ class KotlinToResolvedCallTransformer(
updatedType = updateRecordedTypeForArgument(updatedType, recordedType, expression, context) updatedType = updateRecordedTypeForArgument(updatedType, recordedType, expression, context)
dataFlowAnalyzer.checkType(updatedType, deparenthesized, context, reportErrorDuringTypeCheck) dataFlowAnalyzer.checkType(updatedType, deparenthesized, context, false)
return updatedType return updatedType
} }
@@ -690,32 +687,44 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
resultingDescriptor = run { resultingDescriptor = run {
val candidateDescriptor = resolvedCallAtom.candidateDescriptor val candidateDescriptor = resolvedCallAtom.candidateDescriptor
val containsCapturedTypes = resolvedCallAtom.candidateDescriptor.returnType?.contains { it is NewCapturedType } ?: false val containsIntegerLiteralTypes = resolvedCallAtom.candidateDescriptor.returnType?.contains {
val containsIntegerLiteralTypes = resolvedCallAtom.candidateDescriptor.returnType?.contains { it.constructor is IntegerLiteralTypeConstructor } ?: false it.constructor is IntegerLiteralTypeConstructor
} ?: false
when { when {
candidateDescriptor is FunctionDescriptor || 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, // 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. // but it seems like temporary solution.
candidateDescriptor.substitute(resolvedCallAtom.substitutor).substituteAndApproximateCapturedTypes( candidateDescriptor.substituteAndApproximateIntegerLiteralTypes(resolvedCallAtom.substitutor).let {
substitutor ?: FreshVariableNewTypeSubstitutor.Empty if (substitutor != null) {
) it.substitute(substitutor)
} else {
it
}
}
else -> else ->
candidateDescriptor candidateDescriptor
} }
} as D } as D
typeArguments = resolvedCallAtom.substitutor.freshVariables.map { typeArguments = resolvedCallAtom.substitutor.freshVariables.map {
val substituted = (substitutor ?: FreshVariableNewTypeSubstitutor.Empty).safeSubstitute(it.defaultType) (substitutor ?: FreshVariableNewTypeSubstitutor.Empty).safeSubstitute(it.defaultType)
TypeApproximator(substituted.constructor.builtIns)
.approximateToSuperType(substituted, TypeApproximatorConfiguration.IntegerLiteralsTypesApproximation)
?: substituted
} }
calculateExpectedTypeForSamConvertedArgumentMap(substitutor) 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? = fun getExpectedTypeForSamConvertedArgument(valueArgument: ValueArgument): UnwrappedType? =
expedtedTypeForSamConvertedArgumentMap?.get(valueArgument) expedtedTypeForSamConvertedArgumentMap?.get(valueArgument)
@@ -808,3 +817,41 @@ fun NewResolvedCallImpl<*>.hasInferredReturnType(): Boolean {
val returnType = this.resultingDescriptor.returnType ?: return false val returnType = this.resultingDescriptor.returnType ?: return false
return !returnType.contains { ErrorUtils.isUninferredParameter(it) } 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) { return cache.getOrPut(implicitReceiver) {
context.transformToReceiverWithSmartCastInfo(implicitReceiver.value) context.transformToReceiverWithSmartCastInfo(implicitReceiver.value)
.prepareReceiverRegardingCaptureTypes()
} }
} }
} }
@@ -110,6 +110,7 @@ class ResolvedAtomCompleter(
kotlinToResolvedCallTransformer.reportDiagnostics(topLevelCallContext, topLevelTrace, resolvedCall, diagnostics) kotlinToResolvedCallTransformer.reportDiagnostics(topLevelCallContext, topLevelTrace, resolvedCall, diagnostics)
resolvedCall.approximateCapturedTypesAndHackSetters()
return resolvedCall return resolvedCall
} }
@@ -155,9 +156,7 @@ class ResolvedAtomCompleter(
.replaceBindingTrace(topLevelTrace) .replaceBindingTrace(topLevelTrace)
val argumentExpression = resultValueArgument.valueArgument.getArgumentExpression() ?: continue val argumentExpression = resultValueArgument.valueArgument.getArgumentExpression() ?: continue
kotlinToResolvedCallTransformer.updateRecordedType( kotlinToResolvedCallTransformer.updateRecordedType(argumentExpression, parameter = null, context = newContext)
argumentExpression, parameter = null, context = newContext, reportErrorForTypeMismatch = true
)
} }
} }
@@ -24,10 +24,12 @@ import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.SubstitutingScopeProvider
import org.jetbrains.kotlin.types.WrappedTypeFactory import org.jetbrains.kotlin.types.WrappedTypeFactory
interface LazyClassContext { interface LazyClassContext {
val declarationScopeProvider: DeclarationScopeProvider val declarationScopeProvider: DeclarationScopeProvider
val substitutingScopeProvider: SubstitutingScopeProvider
val storageManager: StorageManager val storageManager: StorageManager
val trace: BindingTrace 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.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.MemberScope; import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.storage.*; import org.jetbrains.kotlin.storage.*;
import org.jetbrains.kotlin.types.SubstitutingScopeProvider;
import org.jetbrains.kotlin.types.WrappedTypeFactory; import org.jetbrains.kotlin.types.WrappedTypeFactory;
import org.jetbrains.kotlin.utils.SmartList; import org.jetbrains.kotlin.utils.SmartList;
@@ -81,6 +82,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
private DelegationFilter delegationFilter; private DelegationFilter delegationFilter;
private WrappedTypeFactory wrappedTypeFactory; private WrappedTypeFactory wrappedTypeFactory;
private PlatformDiagnosticSuppressor platformDiagnosticSuppressor; private PlatformDiagnosticSuppressor platformDiagnosticSuppressor;
private SubstitutingScopeProvider substitutingScopeProvider;
private final SyntheticResolveExtension syntheticResolveExtension; private final SyntheticResolveExtension syntheticResolveExtension;
@@ -146,6 +148,17 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
this.platformDiagnosticSuppressor = platformDiagnosticSuppressor; this.platformDiagnosticSuppressor = platformDiagnosticSuppressor;
} }
@NotNull
@Override
public SubstitutingScopeProvider getSubstitutingScopeProvider() {
return substitutingScopeProvider;
}
@Inject
public void setSubstitutingScopeProvider(SubstitutingScopeProvider substitutingScopeProvider) {
this.substitutingScopeProvider = substitutingScopeProvider;
}
// Only calls from injectors expected // Only calls from injectors expected
@Deprecated @Deprecated
public ResolveSession( public ResolveSession(
@@ -113,7 +113,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
) { ) {
super(c.getStorageManager(), containingDeclaration, name, super(c.getStorageManager(), containingDeclaration, name,
KotlinSourceElementKt.toSourceElement(classLikeInfo.getCorrespondingClassOrObject()), KotlinSourceElementKt.toSourceElement(classLikeInfo.getCorrespondingClassOrObject()),
isExternal isExternal, c.getSubstitutingScopeProvider()
); );
this.c = c; 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
}
}
@@ -958,6 +958,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
boolean result = true; boolean result = true;
KtExpression reportOn = expression != null ? expression : expressionWithParenthesis; KtExpression reportOn = expression != null ? expression : expressionWithParenthesis;
KtExpression originalReportOn = reportOn;
if (reportOn instanceof KtQualifiedExpression) { if (reportOn instanceof KtQualifiedExpression) {
KtExpression selector = ((KtQualifiedExpression) reportOn).getSelectorExpression(); KtExpression selector = ((KtQualifiedExpression) reportOn).getSelectorExpression();
if (selector != null) if (selector != null)
@@ -968,14 +969,19 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) variable; PropertyDescriptor propertyDescriptor = (PropertyDescriptor) variable;
PropertySetterDescriptor setter = propertyDescriptor.getSetter(); PropertySetterDescriptor setter = propertyDescriptor.getSetter();
if (propertyDescriptor.isSetterProjectedOut()) { if (propertyDescriptor.isSetterProjectedOut()) {
trace.report(SETTER_PROJECTED_OUT.on(reportOn, propertyDescriptor)); trace.report(SETTER_PROJECTED_OUT.on(originalReportOn, propertyDescriptor));
result = false; result = false;
} }
else if (setter != null) { else if (setter != null) {
ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(expressionWithParenthesis, context.trace.getBindingContext()); ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(expressionWithParenthesis, context.trace.getBindingContext());
assert resolvedCall != null assert resolvedCall != null
: "Call is not resolved for property setter: " + PsiUtilsKt.getElementTextWithContext(expressionWithParenthesis); : "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);
}
} }
} }
@@ -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.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.SubstitutingScopeProvider
import org.jetbrains.kotlin.types.WrappedTypeFactory import org.jetbrains.kotlin.types.WrappedTypeFactory
class LocalClassifierAnalyzer( class LocalClassifierAnalyzer(
@@ -65,7 +66,8 @@ class LocalClassifierAnalyzer(
private val supertypeLoopChecker: SupertypeLoopChecker, private val supertypeLoopChecker: SupertypeLoopChecker,
private val languageVersionSettings: LanguageVersionSettings, private val languageVersionSettings: LanguageVersionSettings,
private val delegationFilter: DelegationFilter, private val delegationFilter: DelegationFilter,
private val wrappedTypeFactory: WrappedTypeFactory private val wrappedTypeFactory: WrappedTypeFactory,
private val substitutingScopeProvider: SubstitutingScopeProvider
) { ) {
fun processClassOrObject( fun processClassOrObject(
scope: LexicalWritableScope?, scope: LexicalWritableScope?,
@@ -98,7 +100,8 @@ class LocalClassifierAnalyzer(
languageVersionSettings, languageVersionSettings,
SyntheticResolveExtension.getInstance(project), SyntheticResolveExtension.getInstance(project),
delegationFilter, delegationFilter,
wrappedTypeFactory wrappedTypeFactory,
substitutingScopeProvider
), ),
analyzerServices analyzerServices
) )
@@ -126,7 +129,8 @@ class LocalClassDescriptorHolder(
val languageVersionSettings: LanguageVersionSettings, val languageVersionSettings: LanguageVersionSettings,
val syntheticResolveExtension: SyntheticResolveExtension, val syntheticResolveExtension: SyntheticResolveExtension,
val delegationFilter: DelegationFilter, 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 // We do not need to synchronize here, because this code is used strictly from one thread
private var classDescriptor: ClassDescriptor? = null private var classDescriptor: ClassDescriptor? = null
@@ -166,6 +170,7 @@ class LocalClassDescriptorHolder(
override val syntheticResolveExtension = this@LocalClassDescriptorHolder.syntheticResolveExtension override val syntheticResolveExtension = this@LocalClassDescriptorHolder.syntheticResolveExtension
override val delegationFilter: DelegationFilter = this@LocalClassDescriptorHolder.delegationFilter override val delegationFilter: DelegationFilter = this@LocalClassDescriptorHolder.delegationFilter
override val wrappedTypeFactory: WrappedTypeFactory = this@LocalClassDescriptorHolder.wrappedTypeFactory override val wrappedTypeFactory: WrappedTypeFactory = this@LocalClassDescriptorHolder.wrappedTypeFactory
override val substitutingScopeProvider: SubstitutingScopeProvider = this@LocalClassDescriptorHolder.substitutingScopeProvider
}, },
containingDeclaration, containingDeclaration,
classOrObject.nameAsSafeName, classOrObject.nameAsSafeName,
@@ -60,6 +60,20 @@ val CallableDescriptor.returnTypeOrNothing: UnwrappedType
fun TypeSubstitutor.substitute(type: UnwrappedType): UnwrappedType = safeSubstitute(type, Variance.INVARIANT).unwrap() 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 { fun CallableDescriptor.substitute(substitutor: NewTypeSubstitutor): CallableDescriptor {
val wrappedSubstitution = object : TypeSubstitution() { val wrappedSubstitution = object : TypeSubstitution() {
override fun get(key: KotlinType): TypeProjection? = null override fun get(key: KotlinType): TypeProjection? = null
@@ -68,18 +82,25 @@ fun CallableDescriptor.substitute(substitutor: NewTypeSubstitutor): CallableDesc
return substitute(TypeSubstitutor.create(wrappedSubstitution)) 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() { val wrappedSubstitution = object : TypeSubstitution() {
override fun get(key: KotlinType): TypeProjection? = null override fun get(key: KotlinType): TypeProjection? = null
override fun prepareTopLevelType(topLevelType: KotlinType, position: Variance) = override fun prepareTopLevelType(topLevelType: KotlinType, position: Variance): KotlinType {
substitutor.safeSubstitute(topLevelType.unwrap()).let { substitutedType -> val type = topLevelType.unwrap()
TypeApproximator(builtIns).approximateToSuperType(substitutedType, TypeApproximatorConfiguration.CapturedAndIntegerLiteralsTypesApproximation) val approximatedType =
?: substitutedType 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.config.LanguageVersionSettings
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextForCS 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.TypeApproximatorConfiguration.IntersectionStrategy.*
import org.jetbrains.kotlin.types.checker.NewCapturedType
import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor
import org.jetbrains.kotlin.types.model.* import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.types.model.CaptureStatus.* import org.jetbrains.kotlin.types.model.CaptureStatus.*
import org.jetbrains.kotlin.types.typeUtil.builtIns
open class TypeApproximatorConfiguration { open class TypeApproximatorConfiguration {
@@ -424,6 +420,8 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon
if (argument.isStarProjection()) continue if (argument.isStarProjection()) continue
val argumentType = argument.getType()//.unwrap() val argumentType = argument.getType()//.unwrap()
val argumentTypeIsNullable = argumentType.asSimpleType()?.isMarkedNullable() ?: false
val effectiveVariance = AbstractTypeChecker.effectiveVariance(parameter.getVariance(), argument.getVariance()) val effectiveVariance = AbstractTypeChecker.effectiveVariance(parameter.getVariance(), argument.getVariance())
when (effectiveVariance) { when (effectiveVariance) {
null -> { null -> {
@@ -487,7 +485,7 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon
*/ */
if (argumentType.typeConstructor() is NewCapturedTypeConstructor) { if (argumentType.typeConstructor() is NewCapturedTypeConstructor) {
val subType = approximateToSubType(argumentType, conf, depth) ?: continue@loop val subType = approximateToSubType(argumentType, conf, depth) ?: continue@loop
if (!subType.isTrivialSub()) { if (!subType.isTrivialSub(argumentTypeIsNullable)) {
newArguments[index] = createTypeArgument(subType, TypeVariance.IN) newArguments[index] = createTypeArgument(subType, TypeVariance.IN)
continue@loop continue@loop
} }
@@ -498,7 +496,7 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon
if (approximatedSuperType.isTrivialSuper()) { if (approximatedSuperType.isTrivialSuper()) {
val approximatedSubType = val approximatedSubType =
approximateToSubType(argumentType, conf, depth) ?: continue@loop // seems like this is never null 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) newArguments[index] = createTypeArgument(approximatedSubType, TypeVariance.IN)
continue@loop continue@loop
} }
@@ -527,7 +525,12 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon
private fun KotlinTypeMarker.isTrivialSuper() = upperBoundIfFlexible().isNullableAny() private fun KotlinTypeMarker.isTrivialSuper() = upperBoundIfFlexible().isNullableAny()
// Nothing or Nothing! // 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() = //internal fun KotlinTypeMarker.typeDepth() =
@@ -1,4 +1,6 @@
// FILE: test/GenericSam.java // FILE: test/GenericSam.java
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
package test; package test;
@@ -16,7 +18,7 @@ fun f3() = java.lang.Runnable::class
fun f4() = java.lang.Runnable::run fun f4() = java.lang.Runnable::run
fun f5() = GenericSam::class 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 f7() = test.GenericSam::class
fun f8() = test.GenericSam<String>::invoke 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
}
}
@@ -37,5 +37,5 @@ annotation class AnnArray(val a: Array<String>)
@AnnArray(<!OI;NON_VARARG_SPREAD!>*<!>["/"]) @AnnArray(<!OI;NON_VARARG_SPREAD!>*<!>["/"])
fun testArray() {} 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() {} fun testVararg() {}
@@ -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<!>) val bbbb = ( l() <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>) ?: ( l() <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>)
fun f(x : Long?): Long { 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<!> return <!OI;DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>a<!>
} }
@@ -108,7 +108,7 @@ fun testImplicitCoercion() {
val <!UNUSED_VARIABLE!>h<!> = if (false) <!IMPLICIT_CAST_TO_ANY!>4<!> else <!IMPLICIT_CAST_TO_ANY!>{}<!> val <!UNUSED_VARIABLE!>h<!> = if (false) <!IMPLICIT_CAST_TO_ANY!>4<!> else <!IMPLICIT_CAST_TO_ANY!>{}<!>
bar(<!NI;TYPE_MISMATCH!>if (true) { bar(<!NI;TYPE_MISMATCH!>if (true) {
<!CONSTANT_EXPECTED_TYPE_MISMATCH, NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>4<!> <!OI;CONSTANT_EXPECTED_TYPE_MISMATCH!>4<!>
} }
else { else {
<!UNUSED_VALUE!>z =<!> 342 <!UNUSED_VALUE!>z =<!> 342
@@ -26,7 +26,7 @@ fun test1() {
<!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!UNUSED_ANONYMOUS_PARAMETER!>x<!>, <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_ANONYMOUS_PARAMETER!>y<!><!> -> "" <!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!UNUSED_ANONYMOUS_PARAMETER!>x<!>, <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_ANONYMOUS_PARAMETER!>y<!><!> -> ""
}<!> }<!>
foo1 <!NI;TYPE_MISMATCH!>{ 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<!> -> "" <!EXPECTED_PARAMETERS_NUMBER_MISMATCH, UNUSED_ANONYMOUS_PARAMETER!>x<!> -> ""
}<!> }<!>
foo2 <!NI;TYPE_MISMATCH!>{ 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<!>
}<!> }<!>
} }
@@ -1,10 +1,10 @@
// !WITH_NEW_INFERENCE // !WITH_NEW_INFERENCE
fun test(a: Int) { fun test(a: Int) {
run<Int>f@{ run<Int>f@{
if (a > 0) return@f <!NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!> if (a > 0) return@f <!TYPE_MISMATCH!>""<!>
return@f 1 return@f 1
} }
run<Int>{ <!NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!> } run<Int>{ <!TYPE_MISMATCH!>""<!> }
run<Int>{ 1 } 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
}
@@ -20,7 +20,7 @@ class Outer<E> {
} }
if (y is Outer<*>.Inner<*>) { if (y is Outer<*>.Inner<*>) {
<!DEBUG_INFO_SMARTCAST!>y<!>.prop.checkType { _<Any?>() } <!OI;DEBUG_INFO_SMARTCAST!>y<!>.prop.checkType { _<Any?>() }
} }
} }
@@ -9,7 +9,7 @@ fun foo(x: Any?, y: C<*>) {
y.<!OI;MEMBER_PROJECTED_OUT!>bindTo<!>(<!NI;TYPE_MISMATCH!>""<!>) y.<!OI;MEMBER_PROJECTED_OUT!>bindTo<!>(<!NI;TYPE_MISMATCH!>""<!>)
if (x is C<*>) { 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<!>) { with(<!DEBUG_INFO_SMARTCAST!>x<!>) {
<!OI;MEMBER_PROJECTED_OUT!>bindTo<!>(<!NI;TYPE_MISMATCH!>""<!>) <!OI;MEMBER_PROJECTED_OUT!>bindTo<!>(<!NI;TYPE_MISMATCH!>""<!>)
} }
@@ -17,7 +17,7 @@ fun foo(x: Any?, y: C<*>) {
with(x) { with(x) {
if (this is C<*>) { 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!>""<!>)
} }
} }
} }
@@ -5,5 +5,6 @@ interface A<T : A<T?>?> {
fun foo(): T? fun foo(): T?
} }
fun testA(a: A<*>) { 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<*>?>() }
} }
@@ -14,14 +14,14 @@ class A<E> {
fun test(a: A<out CharSequence>, z: Out<CharSequence>) { fun test(a: A<out CharSequence>, z: Out<CharSequence>) {
a.foo { a.foo {
val x: String = <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!> // Should be no TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS 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 { Out() }
a.bar { <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>z.id()<!> } a.bar { <!NI;TYPE_MISMATCH, TYPE_MISMATCH!>z.id()<!> }
a.foo { a.foo {
z.foobar(if (1 > 2) return@foo <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!> else "") z.foobar(if (1 > 2) return@foo <!TYPE_MISMATCH!>""<!> else "")
<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!> <!NI;TYPE_MISMATCH, TYPE_MISMATCH!>""<!>
} }
} }
@@ -14,14 +14,14 @@ class A<T> {
fun foo2(a: A<out CharSequence>, b: A<in CharSequence>) { fun foo2(a: A<out CharSequence>, b: A<in CharSequence>) {
a.<!OI;TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>foo1<!>(<!NI;TYPE_MISMATCH!>Out<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())
a.foo1(Out<Nothing>()) 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.<!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())
a.foo3(In<CharSequence>()) 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>())
b.foo1<Out<CharSequence>>(Out()) 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.<!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.<!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<Any?>())
b.foo3(In()) 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<*>) { fun main(a: A<*>, j: JavaClass<*>, i2: Inv2<*>) {
// Probably it's too restrictive to suppose star projection type here as Any?, // Probably it's too restrictive to suppose star projection type here as Any?,
// but looks like we can refine it later // but looks like we can refine it later
a.foo() checkType { _<Any?>() } a.foo() checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
j.foo() checkType { _<Any?>() } j.foo() checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
i2.x checkType { _<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()<!>) j.bar(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!>, <!NI;TYPE_MISMATCH, OI;TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS!>Any()<!>)
@@ -5,6 +5,6 @@ interface Tr<T> {
} }
fun test(t: Tr<*>) { fun test(t: Tr<*>) {
<!SETTER_PROJECTED_OUT!>t.v<!> = t <!SETTER_PROJECTED_OUT!>t.v<!> = <!NI;TYPE_MISMATCH!>t<!>
t.v checkType { _<Tr<*>>() } t.v checkType { _<Tr<*>>() }
} }
@@ -7,8 +7,9 @@ interface Tr<T> {
} }
fun test(t: Tr<*>) { fun test(t: Tr<*>) {
t.v = null!! <!NI;SETTER_PROJECTED_OUT!>t.v<!> = null!!
<!SETTER_PROJECTED_OUT!>t.v<!> = "" <!SETTER_PROJECTED_OUT!>t.v<!> = <!NI;TYPE_MISMATCH!>""<!>
<!SETTER_PROJECTED_OUT!>t.v<!> = null <!SETTER_PROJECTED_OUT!>t.v<!> = <!NI;NULL_FOR_NONNULL_TYPE!>null<!>
t.v checkType { _<Any?>() } t.v checkType { _<Any?>() }
} }
@@ -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!>""<!>
}
@@ -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
}
@@ -7,5 +7,5 @@ interface Tr<T> {
fun test(t: Tr<out String>) { fun test(t: Tr<out String>) {
// resolved as t.v = t.v + null!!, where type of right operand is 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) // 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!!<!>
} }
@@ -5,15 +5,15 @@
fun <T: Any> bar(a: Array<T>): Array<T?> = null!! fun <T: Any> bar(a: Array<T>): Array<T?> = null!!
fun test1(a: Array<out Int>) { fun test1(a: Array<out Int>) {
val r: Array<out Int?> = <!NI;TYPE_MISMATCH!><!NI;UNSUPPORTED!>bar<!>(a)<!> val r: Array<out Int?> = bar(a)
val t = <!NI;UNSUPPORTED!>bar<!>(a) val t = bar(a)
<!NI;UNSUPPORTED!>t<!> checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Array<out Int?>>() } t checkType { _<Array<out Int?>>() }
} }
fun <T: Any> foo(l: Array<T>): Array<Array<T?>> = null!! fun <T: Any> foo(l: Array<T>): Array<Array<T?>> = null!!
fun test2(a: Array<out Int>) { fun test2(a: Array<out Int>) {
val r: Array<out Array<out Int?>> = <!NI;TYPE_MISMATCH!><!NI;UNSUPPORTED!>foo<!>(a)<!> val r: Array<out Array<out Int?>> = foo(a)
val t = <!NI;UNSUPPORTED!>foo<!>(a) val t = foo(a)
<!NI;UNSUPPORTED!>t<!> checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Array<out Array<out Int?>>>() } t checkType { _<Array<out Array<out Int?>>>() }
} }
@@ -16,5 +16,5 @@ fun <S> test1(a: ParameterizedChild<S>?, b: Child): Base<S> = myRun {
} }
fun <S> test2(a: S?, b: S): 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() { fun foo() {
val l: Foo<String> = object : Foo<String> {} 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() { fun main() {
J <!NI;TYPE_MISMATCH!>{ <!EXPECTED_PARAMETER_TYPE_MISMATCH!>s: String<!> -> s}<!> // should be prohibited, because SAM value parameter has nullable type 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 { "" + it<!UNSAFE_CALL!>.<!>length }
J { <!NI;NULL_FOR_NONNULL_TYPE, NI;NULL_FOR_NONNULL_TYPE, NULL_FOR_NONNULL_TYPE!>null<!> } J { <!NI;NULL_FOR_NONNULL_TYPE, NULL_FOR_NONNULL_TYPE!>null<!> }
J { <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>it?.length?.toString()<!> } J { <!NI;TYPE_MISMATCH, TYPE_MISMATCH!>it?.length?.toString()<!> }
J2 <!NI;TYPE_MISMATCH!>{ <!EXPECTED_PARAMETER_TYPE_MISMATCH!>s: String<!> -> s}<!> J2 <!NI;TYPE_MISMATCH!>{ <!EXPECTED_PARAMETER_TYPE_MISMATCH!>s: String<!> -> s}<!>
J2 { "" + it<!UNSAFE_CALL!>.<!>length } J2 { "" + it<!UNSAFE_CALL!>.<!>length }
J2 { <!NI;NULL_FOR_NONNULL_TYPE, NI;NULL_FOR_NONNULL_TYPE, NULL_FOR_NONNULL_TYPE!>null<!> } J2 { <!NI;NULL_FOR_NONNULL_TYPE, NULL_FOR_NONNULL_TYPE!>null<!> }
J2 { <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, TYPE_MISMATCH!>it?.length?.toString()<!> } J2 { <!NI;TYPE_MISMATCH, TYPE_MISMATCH!>it?.length?.toString()<!> }
} }
@@ -34,7 +34,7 @@ fun main() {
} }
A.baz { 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? = { val block: (String) -> Any? = {
+1 -1
View File
@@ -14,5 +14,5 @@ class Owner<in T> {
fun getT() = u fun getT() = u
} }
fun foo(arg: Inner<*>) = arg.getT() <!NI;TYPE_VARIANCE_CONFLICT!>fun foo(arg: Inner<*>)<!> = arg.getT()
} }
+2 -2
View File
@@ -3,7 +3,7 @@ package
public final class Owner</*0*/ in T> { public final class Owner</*0*/ in T> {
public constructor 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 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 hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String 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 interface Super</*0*/ out U> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean 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 hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
} }
@@ -29,9 +29,9 @@ class WithMod {
<!FORBIDDEN_BINARY_MOD!>operator<!> fun mod(other: WithMod) = this <!FORBIDDEN_BINARY_MOD!>operator<!> fun mod(other: WithMod) = this
fun test() { 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) 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 var a = 1 % 2
a <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE!>%=<!> 3 a <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE!>%=<!> 3
1.mod(2) 1.mod(2)
b % <!NI;TYPE_MISMATCH!>s<!> b % s
1.0 % <!NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>2.0<!> 1.0 % 2.0
} }
@@ -29,9 +29,9 @@ class WithMod {
<!DEPRECATED_BINARY_MOD!>operator<!> fun mod(other: WithMod) = this <!DEPRECATED_BINARY_MOD!>operator<!> fun mod(other: WithMod) = this
fun test() { 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) 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 var a = 1 % 2
a <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE!>%=<!> 3 a <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE!>%=<!> 3
1.mod(2) 1.mod(2)
b % <!NI;TYPE_MISMATCH!>s<!> b % s
1.0 % <!NI;CONSTANT_EXPECTED_TYPE_MISMATCH!>2.0<!> 1.0 % 2.0
} }
@@ -11,9 +11,13 @@ public class A {
// FILE: k.kt // FILE: k.kt
fun test() { 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.bar<String?>(<!NULL_FOR_NONNULL_TYPE!>null<!>, "") A.bar<String?>(<!OI;NULL_FOR_NONNULL_TYPE!>null<!>, "")
A.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>bar<!>(<!NULL_FOR_NONNULL_TYPE!>null<!>, A.platformString()) 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<!>, "")
} }
@@ -2,7 +2,7 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER // !DIAGNOSTICS: -UNUSED_PARAMETER
fun test(a: Int, b: Boolean) { 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() 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
}
@@ -8,7 +8,7 @@ fun test() {
<!OI;CONSTANT_EXPECTED_TYPE_MISMATCH!>2<!> <!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 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<*, *>) { 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<!>.r().checkType { _<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<!>.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
} }
@@ -21,21 +21,21 @@ fun test2() {}
@Ann(s = <!NI;TYPE_MISMATCH, OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>arrayOf(1)<!>) @Ann(s = <!NI;TYPE_MISMATCH, OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>arrayOf(1)<!>)
fun test3() {} 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() {} fun test5() {}
@JavaAnn(value = <!NI;TYPE_MISMATCH, OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>arrayOf("value")<!>) @JavaAnn(value = <!NI;TYPE_MISMATCH, OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>arrayOf("value")<!>)
fun jTest1() {} 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() {} 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() {} fun jTest3() {}
annotation class IntAnn(vararg val i: Int) 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() {} fun foo1() {}
@IntAnn(i = <!TYPE_MISMATCH!>intArrayOf(0)<!>) @IntAnn(i = <!TYPE_MISMATCH!>intArrayOf(0)<!>)
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices
import org.jetbrains.kotlin.types.SubstitutingScopeProviderImpl
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.types.expressions.FakeCallResolver import org.jetbrains.kotlin.types.expressions.FakeCallResolver
@@ -40,6 +41,7 @@ fun createContainerForTests(project: Project, module: ModuleDescriptor): Contain
BindingTraceContext(), BindingTraceContext(),
LanguageVersionSettingsImpl.DEFAULT LanguageVersionSettingsImpl.DEFAULT
) )
useImpl<SubstitutingScopeProviderImpl>()
useImpl<AnnotationResolverImpl>() useImpl<AnnotationResolverImpl>()
}) })
} }
@@ -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_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<!>.y<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!><!DEBUG_INFO_SMARTCAST!>x<!>.z<!> <!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("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<!> <!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 // TESTCASE NUMBER: 1
fun Any.case_1() { fun Any.case_1() {
if (this is Inv<*>) { if (this is Inv<*>) {
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<*>"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any"), DEBUG_INFO_SMARTCAST!>this<!>.test() <!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<*>"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any"), DEBUG_INFO_SMARTCAST!>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<!>
<!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_EXPRESSION_TYPE("Inv<*> & kotlin.Any"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>this<!>.prop_4<!>.inv()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int"), DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>prop_4<!> <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>prop_4<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int"), DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>prop_4<!>.inv() <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>prop_4<!>.inv()
} }
} }
// TESTCASE NUMBER: 2 // TESTCASE NUMBER: 2
fun Any.case_2() { fun Any.case_2() {
if (this is ClassWithSixTypeParameters<*, *, *, *, *, *>) { 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<!>.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_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<!> <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?"), DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>x<!>
@@ -36,18 +36,18 @@ fun Any.case_2() {
// TESTCASE NUMBER: 3 // TESTCASE NUMBER: 3
fun <T> T.case_3() { fun <T> T.case_3() {
if (this is Inv<*>) { if (this is Inv<*>) {
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<*>"), DEBUG_INFO_EXPRESSION_TYPE("T"), DEBUG_INFO_SMARTCAST!>this<!>.test() <!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<*>"), DEBUG_INFO_EXPRESSION_TYPE("T"), DEBUG_INFO_SMARTCAST!>this<!>.prop_4<!> <!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<*>"), DEBUG_INFO_EXPRESSION_TYPE("T"), DEBUG_INFO_SMARTCAST!>this<!>.prop_4<!>.inv() <!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"), DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>prop_4<!> <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>prop_4<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int"), DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>prop_4<!>.inv() <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>prop_4<!>.inv()
} }
} }
// TESTCASE NUMBER: 4 // TESTCASE NUMBER: 4
fun <T> T?.case_4() { fun <T> T?.case_4() {
if (this is ClassWithSixTypeParameters<*, *, *, *, *, *>) { 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<!>.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_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<!> <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?"), DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>x<!>
@@ -36,26 +36,26 @@ fun case_2(a: Out<<!REDUNDANT_PROJECTION!>out<!> Out<<!REDUNDANT_PROJECTION!>out
if (a != null) { if (a != null) {
val b = <!DEBUG_INFO_EXPRESSION_TYPE("Out<out Out<out Out<out Out<out Out<out Out<out kotlin.Int?>?>?>?>?>?> & Out<out Out<out Out<out Out<out Out<out Out<out kotlin.Int?>?>?>?>?>?>?")!>a<!>.get() val b = <!DEBUG_INFO_EXPRESSION_TYPE("Out<out Out<out Out<out Out<out Out<out Out<out kotlin.Int?>?>?>?>?>?> & Out<out Out<out Out<out Out<out Out<out Out<out kotlin.Int?>?>?>?>?>?>?")!>a<!>.get()
if (b != null) { if (b != null) {
val c = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<Out<Out<Out<kotlin.Int?>?>?>?>?> & Out<Out<Out<Out<Out<kotlin.Int?>?>?>?>?>?"), DEBUG_INFO_SMARTCAST!>b<!>.get() val c = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<Out<Out<Out<kotlin.Any?>?>?>?>?> & Out<Out<Out<Out<Out<kotlin.Any?>?>?>?>?>?"), DEBUG_INFO_SMARTCAST!>b<!>.get()
if (c != null) { if (c != null) {
val d = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<Out<Out<kotlin.Int?>?>?>?> & Out<Out<Out<Out<kotlin.Int?>?>?>?>?"), DEBUG_INFO_SMARTCAST!>c<!>.get() val d = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<Out<Out<kotlin.Any?>?>?>?> & Out<Out<Out<Out<kotlin.Any?>?>?>?>?"), DEBUG_INFO_SMARTCAST!>c<!>.get()
if (d != null) { if (d != null) {
val e = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<Out<kotlin.Int?>?>?> & Out<Out<Out<kotlin.Int?>?>?>?"), DEBUG_INFO_SMARTCAST!>d<!>.get() val e = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<Out<kotlin.Any?>?>?> & Out<Out<Out<kotlin.Any?>?>?>?"), DEBUG_INFO_SMARTCAST!>d<!>.get()
if (e != null) { if (e != null) {
val f = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<kotlin.Int?>?> & Out<Out<kotlin.Int?>?>?"), DEBUG_INFO_SMARTCAST!>e<!>.get() val f = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<kotlin.Any?>?> & Out<Out<kotlin.Any?>?>?"), DEBUG_INFO_SMARTCAST!>e<!>.get()
if (f != null) { if (f != null) {
val g = <!DEBUG_INFO_EXPRESSION_TYPE("Out<kotlin.Int?> & Out<kotlin.Int?>?"), DEBUG_INFO_SMARTCAST!>f<!>.get() val g = <!DEBUG_INFO_EXPRESSION_TYPE("Out<kotlin.Any?> & Out<kotlin.Any?>?"), DEBUG_INFO_SMARTCAST!>f<!>.get()
if (g != null) { if (g != null) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?")!>g<!> <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?")!>g<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?"), DEBUG_INFO_SMARTCAST!>g<!>.equals(null) <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>g<!>.equals(null)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?"), DEBUG_INFO_SMARTCAST!>g<!>.propT <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>g<!>.propT
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?"), DEBUG_INFO_SMARTCAST!>g<!>.propAny <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>g<!>.propAny
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?")!>g<!>.propNullableT <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?")!>g<!>.propNullableT
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?")!>g<!>.propNullableAny <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?")!>g<!>.propNullableAny
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?"), DEBUG_INFO_SMARTCAST!>g<!>.funT() <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>g<!>.funT()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?"), DEBUG_INFO_SMARTCAST!>g<!>.funAny() <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>g<!>.funAny()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?")!>g<!>.funNullableT() <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?")!>g<!>.funNullableT()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?")!>g<!>.funNullableAny() <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?")!>g<!>.funNullableAny()
} }
} }
} }
@@ -392,26 +392,26 @@ fun case_17(a: Inv<out Out<Out<Out<Out<Out<Int?>?>?>?>?>?>?) {
if (a != null) { if (a != null) {
val b = <!DEBUG_INFO_EXPRESSION_TYPE("Inv<out Out<Out<Out<Out<Out<kotlin.Int?>?>?>?>?>?> & Inv<out Out<Out<Out<Out<Out<kotlin.Int?>?>?>?>?>?>?")!>a<!>.get() val b = <!DEBUG_INFO_EXPRESSION_TYPE("Inv<out Out<Out<Out<Out<Out<kotlin.Int?>?>?>?>?>?> & Inv<out Out<Out<Out<Out<Out<kotlin.Int?>?>?>?>?>?>?")!>a<!>.get()
if (b != null) { if (b != null) {
val c = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<Out<Out<Out<kotlin.Int?>?>?>?>?> & Out<Out<Out<Out<Out<kotlin.Int?>?>?>?>?>?"), DEBUG_INFO_SMARTCAST!>b<!>.get() val c = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<Out<Out<Out<kotlin.Any?>?>?>?>?> & Out<Out<Out<Out<Out<kotlin.Any?>?>?>?>?>?"), DEBUG_INFO_SMARTCAST!>b<!>.get()
if (c != null) { if (c != null) {
val d = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<Out<Out<kotlin.Int?>?>?>?> & Out<Out<Out<Out<kotlin.Int?>?>?>?>?"), DEBUG_INFO_SMARTCAST!>c<!>.get() val d = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<Out<Out<kotlin.Any?>?>?>?> & Out<Out<Out<Out<kotlin.Any?>?>?>?>?"), DEBUG_INFO_SMARTCAST!>c<!>.get()
if (d != null) { if (d != null) {
val e = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<Out<kotlin.Int?>?>?> & Out<Out<Out<kotlin.Int?>?>?>?"), DEBUG_INFO_SMARTCAST!>d<!>.get() val e = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<Out<kotlin.Any?>?>?> & Out<Out<Out<kotlin.Any?>?>?>?"), DEBUG_INFO_SMARTCAST!>d<!>.get()
if (e != null) { if (e != null) {
val f = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<kotlin.Int?>?> & Out<Out<kotlin.Int?>?>?"), DEBUG_INFO_SMARTCAST!>e<!>.get() val f = <!DEBUG_INFO_EXPRESSION_TYPE("Out<Out<kotlin.Any?>?> & Out<Out<kotlin.Any?>?>?"), DEBUG_INFO_SMARTCAST!>e<!>.get()
if (f != null) { if (f != null) {
val g = <!DEBUG_INFO_EXPRESSION_TYPE("Out<kotlin.Int?> & Out<kotlin.Int?>?"), DEBUG_INFO_SMARTCAST!>f<!>.get() val g = <!DEBUG_INFO_EXPRESSION_TYPE("Out<kotlin.Any?> & Out<kotlin.Any?>?"), DEBUG_INFO_SMARTCAST!>f<!>.get()
if (g != null) { if (g != null) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?")!>g<!> <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?")!>g<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?"), DEBUG_INFO_SMARTCAST!>g<!>.equals(null) <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>g<!>.equals(null)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?"), DEBUG_INFO_SMARTCAST!>g<!>.propT <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>g<!>.propT
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?"), DEBUG_INFO_SMARTCAST!>g<!>.propAny <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>g<!>.propAny
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?")!>g<!>.propNullableT <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?")!>g<!>.propNullableT
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?")!>g<!>.propNullableAny <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?")!>g<!>.propNullableAny
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?"), DEBUG_INFO_SMARTCAST!>g<!>.funT() <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>g<!>.funT()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?"), DEBUG_INFO_SMARTCAST!>g<!>.funAny() <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>g<!>.funAny()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?")!>g<!>.funNullableT() <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?")!>g<!>.funNullableT()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?")!>g<!>.funNullableAny() <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?")!>g<!>.funNullableAny()
} }
} }
} }
@@ -8093,6 +8093,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt"); 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") @TestMetadata("commonSupertypeContravariant.kt")
public void testCommonSupertypeContravariant() throws Exception { public void testCommonSupertypeContravariant() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt"); 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"); 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") @TestMetadata("setterProjectedOutNoPlusAssign.kt")
public void testSetterProjectedOutNoPlusAssign() throws Exception { public void testSetterProjectedOutNoPlusAssign() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.kt"); runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.kt");
@@ -17385,6 +17395,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/resolve/HiddenDeclarations.kt"); 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") @TestMetadata("implicitReceiverProperty.kt")
public void testImplicitReceiverProperty() throws Exception { public void testImplicitReceiverProperty() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.kt"); runTest("compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.kt");
@@ -18102,6 +18117,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.kt"); 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") @TestMetadata("OverloadPriority.kt")
public void testOverloadPriority() throws Exception { public void testOverloadPriority() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/OverloadPriority.kt"); runTest("compiler/testData/diagnostics/tests/samConversions/OverloadPriority.kt");
@@ -8088,6 +8088,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt"); 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") @TestMetadata("commonSupertypeContravariant.kt")
public void testCommonSupertypeContravariant() throws Exception { public void testCommonSupertypeContravariant() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt"); 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"); 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") @TestMetadata("setterProjectedOutNoPlusAssign.kt")
public void testSetterProjectedOutNoPlusAssign() throws Exception { public void testSetterProjectedOutNoPlusAssign() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.kt"); runTest("compiler/testData/diagnostics/tests/generics/varProjection/setterProjectedOutNoPlusAssign.kt");
@@ -17375,6 +17385,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/resolve/HiddenDeclarations.kt"); 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") @TestMetadata("implicitReceiverProperty.kt")
public void testImplicitReceiverProperty() throws Exception { public void testImplicitReceiverProperty() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.kt"); runTest("compiler/testData/diagnostics/tests/resolve/implicitReceiverProperty.kt");
@@ -18092,6 +18107,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.kt"); 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") @TestMetadata("OverloadPriority.kt")
public void testOverloadPriority() throws Exception { public void testOverloadPriority() throws Exception {
runTest("compiler/testData/diagnostics/tests/samConversions/OverloadPriority.kt"); 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.load.kotlin.PackagePartProvider
import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.SubstitutingScopeProvider
import java.util.* import java.util.*
class JavaResolverComponents( class JavaResolverComponents(
@@ -64,7 +65,8 @@ class JavaResolverComponents(
val annotationTypeQualifierResolver: AnnotationTypeQualifierResolver, val annotationTypeQualifierResolver: AnnotationTypeQualifierResolver,
val signatureEnhancement: SignatureEnhancement, val signatureEnhancement: SignatureEnhancement,
val javaClassesTracker: JavaClassesTracker, val javaClassesTracker: JavaClassesTracker,
val settings: JavaResolverSettings val settings: JavaResolverSettings,
val substitutingScopeProvider: SubstitutingScopeProvider
) { ) {
fun replace( fun replace(
javaResolverCache: JavaResolverCache = this.javaResolverCache javaResolverCache: JavaResolverCache = this.javaResolverCache
@@ -73,7 +75,7 @@ class JavaResolverComponents(
signaturePropagator, errorReporter, javaResolverCache, signaturePropagator, errorReporter, javaResolverCache,
javaPropertyInitializerEvaluator, samConversionResolver, sourceElementFactory, javaPropertyInitializerEvaluator, samConversionResolver, sourceElementFactory,
moduleClassResolver, packagePartProvider, supertypeLoopChecker, lookupTracker, module, reflectionTypes, moduleClassResolver, packagePartProvider, supertypeLoopChecker, lookupTracker, module, reflectionTypes,
annotationTypeQualifierResolver, signatureEnhancement, javaClassesTracker, settings annotationTypeQualifierResolver, signatureEnhancement, javaClassesTracker, settings, substitutingScopeProvider
) )
} }
@@ -46,7 +46,8 @@ class LazyJavaClassDescriptor(
) : ClassDescriptorBase( ) : ClassDescriptorBase(
outerContext.storageManager, containingDeclaration, jClass.name, outerContext.storageManager, containingDeclaration, jClass.name,
outerContext.components.sourceElementFactory.source(jClass), outerContext.components.sourceElementFactory.source(jClass),
/* isExternal = */ false /* isExternal = */ false,
outerContext.components.substitutingScopeProvider
), JavaClassDescriptor { ), JavaClassDescriptor {
companion object { companion object {
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.serialization.deserialization.ContractDeserializer
import org.jetbrains.kotlin.serialization.deserialization.DeserializationComponents import org.jetbrains.kotlin.serialization.deserialization.DeserializationComponents
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.SubstitutingScopeProvider
import org.jetbrains.kotlin.utils.Jsr305State import org.jetbrains.kotlin.utils.Jsr305State
class RuntimeModuleData private constructor( class RuntimeModuleData private constructor(
@@ -70,7 +71,7 @@ class RuntimeModuleData private constructor(
singleModuleClassResolver, PackagePartProvider.Empty, SupertypeLoopChecker.EMPTY, LookupTracker.DO_NOTHING, module, singleModuleClassResolver, PackagePartProvider.Empty, SupertypeLoopChecker.EMPTY, LookupTracker.DO_NOTHING, module,
ReflectionTypes(module, notFoundClasses), annotationTypeQualifierResolver, ReflectionTypes(module, notFoundClasses), annotationTypeQualifierResolver,
SignatureEnhancement(annotationTypeQualifierResolver, Jsr305State.DISABLED), SignatureEnhancement(annotationTypeQualifierResolver, Jsr305State.DISABLED),
JavaClassesTracker.Default, JavaResolverSettings.Default JavaClassesTracker.Default, JavaResolverSettings.Default, SubstitutingScopeProvider.DEFAULT
) )
val lazyJavaPackageFragmentProvider = LazyJavaPackageFragmentProvider(javaResolverComponents) val lazyJavaPackageFragmentProvider = LazyJavaPackageFragmentProvider(javaResolverComponents)
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor;
import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.scopes.InnerClassesScopeWrapper; import org.jetbrains.kotlin.resolve.scopes.InnerClassesScopeWrapper;
import org.jetbrains.kotlin.resolve.scopes.MemberScope; 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.NotNullLazyValue;
import org.jetbrains.kotlin.storage.StorageManager; import org.jetbrains.kotlin.storage.StorageManager;
import org.jetbrains.kotlin.types.*; import org.jetbrains.kotlin.types.*;
@@ -34,10 +33,11 @@ import java.util.List;
public abstract class AbstractClassDescriptor implements ClassDescriptor { public abstract class AbstractClassDescriptor implements ClassDescriptor {
private final Name name; private final Name name;
protected final NotNullLazyValue<SimpleType> defaultType; protected final NotNullLazyValue<SimpleType> defaultType;
protected final SubstitutingScopeProvider substitutingScopeProvider;
private final NotNullLazyValue<MemberScope> unsubstitutedInnerClassesScope; private final NotNullLazyValue<MemberScope> unsubstitutedInnerClassesScope;
private final NotNullLazyValue<ReceiverParameterDescriptor> thisAsReceiverParameter; 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.name = name;
this.defaultType = storageManager.createLazyValue(new Function0<SimpleType>() { this.defaultType = storageManager.createLazyValue(new Function0<SimpleType>() {
@Override @Override
@@ -57,6 +57,11 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
return new LazyClassReceiverParameterDescriptor(AbstractClassDescriptor.this); return new LazyClassReceiverParameterDescriptor(AbstractClassDescriptor.this);
} }
}); });
this.substitutingScopeProvider = substitutingScopeProvider;
}
public AbstractClassDescriptor(@NotNull StorageManager storageManager, @NotNull Name name) {
this(storageManager, name, SubstitutingScopeProvider.Companion.getDEFAULT());
} }
@NotNull @NotNull
@@ -92,7 +97,7 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
if (typeArguments.isEmpty()) return getUnsubstitutedMemberScope(); if (typeArguments.isEmpty()) return getUnsubstitutedMemberScope();
TypeSubstitutor substitutor = TypeConstructorSubstitution.create(getTypeConstructor(), typeArguments).buildSubstitutor(); TypeSubstitutor substitutor = TypeConstructorSubstitution.create(getTypeConstructor(), typeArguments).buildSubstitutor();
return new SubstitutingScope(getUnsubstitutedMemberScope(), substitutor); return substitutingScopeProvider.createSubstitutingScope(getUnsubstitutedMemberScope(), substitutor);
} }
@NotNull @NotNull
@@ -101,7 +106,7 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
if (typeSubstitution.isEmpty()) return getUnsubstitutedMemberScope(); if (typeSubstitution.isEmpty()) return getUnsubstitutedMemberScope();
TypeSubstitutor substitutor = TypeSubstitutor.create(typeSubstitution); TypeSubstitutor substitutor = TypeSubstitutor.create(typeSubstitution);
return new SubstitutingScope(getUnsubstitutedMemberScope(), substitutor); return substitutingScopeProvider.createSubstitutingScope(getUnsubstitutedMemberScope(), substitutor);
} }
@NotNull @NotNull
@@ -110,7 +115,7 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
if (substitutor.isEmpty()) { if (substitutor.isEmpty()) {
return this; return this;
} }
return new LazySubstitutingClassDescriptor(this, substitutor); return new LazySubstitutingClassDescriptor(this, substitutor, substitutingScopeProvider);
} }
@NotNull @NotNull
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.SourceElement; import org.jetbrains.kotlin.descriptors.SourceElement;
import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.storage.StorageManager; import org.jetbrains.kotlin.storage.StorageManager;
import org.jetbrains.kotlin.types.SubstitutingScopeProvider;
public abstract class ClassDescriptorBase extends AbstractClassDescriptor { public abstract class ClassDescriptorBase extends AbstractClassDescriptor {
@@ -35,7 +36,18 @@ public abstract class ClassDescriptorBase extends AbstractClassDescriptor {
@NotNull SourceElement source, @NotNull SourceElement source,
boolean isExternal 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.containingDeclaration = containingDeclaration;
this.source = source; this.source = source;
this.isExternal = isExternal; this.isExternal = isExternal;
@@ -324,11 +324,21 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
} }
@Override @Override
@Nullable
public FunctionDescriptor substitute(@NotNull TypeSubstitutor originalSubstitutor) { public FunctionDescriptor substitute(@NotNull TypeSubstitutor originalSubstitutor) {
return substitute(originalSubstitutor, SubstitutingScopeProvider.Companion.getDEFAULT());
}
@Nullable
public FunctionDescriptor substitute(@NotNull TypeSubstitutor originalSubstitutor, SubstitutingScopeProvider substitutingScopeProvider) {
if (originalSubstitutor.isEmpty()) { if (originalSubstitutor.isEmpty()) {
return this; return this;
} }
return newCopyBuilder(originalSubstitutor).setOriginal(getOriginal()).setJustForTypeSubstitution(true).build(); return newCopyBuilder(originalSubstitutor)
.setOriginal(getOriginal())
.setJustForTypeSubstitution(true)
.setSubstitutingScopeProvider(substitutingScopeProvider)
.build();
} }
@Nullable @Nullable
@@ -365,6 +375,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
private Map<UserDataKey<?>, Object> userDataMap = new LinkedHashMap<UserDataKey<?>, Object>(); private Map<UserDataKey<?>, Object> userDataMap = new LinkedHashMap<UserDataKey<?>, Object>();
private Boolean newHasSynthesizedParameterNames = null; private Boolean newHasSynthesizedParameterNames = null;
protected boolean justForTypeSubstitution = false; protected boolean justForTypeSubstitution = false;
protected @NotNull SubstitutingScopeProvider substitutingScopeProvider;
public CopyConfiguration( public CopyConfiguration(
@NotNull TypeSubstitution substitution, @NotNull TypeSubstitution substitution,
@@ -386,6 +397,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
this.newExtensionReceiverParameter = newExtensionReceiverParameter; this.newExtensionReceiverParameter = newExtensionReceiverParameter;
this.newReturnType = newReturnType; this.newReturnType = newReturnType;
this.name = name; this.name = name;
substitutingScopeProvider = SubstitutingScopeProvider.Companion.getDEFAULT();
} }
@Override @Override
@@ -554,6 +566,12 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
justForTypeSubstitution = value; justForTypeSubstitution = value;
return this; return this;
} }
@NotNull
public CopyConfiguration setSubstitutingScopeProvider(@NotNull SubstitutingScopeProvider substitutingScopeProvider) {
this.substitutingScopeProvider = substitutingScopeProvider;
return this;
}
} }
@Override @Override
@@ -591,7 +609,8 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
List<TypeParameterDescriptor> substitutedTypeParameters = List<TypeParameterDescriptor> substitutedTypeParameters =
new ArrayList<TypeParameterDescriptor>(unsubstitutedTypeParameters.size()); new ArrayList<TypeParameterDescriptor>(unsubstitutedTypeParameters.size());
final TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters( final TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(
unsubstitutedTypeParameters, configuration.substitution, substitutedDescriptor, substitutedTypeParameters, wereChanges unsubstitutedTypeParameters, configuration.substitution, substitutedDescriptor, substitutedTypeParameters,
wereChanges, configuration.substitutingScopeProvider
); );
if (substitutor == null) return null; if (substitutor == null) return null;
@@ -28,10 +28,12 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
private List<TypeParameterDescriptor> typeConstructorParameters; private List<TypeParameterDescriptor> typeConstructorParameters;
private List<TypeParameterDescriptor> declaredTypeParameters; private List<TypeParameterDescriptor> declaredTypeParameters;
private TypeConstructor typeConstructor; 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.original = descriptor;
this.originalSubstitutor = substitutor; this.originalSubstitutor = substitutor;
this.substitutingScopeProvider = substitutingScopeProvider;
} }
private TypeSubstitutor getSubstitutor() { private TypeSubstitutor getSubstitutor() {
@@ -87,7 +89,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
if (originalSubstitutor.isEmpty()) { if (originalSubstitutor.isEmpty()) {
return memberScope; return memberScope;
} }
return new SubstitutingScope(memberScope, getSubstitutor()); return substitutingScopeProvider.createSubstitutingScope(memberScope, getSubstitutor());
} }
@NotNull @NotNull
@@ -97,7 +99,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
if (originalSubstitutor.isEmpty()) { if (originalSubstitutor.isEmpty()) {
return memberScope; return memberScope;
} }
return new SubstitutingScope(memberScope, getSubstitutor()); return substitutingScopeProvider.createSubstitutingScope(memberScope, getSubstitutor());
} }
@NotNull @NotNull
@@ -107,7 +109,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
if (originalSubstitutor.isEmpty()) { if (originalSubstitutor.isEmpty()) {
return memberScope; return memberScope;
} }
return new SubstitutingScope(memberScope, getSubstitutor()); return substitutingScopeProvider.createSubstitutingScope(memberScope, getSubstitutor());
} }
@NotNull @NotNull
@@ -175,7 +177,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
@Override @Override
public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) { public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
if (substitutor.isEmpty()) return this; 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 @Override
@@ -47,6 +47,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
private final boolean isExternal; private final boolean isExternal;
private final boolean isDelegated; private final boolean isDelegated;
private final SubstitutingScopeProvider substitutingScopeProvider;
private ReceiverParameterDescriptor dispatchReceiverParameter; private ReceiverParameterDescriptor dispatchReceiverParameter;
private ReceiverParameterDescriptor extensionReceiverParameter; private ReceiverParameterDescriptor extensionReceiverParameter;
private List<TypeParameterDescriptor> typeParameters; private List<TypeParameterDescriptor> typeParameters;
@@ -72,6 +74,28 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
boolean isActual, boolean isActual,
boolean isExternal, boolean isExternal,
boolean isDelegated 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); super(containingDeclaration, annotations, name, null, isVar, source);
this.modality = modality; this.modality = modality;
@@ -84,6 +108,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
this.isActual = isActual; this.isActual = isActual;
this.isExternal = isExternal; this.isExternal = isExternal;
this.isDelegated = isDelegated; this.isDelegated = isDelegated;
this.substitutingScopeProvider = substitutingScopeProvider;
} }
@NotNull @NotNull
@@ -102,10 +127,39 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
boolean isActual, boolean isActual,
boolean isExternal, boolean isExternal,
boolean isDelegated 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, return new PropertyDescriptorImpl(containingDeclaration, null, annotations,
modality, visibility, isVar, name, kind, source, lateInit, isConst, 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( public void setType(
@@ -258,6 +312,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
private ReceiverParameterDescriptor dispatchReceiverParameter = PropertyDescriptorImpl.this.dispatchReceiverParameter; private ReceiverParameterDescriptor dispatchReceiverParameter = PropertyDescriptorImpl.this.dispatchReceiverParameter;
private List<TypeParameterDescriptor> newTypeParameters = null; private List<TypeParameterDescriptor> newTypeParameters = null;
private Name name = getName(); private Name name = getName();
private boolean setterProjectedOut = PropertyDescriptorImpl.this.setterProjectedOut;
@NotNull @NotNull
@Override @Override
@@ -364,6 +419,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters( TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(
originalTypeParameters, copyConfiguration.substitution, substitutedDescriptor, substitutedTypeParameters originalTypeParameters, copyConfiguration.substitution, substitutedDescriptor, substitutedTypeParameters
); );
substitutor.setSubstitutingScopeProvider(substitutingScopeProvider);
KotlinType originalOutType = getType(); KotlinType originalOutType = getType();
KotlinType outType = substitutor.substitute(originalOutType, Variance.OUT_VARIANCE); KotlinType outType = substitutor.substitute(originalOutType, Variance.OUT_VARIANCE);
@@ -460,6 +516,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
substitutedDescriptor.setCompileTimeInitializer(compileTimeInitializer); substitutedDescriptor.setCompileTimeInitializer(compileTimeInitializer);
} }
substitutedDescriptor.setterProjectedOut = copyConfiguration.setterProjectedOut;
return substitutedDescriptor; return substitutedDescriptor;
} }
@@ -470,7 +528,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
return prev; return prev;
} }
private static FunctionDescriptor getSubstitutedInitialSignatureDescriptor( public static FunctionDescriptor getSubstitutedInitialSignatureDescriptor(
@NotNull TypeSubstitutor substitutor, @NotNull TypeSubstitutor substitutor,
@NotNull PropertyAccessorDescriptor accessorDescriptor @NotNull PropertyAccessorDescriptor accessorDescriptor
) { ) {
@@ -490,7 +548,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
) { ) {
return new PropertyDescriptorImpl( return new PropertyDescriptorImpl(
newOwner, original, getAnnotations(), newModality, newVisibility, isVar(), newName, kind, SourceElement.NO_SOURCE, 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) { public <V> V getUserData(UserDataKey<V> key) {
return null; return null;
} }
@NotNull
public SubstitutingScopeProvider getSubstitutingScopeProvider() {
return substitutingScopeProvider;
}
} }
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeSubstitutor import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.utils.join import org.jetbrains.kotlin.utils.join
open class ValueParameterDescriptorImpl( open class ValueParameterDescriptorImpl(
@@ -102,8 +103,7 @@ open class ValueParameterDescriptorImpl(
override fun getOriginal() = if (original === this) this else original.original override fun getOriginal() = if (original === this) this else original.original
override fun substitute(substitutor: TypeSubstitutor): ValueParameterDescriptor { override fun substitute(substitutor: TypeSubstitutor): ValueParameterDescriptor {
if (substitutor.isEmpty) return this return this
throw UnsupportedOperationException() // TODO
} }
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R { override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R {
@@ -100,16 +100,25 @@ class CapturedType(
CapturedType(typeProjection, constructor, isMarkedNullable, newAnnotations) 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 createCapturedType(typeProjection: TypeProjection): KotlinType = CapturedType(typeProjection)
fun KotlinType.isCaptured(): Boolean = constructor is CapturedTypeConstructor 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) if (this is IndexedParametersSubstitution)
IndexedParametersSubstitution( IndexedParametersSubstitution(
this.parameters, this.parameters,
this.arguments.zip(this.parameters).map { this.arguments.zip(this.parameters).map {
it.first.createCapturedIfNeeded(it.second) it.first.createCapturedIfNeeded(it.second, capturedTypeCreator)
}.toTypedArray(), }.toTypedArray(),
approximateCapturedTypes = needApproximation approximateCapturedTypes = needApproximation
) )
@@ -117,10 +126,16 @@ fun TypeSubstitution.wrapWithCapturingSubstitution(needApproximation: Boolean =
object : DelegatedTypeSubstitution(this@wrapWithCapturingSubstitution) { object : DelegatedTypeSubstitution(this@wrapWithCapturingSubstitution) {
override fun approximateContravariantCapturedTypes() = needApproximation override fun approximateContravariantCapturedTypes() = needApproximation
override fun get(key: KotlinType) = 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 if (typeParameterDescriptor == null || projectionKind == Variance.INVARIANT) return this
// Treat consistent projections as invariant // Treat consistent projections as invariant
@@ -134,5 +149,5 @@ private fun TypeProjection.createCapturedIfNeeded(typeParameterDescriptor: TypeP
TypeProjectionImpl(this@createCapturedIfNeeded.type) 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.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.Substitutable 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.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.calls.inference.wrapWithCapturingSubstitution 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.types.TypeSubstitutor
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.newLinkedHashSetWithExpectedSize import org.jetbrains.kotlin.utils.newLinkedHashSetWithExpectedSize
import org.jetbrains.kotlin.utils.sure import org.jetbrains.kotlin.utils.sure
import java.util.* 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 private var substitutedDescriptors: MutableMap<DeclarationDescriptor, DeclarationDescriptor>? = null
@@ -43,11 +49,44 @@ class SubstitutingScope(private val workerScope: MemberScope, givenSubstitutor:
} }
val substituted = substitutedDescriptors!!.getOrPut(descriptor) { 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) { when (descriptor) {
is Substitutable<*> -> descriptor.substitute(substitutor).sure { /*
"We expect that no conflict should happen while substitution is guaranteed to generate invariant projection, " + * Here we can take null if NI enabled, because inside this place we have OI and NI collide. See following example:
"but $descriptor substitution fails" *
* 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") 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 getContributedVariables(name: Name, location: LookupLocation) = substitute(workerScope.getContributedVariables(name, location))
override fun getContributedClassifier(name: Name, location: LookupLocation) = 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)) 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 org.jetbrains.kotlin.types.typeUtil.builtIns
import java.util.* import java.util.*
class OldCaptureTypeApproximator : CapturedTypeApproximator {
override fun approximateCapturedTypes(typeProjection: TypeProjection?, approximateContravariant: Boolean): TypeProjection? {
return approximateCapturedTypesIfNecessary(typeProjection, approximateContravariant)
}
}
data class ApproximationBounds<out T>( data class ApproximationBounds<out T>(
val lower: T, val lower: T,
val upper: T val upper: T
@@ -40,7 +40,7 @@ public class DescriptorSubstitutor {
@NotNull DeclarationDescriptor newContainingDeclaration, @NotNull DeclarationDescriptor newContainingDeclaration,
@NotNull @Mutable List<TypeParameterDescriptor> result @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"); if (substitutor == null) throw new AssertionError("Substitution failed");
return substitutor; return substitutor;
} }
@@ -51,7 +51,8 @@ public class DescriptorSubstitutor {
@NotNull TypeSubstitution originalSubstitution, @NotNull TypeSubstitution originalSubstitution,
@NotNull DeclarationDescriptor newContainingDeclaration, @NotNull DeclarationDescriptor newContainingDeclaration,
@NotNull @Mutable List<TypeParameterDescriptor> result, @NotNull @Mutable List<TypeParameterDescriptor> result,
@Nullable boolean[] wereChanges @Nullable boolean[] wereChanges,
@NotNull SubstitutingScopeProvider substitutingScopeProvider
) { ) {
Map<TypeConstructor, TypeProjection> mutableSubstitution = new HashMap<TypeConstructor, TypeProjection>(); Map<TypeConstructor, TypeProjection> mutableSubstitution = new HashMap<TypeConstructor, TypeProjection>();
@@ -76,7 +77,7 @@ public class DescriptorSubstitutor {
TypeSubstitutor substitutor = TypeSubstitutor.createChainedSubstitutor( TypeSubstitutor substitutor = TypeSubstitutor.createChainedSubstitutor(
originalSubstitution, TypeConstructorSubstitution.createByConstructorsMap(mutableSubstitution) originalSubstitution, TypeConstructorSubstitution.createByConstructorsMap(mutableSubstitution)
); ).setSubstitutingScopeProvider(substitutingScopeProvider);
for (TypeParameterDescriptor descriptor : typeParameters) { for (TypeParameterDescriptor descriptor : typeParameters) {
TypeParameterDescriptorImpl substituted = substitutedMap.get(descriptor); 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.resolve.calls.inference.CapturedTypeConstructorKt;
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker; import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker;
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt; import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
import org.jetbrains.kotlin.types.typesApproximation.CapturedTypeApproximationKt;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt; import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import java.util.ArrayList; 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 @NotNull
public static TypeSubstitutor create(@NotNull TypeSubstitution substitution) { public static TypeSubstitutor create(@NotNull TypeSubstitution substitution) {
return new TypeSubstitutor(substitution); return new TypeSubstitutor(substitution);
@@ -73,6 +80,7 @@ public class TypeSubstitutor implements TypeSubstitutorMarker {
protected TypeSubstitutor(@NotNull TypeSubstitution substitution) { protected TypeSubstitutor(@NotNull TypeSubstitution substitution) {
this.substitution = substitution; this.substitution = substitution;
this.substitutingScopeProvider = SubstitutingScopeProvider.Companion.getDEFAULT();
} }
public boolean isEmpty() { public boolean isEmpty() {
@@ -110,8 +118,12 @@ public class TypeSubstitutor implements TypeSubstitutorMarker {
if (!substitution.approximateCapturedTypes() && !substitution.approximateContravariantCapturedTypes()) { if (!substitution.approximateCapturedTypes() && !substitution.approximateContravariantCapturedTypes()) {
return substitutedTypeProjection; return substitutedTypeProjection;
} }
return CapturedTypeApproximationKt.approximateCapturedTypesIfNecessary(
substitutedTypeProjection, substitution.approximateContravariantCapturedTypes()); CapturedTypeApproximator approximator = substitutingScopeProvider.provideApproximator();
return approximator.approximateCapturedTypes(
substitutedTypeProjection,
substitution.approximateContravariantCapturedTypes()
);
} }
@Nullable @Nullable
@@ -55,6 +55,11 @@ public class TypeUtils {
throw new IllegalStateException(name); throw new IllegalStateException(name);
} }
@Override
public boolean isMarkedNullable() {
return false;
}
@NotNull @NotNull
@Override @Override
public String toString() { public String toString() {
@@ -72,10 +72,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProvid
import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.WrappedTypeFactory
import org.jetbrains.kotlin.utils.sure import org.jetbrains.kotlin.utils.sure
@@ -334,7 +331,7 @@ internal object IDELightClassContexts {
}) })
IdeaEnvironment.configure(this) IdeaEnvironment.configure(this)
useImpl<SubstitutingScopeProviderImpl>()
useImpl<ResolveSession>() useImpl<ResolveSession>()
} }
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.platform.js.JsPlatforms
import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.types.SubstitutingScopeProviderImpl
fun createTopDownAnalyzerForJs( fun createTopDownAnalyzerForJs(
moduleContext: ModuleContext, moduleContext: ModuleContext,
@@ -55,6 +56,7 @@ fun createTopDownAnalyzerForJs(
configureIncrementalCompilation(lookupTracker, expectActualTracker) configureIncrementalCompilation(lookupTracker, expectActualTracker)
configureStandardResolveComponents() configureStandardResolveComponents()
useImpl<SubstitutingScopeProviderImpl>()
useInstance(declarationProviderFactory) useInstance(declarationProviderFactory)
CompilerEnvironment.configure(this) CompilerEnvironment.configure(this)