mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This helps to postpone attempting bindings related to generic
parameters with all else being equal.
Consider situation when function has class requirement on its
generic parameter. Without such requirement solver would infer
sub-class for `T`. But currently when requirement is present base
class is inferred instead, because when bindings for such generic
parameter are attempted early single available binding at that
point comes from the requirement.
```swift
class BaseClass {}
class SubClass: BaseClass {}
struct Box<T> { init(_: T.Type) {} }
func test<T: BaseClass>(box: Box<T>) -> T.Type {
return T.self
}
test(box: .init(SubClass.self)) // `T` expected to be `SubClass`
```
Resolves: [SR-9626](https://bugs.swift.org/browse/SR-9626)
Resolves: rdar://problem/47324309
23 lines
610 B
Swift
23 lines
610 B
Swift
// RUN: %target-swift-frontend -emit-sil -verify %s | %FileCheck %s
|
|
|
|
class BaseClass {}
|
|
class SubClass: BaseClass {}
|
|
struct Box<T> { init(_: T.Type) {} }
|
|
|
|
|
|
func test1<T>(box: Box<T>) -> T.Type {
|
|
return T.self
|
|
}
|
|
|
|
func test2<T: BaseClass>(box: Box<T>) -> T.Type {
|
|
return T.self
|
|
}
|
|
|
|
// CHECK: [[F1:%.*]] = function_ref @$s6sr96263BoxVyACyxGxmcfC
|
|
// CHECK-NEXT: apply [[F1]]<SubClass>({{.*}}, {{.*}})
|
|
_ = test1(box: .init(SubClass.self))
|
|
|
|
// CHECK: [[F2:%.*]] = function_ref @$s6sr96265test23boxxmAA3BoxVyxG_tAA9BaseClassCRbzlF
|
|
// CHECK-NEXT: apply [[F2]]<SubClass>({{.*}})
|
|
_ = test2(box: .init(SubClass.self))
|