[NI] Refactor UnstableSmartCast diagnostic
Split diagnostic classes for unstable smartcast with different resolution applicability. ^KT-36264 Fixed
This commit is contained in:
+2
-1
@@ -121,7 +121,8 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
override fun onCallArgument(callArgument: KotlinCallArgument, diagnostic: KotlinCallDiagnostic) {
|
override fun onCallArgument(callArgument: KotlinCallArgument, diagnostic: KotlinCallDiagnostic) {
|
||||||
when (diagnostic.javaClass) {
|
when (diagnostic.javaClass) {
|
||||||
SmartCastDiagnostic::class.java -> reportSmartCast(diagnostic as SmartCastDiagnostic)
|
SmartCastDiagnostic::class.java -> reportSmartCast(diagnostic as SmartCastDiagnostic)
|
||||||
UnstableSmartCast::class.java -> reportUnstableSmartCast(diagnostic as UnstableSmartCast)
|
UnstableSmartCastDiagnosticError::class.java,
|
||||||
|
UnstableSmartCastResolutionError::class.java -> reportUnstableSmartCast(diagnostic as UnstableSmartCast)
|
||||||
TooManyArguments::class.java -> {
|
TooManyArguments::class.java -> {
|
||||||
trace.reportTrailingLambdaErrorOr(callArgument.psiExpression) { expr ->
|
trace.reportTrailingLambdaErrorOr(callArgument.psiExpression) { expr ->
|
||||||
TOO_MANY_ARGUMENTS.on(expr, (diagnostic as TooManyArguments).descriptor)
|
TOO_MANY_ARGUMENTS.on(expr, (diagnostic as TooManyArguments).descriptor)
|
||||||
|
|||||||
+15
-4
@@ -139,7 +139,7 @@ class SmartCastDiagnostic(
|
|||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnstableSmartCast private constructor(
|
sealed class UnstableSmartCast(
|
||||||
val argument: ExpressionKotlinCallArgument,
|
val argument: ExpressionKotlinCallArgument,
|
||||||
val targetType: UnwrappedType,
|
val targetType: UnwrappedType,
|
||||||
applicability: ResolutionCandidateApplicability,
|
applicability: ResolutionCandidateApplicability,
|
||||||
@@ -150,14 +150,25 @@ class UnstableSmartCast private constructor(
|
|||||||
operator fun invoke(
|
operator fun invoke(
|
||||||
argument: ExpressionKotlinCallArgument,
|
argument: ExpressionKotlinCallArgument,
|
||||||
targetType: UnwrappedType,
|
targetType: UnwrappedType,
|
||||||
isReceiver: Boolean = false,
|
isReceiver: Boolean = false, // for reproducing OI behaviour
|
||||||
): UnstableSmartCast {
|
): UnstableSmartCast {
|
||||||
val applicability = if (isReceiver) MAY_THROW_RUNTIME_ERROR else RESOLVED_WITH_ERROR
|
return if (isReceiver)
|
||||||
return UnstableSmartCast(argument, targetType, applicability)
|
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) {
|
class UnsafeCallError(val receiver: SimpleKotlinCallArgument) : KotlinCallDiagnostic(MAY_THROW_RUNTIME_ERROR) {
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallReceiver(receiver, this)
|
override fun report(reporter: DiagnosticReporter) = reporter.onCallReceiver(receiver, this)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user