Skip to content

Commit 1802ec9

Browse files
authored
Merge pull request #32753 from theblixguy/fix/associated-type-inference-enum-witness
[AssociatedTypeInference] Strip 'self' parameter from function type of an enum case witness
2 parents f8d8091 + be79d34 commit 1802ec9

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,8 @@ static Type getWitnessTypeForMatching(NormalProtocolConformance *conformance,
546546

547547
/// Remove the 'self' type from the given type, if it's a method type.
548548
static Type removeSelfParam(ValueDecl *value, Type type) {
549-
if (auto func = dyn_cast<AbstractFunctionDecl>(value)) {
550-
if (func->getDeclContext()->isTypeContext())
551-
return type->castTo<AnyFunctionType>()->getResult();
549+
if (value->hasCurriedSelf()) {
550+
return type->castTo<AnyFunctionType>()->getResult();
552551
}
553552

554553
return type;

test/decl/protocol/req/associated_type_inference.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,22 @@ extension SR_12707_P2 {
588588
struct SR_12707_Conform_P2: SR_12707_P2 {
589589
typealias A = Never
590590
}
591+
592+
// SR-13172: Inference when witness is an enum case
593+
protocol SR_13172_P1 {
594+
associatedtype Bar
595+
static func bar(_ value: Bar) -> Self
596+
}
597+
598+
enum SR_13172_E1: SR_13172_P1 {
599+
case bar(String) // Okay
600+
}
601+
602+
protocol SR_13172_P2 {
603+
associatedtype Bar
604+
static var bar: Bar { get }
605+
}
606+
607+
enum SR_13172_E2: SR_13172_P2 {
608+
case bar // Okay
609+
}

0 commit comments

Comments
 (0)