-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfgeneric constraintsFeature → generics: generic constraintsFeature → generics: generic constraintsgenericsFeature: generic declarations and typesFeature: generic declarations and typestype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistype inferenceFeature: type inferenceFeature: type inferenceunexpected errorBug: Unexpected errorBug: Unexpected error
Description
| Previous ID | SR-8705 |
| Radar | None |
| Original Reporter | spiceginger (JIRA User) |
| Type | Bug |
Attachment: Download
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Compiler |
| Labels | Bug, AssociatedTypeInference |
| Assignee | None |
| Priority | Medium |
md5: 8df8fbcda4ed1cc019b6f866dad7f962
Issue Description:
import UIKit
protocol Factory {
associatedtype ViewController: UIViewController
associatedtype Context
func build(with context: Context) -> ViewController
}
struct NavigationFactory: Factory {
func build(with context: Any?) -> UINavigationController {
return UINavigationController(nibName: nil, bundle: nil)
}
}
struct Duplicator<VC: UIViewController, C>: Factory {
typealias ViewController = VC
typealias Context = C
func build(with context: Context) -> ViewController {
return ViewController(nibName: nil, bundle: nil)
}
}
struct MergerWorks<F1: Factory, F2: Factory> where F1.ViewController == F2.ViewController, F1.Context == F2.Context {
let vc1: UIViewController
let vc2: UIViewController
init(factory1: F1, factory2:F2, context: F1.Context) {
self.vc1 = factory1.build(with: context)
self.vc2 = factory2.build(with: context)
}
}
struct MergerBroken {
let vc1: UIViewController
let vc2: UIViewController
init<F1: Factory, F2: Factory>(factory1: F1, factory2:F2, context: F1.Context) where F1.ViewController == F2.ViewController, F1.Context == F2.Context {
self.vc1 = factory1.build(with: context)
self.vc2 = factory2.build(with: context)
}
}
let mergerWorks = MergerWorks(factory1: NavigationFactory(), factory2: Duplicator(), context: nil)
let mergerBroken = MergerBroken(factory1: NavigationFactory(), factory2: Duplicator(), context: nil) // Causes error: error: generic parameter 'C' could not be inferred, note: explicitly specify the generic arguments to fix this issueImplicitly specifying the type of `Duplicator` helps:
let mergerBroken = MergerBroken(factory1: NavigationFactory(), factory2: Duplicator<UINavigationController, Any?>(), context: nil)But expected the same behaviour as in MergerWorks where compiler is able to resolve the type of Duplicator.
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfgeneric constraintsFeature → generics: generic constraintsFeature → generics: generic constraintsgenericsFeature: generic declarations and typesFeature: generic declarations and typestype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistype inferenceFeature: type inferenceFeature: type inferenceunexpected errorBug: Unexpected errorBug: Unexpected error