Skip to content

Commit 6ace447

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents b1cc1ae + 44d4386 commit 6ace447

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,14 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
850850
Type openedFullWitnessType;
851851
Type reqType, openedFullReqType;
852852

853-
auto reqSig = req->getInnermostDeclContext()->getGenericSignatureOfContext();
853+
GenericSignature reqSig = proto->getGenericSignature();
854+
if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(req)) {
855+
if (funcDecl->isGeneric())
856+
reqSig = funcDecl->getGenericSignature();
857+
} else if (auto *subscriptDecl = dyn_cast<SubscriptDecl>(req)) {
858+
if (subscriptDecl->isGeneric())
859+
reqSig = subscriptDecl->getGenericSignature();
860+
}
854861

855862
ClassDecl *covariantSelf = nullptr;
856863
if (witness->getDeclContext()->getExtendedProtocolDecl()) {

test/decl/protocol/req/unsatisfiable.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,25 @@ protocol P4 {
5858
protocol P5 {
5959
associatedtype Y where Y : S // expected-error {{type 'Self.Y' constrained to non-protocol, non-class type 'S'}}
6060
}
61+
62+
protocol P6 {
63+
associatedtype T
64+
associatedtype U
65+
66+
func foo() where T == U
67+
// expected-error@-1 {{instance method requirement 'foo()' cannot add constraint 'Self.T == Self.U' on 'Self'}}
68+
// expected-note@-2 {{protocol requires function 'foo()' with type '() -> ()'; do you want to add a stub?}}
69+
}
70+
71+
struct S2 : P6 {
72+
// expected-error@-1 {{type 'S2' does not conform to protocol 'P6'}}
73+
typealias T = Int
74+
typealias U = String
75+
76+
func foo() {}
77+
// expected-note@-1 {{candidate has non-matching type '() -> ()'}}
78+
79+
// FIXME: This error is bogus and should be omitted on account of the protocol requirement itself
80+
// being invalid.
81+
}
82+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %target-swift-frontend -emit-ir %s
2+
3+
public protocol HorseSaddle {}
4+
public enum EnglishSaddle : HorseSaddle {}
5+
6+
public enum WesternSaddle<A, B> : HorseSaddle {}
7+
8+
public protocol Horse {
9+
associatedtype Body : Horse
10+
11+
associatedtype Saddle: HorseSaddle
12+
13+
var body: Body { get }
14+
}
15+
16+
extension Horse {
17+
typealias Saddle = Body.Saddle
18+
}
19+
20+
public struct DraftHorse<T> : Pony {
21+
public typealias Saddle = EnglishSaddle
22+
public typealias Body = Never
23+
var contents: T
24+
}
25+
26+
// MARK: - Implementation detail
27+
28+
extension Never : Horse {
29+
public typealias Saddle = EnglishSaddle
30+
public typealias Body = Never
31+
32+
public var body: Never {
33+
switch self {}
34+
}
35+
}
36+
37+
protocol Pony : Horse where Body == Never {}
38+
extension Pony {
39+
public var body: Never { fatalError() }
40+
}
41+

0 commit comments

Comments
 (0)