Inconsistent Type Inference with Generics and Protocols in Closure #68306
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
triage needed
This issue needs more specific labels
Description
When combining protocols with type constraints and generics for function’s parameter type, the type returned by the function in the closure is different from the type of the other parameter, even though in the body of the function it is required that they are the same.
Example:
viewController
parameter ingoTo(viewController:completion:)
is correctly bound toT
that indisplaySpecialVC()
will beSpecialViewControllerProtocol
, however the type ofactualVC
is justGenericViewController
instead ofT
and it requires a casting likeguard let actualVCCasted: SpecialViewControllerProtocol = actualVC as? SpecialViewControllerProtocol else { return }
in order to call protocols’s functions.I took a look at #61296 and #58624, but it seems that this is a different case.
Steps to reproduce
See example above.
Expected behavior
The type returned in the closure
completion
should be the same as the one passed in the parameterviewController
.Environment
swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100) - Target: x86_64-apple-macosx13.0
Xcode 14.3.1 - Build version 14E300c
The text was updated successfully, but these errors were encountered: