Skip to content

Commit bdcb2a4

Browse files
authored
Merge pull request swiftlang#35844 from slavapestov/enum-witness-throwing-requirement
Sema: Allow an enum case to witness a throwing static method requirement
2 parents 2009308 + 6c5e516 commit bdcb2a4

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ swift::matchWitness(
620620
if (isa<VarDecl>(req) &&
621621
cast<VarDecl>(req)->getParsedAccessor(AccessorKind::Set))
622622
return RequirementMatch(witness, MatchKind::SettableConflict);
623+
624+
decomposeFunctionType = enumCase->hasAssociatedValues();
623625
}
624626

625627
// If the requirement is @objc, the witness must not be marked with @nonobjc.

test/decl/protocol/protocol_enum_witness.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,21 @@ enum Bar8: Foo8 {
8181
// Witness does not have argument label, but requirement does
8282

8383
protocol Foo9 {
84-
static func bar(f: Int) -> Self // expected-note {{protocol requires function 'bar(f:)' with type '(Int) -> Bar9'; do you want to add a stub?}}
84+
static func bar(f: Int) -> Self // expected-note {{requirement 'bar(f:)' declared here}}
8585
}
8686

87-
enum Bar9: Foo9 { // expected-error {{type 'Bar9' does not conform to protocol 'Foo9'}}
88-
case bar(_ f: Int) // expected-note {{candidate has non-matching type '(Bar9.Type) -> (Int) -> Bar9'}}
87+
enum Bar9: Foo9 {
88+
case bar(_ f: Int) // expected-error {{enum case 'bar' has different argument labels from those required by protocol 'Foo9' ('bar(f:)')}}
8989
}
9090

9191
// Witness does not have any labels, but requirement does
9292

9393
protocol Foo10 {
94-
static func bar(g: Int) -> Self // expected-note {{protocol requires function 'bar(g:)' with type '(Int) -> Bar10'; do you want to add a stub?}}
94+
static func bar(g: Int) -> Self // expected-note {{requirement 'bar(g:)' declared here}}
9595
}
9696

97-
enum Bar10: Foo10 { // expected-error {{type 'Bar10' does not conform to protocol 'Foo10'}}
98-
case bar(Int) // expected-note {{candidate has non-matching type '(Bar10.Type) -> (Int) -> Bar10'}}
97+
enum Bar10: Foo10 {
98+
case bar(Int) // expected-error {{enum case 'bar' has different argument labels from those required by protocol 'Foo10' ('bar(g:)')}}
9999
}
100100

101101
// Witness does not have a payload, but requirement is a function
@@ -129,3 +129,13 @@ enum Bar13: Foo13 {
129129
case bar(j: Int) // Okay
130130
case baz(_ k: String) // Okay
131131
}
132+
133+
////// REQUIREMENT IS A THROWING FUNCTION //////
134+
135+
protocol ThrowingFactory {
136+
static func horse(_: Int) throws -> Self
137+
}
138+
139+
enum HorseFactory : ThrowingFactory {
140+
case horse(Int)
141+
}

0 commit comments

Comments
 (0)