[NI] Support smartcast info in ResolvedCall on receivers

This commit is contained in:
Stanislav Erokhin
2017-08-18 05:54:20 +03:00
parent cb1270836c
commit d9eef94a8e
5 changed files with 65 additions and 28 deletions
@@ -35,10 +35,14 @@ class AdditionalDiagnosticReporter {
reportSmartCasts(candidate, resultingDescriptor, kotlinDiagnosticsHolder)
}
private fun createSmartCastDiagnostic(argument: KotlinCallArgument, expectedResultType: UnwrappedType): SmartCastDiagnostic? {
private fun createSmartCastDiagnostic(
candidate: ResolvedCallAtom,
argument: KotlinCallArgument,
expectedResultType: UnwrappedType
): SmartCastDiagnostic? {
if (argument !is ExpressionKotlinCallArgument) return null
if (!KotlinTypeChecker.DEFAULT.isSubtypeOf(argument.receiver.receiverValue.type, expectedResultType)) {
return SmartCastDiagnostic(argument, expectedResultType.unwrap())
return SmartCastDiagnostic(argument, expectedResultType.unwrap(), candidate.atom)
}
return null
}
@@ -51,7 +55,7 @@ class AdditionalDiagnosticReporter {
if (receiver == null || parameter == null) return null
val expectedType = parameter.type.unwrap().let { if (receiver.isSafeCall) it.makeNullableAsSpecified(true) else it }
val smartCastDiagnostic = createSmartCastDiagnostic(receiver, expectedType) ?: return null
val smartCastDiagnostic = createSmartCastDiagnostic(candidate, receiver, expectedType) ?: return null
// todo may be we have smart cast to Int?
return smartCastDiagnostic.takeIf {
@@ -75,7 +79,7 @@ class AdditionalDiagnosticReporter {
for (parameter in resultingDescriptor.valueParameters) {
for (argument in candidate.argumentMappingByOriginal[parameter.original]?.arguments ?: continue) {
val smartCastDiagnostic = createSmartCastDiagnostic(argument, argument.getExpectedType(parameter)) ?: continue
val smartCastDiagnostic = createSmartCastDiagnostic(candidate, argument, argument.getExpectedType(parameter)) ?: continue
val thereIsUnstableSmartCastError = candidate.diagnostics.filterIsInstance<UnstableSmartCast>().any {
it.argument == argument
@@ -58,7 +58,7 @@ internal object CheckVisibility : ResolutionPart() {
if (dispatchReceiverArgument is ExpressionKotlinCallArgument) {
val smartCastReceiver = getReceiverValueWithSmartCast(receiverValue, dispatchReceiverArgument.receiver.stableType)
if (Visibilities.findInvisibleMember(smartCastReceiver, candidateDescriptor, containingDescriptor) == null) {
addDiagnostic(SmartCastDiagnostic(dispatchReceiverArgument, dispatchReceiverArgument.receiver.stableType))
addDiagnostic(SmartCastDiagnostic(dispatchReceiverArgument, dispatchReceiverArgument.receiver.stableType, resolvedCall.atom))
return
}
}
@@ -128,7 +128,8 @@ class NotCallableExpectedType(
// SmartCasts
class SmartCastDiagnostic(
val argument: ExpressionKotlinCallArgument,
val smartCastType: UnwrappedType
val smartCastType: UnwrappedType,
val kotlinCall: KotlinCall?
): KotlinCallDiagnostic(RESOLVED) {
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
}