[NI] Refactor UnstableSmartCast diagnostic

Split diagnostic classes for unstable smartcast with different resolution applicability.

^KT-36264 Fixed
This commit is contained in:
Pavel Kirpichenkov
2020-02-13 13:13:55 +03:00
parent 15d744c3da
commit 5d6d287faa
2 changed files with 17 additions and 5 deletions
@@ -139,7 +139,7 @@ class SmartCastDiagnostic(
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
}
class UnstableSmartCast private constructor(
sealed class UnstableSmartCast(
val argument: ExpressionKotlinCallArgument,
val targetType: UnwrappedType,
applicability: ResolutionCandidateApplicability,
@@ -150,14 +150,25 @@ class UnstableSmartCast private constructor(
operator fun invoke(
argument: ExpressionKotlinCallArgument,
targetType: UnwrappedType,
isReceiver: Boolean = false,
isReceiver: Boolean = false, // for reproducing OI behaviour
): UnstableSmartCast {
val applicability = if (isReceiver) MAY_THROW_RUNTIME_ERROR else RESOLVED_WITH_ERROR
return UnstableSmartCast(argument, targetType, applicability)
return if (isReceiver)
UnstableSmartCastResolutionError(argument, targetType)
else UnstableSmartCastDiagnosticError(argument, targetType)
}
}
}
class UnstableSmartCastResolutionError(
argument: ExpressionKotlinCallArgument,
targetType: UnwrappedType,
) : UnstableSmartCast(argument, targetType, MAY_THROW_RUNTIME_ERROR)
class UnstableSmartCastDiagnosticError(
argument: ExpressionKotlinCallArgument,
targetType: UnwrappedType,
) : UnstableSmartCast(argument, targetType, RESOLVED_WITH_ERROR)
class UnsafeCallError(val receiver: SimpleKotlinCallArgument) : KotlinCallDiagnostic(MAY_THROW_RUNTIME_ERROR) {
override fun report(reporter: DiagnosticReporter) = reporter.onCallReceiver(receiver, this)
}