Skip to content

Commit da7e486

Browse files
authored
Merge pull request #23566 from xedin/rdar-49159472-5.1
[5.1][CSSimplify] Teach disjunction filtering that some enum cases have cu…
2 parents 97adda9 + 215371f commit da7e486

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,11 @@ bool constraints::areConservativelyCompatibleArgumentLabels(
132132
hasCurriedSelf = false;
133133
} else if (baseType->is<AnyMetatypeType>() && decl->isInstanceMember()) {
134134
hasCurriedSelf = false;
135-
} else if (isa<EnumElementDecl>(decl)) {
136-
hasCurriedSelf = false;
135+
} else if (auto *EED = dyn_cast<EnumElementDecl>(decl)) {
136+
// enum elements have either `(Self.Type) -> (Arg...) -> Self`, or
137+
// `(Self.Type) -> Self`, in the former case self type has to be
138+
// stripped off.
139+
hasCurriedSelf = bool(EED->getParameterList());
137140
} else {
138141
hasCurriedSelf = true;
139142
}

test/Constraints/enum_cases.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,34 @@ func rdar34583132() {
124124
}
125125
}
126126
}
127+
128+
func rdar_49159472() {
129+
struct A {}
130+
struct B {}
131+
struct C {}
132+
133+
enum E {
134+
case foo(a: A, b: B?)
135+
136+
var foo: C? {
137+
return nil
138+
}
139+
}
140+
141+
class Test {
142+
var e: E
143+
144+
init(_ e: E) {
145+
self.e = e
146+
}
147+
148+
func bar() {
149+
e = .foo(a: A(), b: nil) // Ok
150+
e = E.foo(a: A(), b: nil) // Ok
151+
baz(e: .foo(a: A(), b: nil)) // Ok
152+
baz(e: E.foo(a: A(), b: nil)) // Ok
153+
}
154+
155+
func baz(e: E) {}
156+
}
157+
}

0 commit comments

Comments
 (0)