Skip to content

Commit 3617ee8

Browse files
authored
[AssociatedTypeInference] Strip 'self' parameter from function type of an enum case witness (swiftlang#32768)
1 parent d63bcf7 commit 3617ee8

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
@@ -549,9 +549,8 @@ static Type getWitnessTypeForMatching(NormalProtocolConformance *conformance,
549549

550550
/// Remove the 'self' type from the given type, if it's a method type.
551551
static Type removeSelfParam(ValueDecl *value, Type type) {
552-
if (auto func = dyn_cast<AbstractFunctionDecl>(value)) {
553-
if (func->getDeclContext()->isTypeContext())
554-
return type->castTo<AnyFunctionType>()->getResult();
552+
if (value->hasCurriedSelf()) {
553+
return type->castTo<AnyFunctionType>()->getResult();
555554
}
556555

557556
return type;

test/decl/protocol/req/associated_type_inference.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,22 @@ extension S30 {
527527
T.bar()
528528
}
529529
}
530+
531+
// SR-13172: Inference when witness is an enum case
532+
protocol SR_13172_P1 {
533+
associatedtype Bar
534+
static func bar(_ value: Bar) -> Self
535+
}
536+
537+
enum SR_13172_E1: SR_13172_P1 {
538+
case bar(String) // Okay
539+
}
540+
541+
protocol SR_13172_P2 {
542+
associatedtype Bar
543+
static var bar: Bar { get }
544+
}
545+
546+
enum SR_13172_E2: SR_13172_P2 {
547+
case bar // Okay
548+
}

0 commit comments

Comments
 (0)