diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java index 07563d930c3..e23338b921d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java @@ -55,7 +55,6 @@ import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE; public class ArgumentTypeResolver { @NotNull private final TypeResolver typeResolver; - @NotNull private final DoubleColonExpressionResolver doubleColonExpressionResolver; @NotNull private final KotlinBuiltIns builtIns; @NotNull private final ReflectionTypes reflectionTypes; @NotNull private final ConstantExpressionEvaluator constantExpressionEvaluator; @@ -63,10 +62,10 @@ public class ArgumentTypeResolver { @NotNull private final ModuleDescriptor moduleDescriptor; private ExpressionTypingServices expressionTypingServices; + private DoubleColonExpressionResolver doubleColonExpressionResolver; public ArgumentTypeResolver( @NotNull TypeResolver typeResolver, - @NotNull DoubleColonExpressionResolver doubleColonExpressionResolver, @NotNull KotlinBuiltIns builtIns, @NotNull ReflectionTypes reflectionTypes, @NotNull ConstantExpressionEvaluator constantExpressionEvaluator, @@ -74,7 +73,6 @@ public class ArgumentTypeResolver { @NotNull ModuleDescriptor moduleDescriptor ) { this.typeResolver = typeResolver; - this.doubleColonExpressionResolver = doubleColonExpressionResolver; this.builtIns = builtIns; this.reflectionTypes = reflectionTypes; this.constantExpressionEvaluator = constantExpressionEvaluator; @@ -88,7 +86,12 @@ public class ArgumentTypeResolver { this.expressionTypingServices = expressionTypingServices; } - public static boolean isSubtypeOfForArgumentType( + @Inject + public void setDoubleColonExpressionResolver(@NotNull DoubleColonExpressionResolver doubleColonExpressionResolver) { + this.doubleColonExpressionResolver = doubleColonExpressionResolver; + } + + public boolean isSubtypeOfForArgumentType( @NotNull KotlinType actualType, @NotNull KotlinType expectedType ) { @@ -99,6 +102,7 @@ public class ArgumentTypeResolver { return KotlinTypeChecker.DEFAULT.isSubtypeOf(actualType, expectedType); } + public void checkTypesWithNoCallee( @NotNull CallResolutionContext context ) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt index 811275c62b9..b1a57958b15 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt @@ -362,7 +362,7 @@ class CandidateResolver( if (type == null || (type.isError && !type.isFunctionPlaceholder)) { matchStatus = ArgumentMatchStatus.ARGUMENT_HAS_NO_TYPE } else if (!noExpectedType(expectedType)) { - if (!ArgumentTypeResolver.isSubtypeOfForArgumentType(type, expectedType)) { + if (!argumentTypeResolver.isSubtypeOfForArgumentType(type, expectedType)) { val smartCast = smartCastValueArgumentTypeIfPossible(expression, newContext.expectedType, type, newContext) if (smartCast == null) { resultStatus = tryNotNullableArgument(type, expectedType) ?: OTHER_ERROR @@ -410,7 +410,7 @@ class CandidateResolver( if (!argumentType.isMarkedNullable || parameterType.isMarkedNullable) return null val notNullableArgumentType = argumentType.makeNotNullable() - val isApplicable = ArgumentTypeResolver.isSubtypeOfForArgumentType(notNullableArgumentType, parameterType) + val isApplicable = argumentTypeResolver.isSubtypeOfForArgumentType(notNullableArgumentType, parameterType) return if (isApplicable) NULLABLE_ARGUMENT_TYPE_MISMATCH else null } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastManager.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastManager.kt index 4f2b73fe958..72da23cedac 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastManager.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastManager.kt @@ -37,7 +37,7 @@ import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.typeUtil.expandIntersectionTypeIfNecessary import java.util.* -class SmartCastManager { +class SmartCastManager(private val argumentTypeResolver: ArgumentTypeResolver) { fun getSmartCastVariants( receiverToCast: ReceiverValue, @@ -110,10 +110,10 @@ class SmartCastManager { context: ResolutionContext<*> ): ReceiverSmartCastResult? = when { - ArgumentTypeResolver.isSubtypeOfForArgumentType(receiverArgument.type, receiverParameterType) -> + argumentTypeResolver.isSubtypeOfForArgumentType(receiverArgument.type, receiverParameterType) -> ReceiverSmartCastResult.OK getSmartCastVariantsExcludingReceiver(context, receiverArgument).any { - ArgumentTypeResolver.isSubtypeOfForArgumentType(it, receiverParameterType) + argumentTypeResolver.isSubtypeOfForArgumentType(it, receiverParameterType) } -> ReceiverSmartCastResult.SMARTCAST_NEEDED_OR_NOT_NULL_EXPECTED else -> null @@ -135,7 +135,7 @@ class SmartCastManager { listOf(expectedType) for (possibleType in c.dataFlowInfo.getCollectedTypes(dataFlowValue, c.languageVersionSettings)) { - if (expectedTypes.any { ArgumentTypeResolver.isSubtypeOfForArgumentType(possibleType, it) } && + if (expectedTypes.any { argumentTypeResolver.isSubtypeOfForArgumentType(possibleType, it) } && (additionalPredicate == null || additionalPredicate(possibleType)) ) { if (expression != null) { @@ -180,7 +180,7 @@ class SmartCastManager { val immanentlyNotNull = !dataFlowValue.immanentNullability.canBeNull() val nullableExpectedType = TypeUtils.makeNullable(expectedType) - if (ArgumentTypeResolver.isSubtypeOfForArgumentType(dataFlowValue.type, nullableExpectedType) && + if (argumentTypeResolver.isSubtypeOfForArgumentType(dataFlowValue.type, nullableExpectedType) && (additionalPredicate == null || additionalPredicate(dataFlowValue.type)) ) { if (!immanentlyNotNull && expression != null) {