Skip to content

Commit 6f512ad

Browse files
authored
Merge pull request #58666 from xedin/rdar-92327807-5.7
[5.7][CSSimplify] Don't attempt to synthesize ~= for optional base types
2 parents 4a7b710 + 387be07 commit 6f512ad

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9205,17 +9205,21 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
92059205
dyn_cast<EnumElementPattern>(patternLoc->getPattern())) {
92069206
auto enumType = baseObjTy->getMetatypeInstanceType();
92079207

9208-
// If the synthesis of ~= resulted in errors (i.e. broken stdlib)
9209-
// that would be diagnosed inline, so let's just fall through and
9210-
// let this situation be diagnosed as a missing member.
9211-
auto hadErrors = inferEnumMemberThroughTildeEqualsOperator(
9208+
// Optional base type does not trigger `~=` synthesis, but it tries
9209+
// to find member on both `Optional` and its wrapped type.
9210+
if (!enumType->getOptionalObjectType()) {
9211+
// If the synthesis of ~= resulted in errors (i.e. broken stdlib)
9212+
// that would be diagnosed inline, so let's just fall through and
9213+
// let this situation be diagnosed as a missing member.
9214+
auto hadErrors = inferEnumMemberThroughTildeEqualsOperator(
92129215
*this, enumElement, enumType, memberTy, locator);
92139216

9214-
// Let's consider current member constraint solved because it's
9215-
// replaced by a new set of constraints that would resolve member
9216-
// type.
9217-
if (!hadErrors)
9218-
return SolutionKind::Solved;
9217+
// Let's consider current member constraint solved because it's
9218+
// replaced by a new set of constraints that would resolve member
9219+
// type.
9220+
if (!hadErrors)
9221+
return SolutionKind::Solved;
9222+
}
92199223
}
92209224
}
92219225
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
enum MyEnum {
4+
case test(Int)
5+
}
6+
7+
func test(result: MyEnum, optResult: MyEnum?) {
8+
if let .co = result { // expected-error {{pattern matching in a condition requires the 'case' keyword}}
9+
// expected-error@-1 {{type 'MyEnum' has no member 'co'}}
10+
}
11+
12+
if let .co(42) = result { // expected-error {{pattern matching in a condition requires the 'case' keyword}}
13+
// expected-error@-1 {{type of expression is ambiguous without more context}}
14+
}
15+
16+
if let .co = optResult { // expected-error {{pattern matching in a condition requires the 'case' keyword}}
17+
// expected-error@-1 {{type 'MyEnum?' has no member 'co'}}
18+
}
19+
20+
let _ = {
21+
if let .co = result { // expected-error 2 {{pattern matching in a condition requires the 'case' keyword}}
22+
// expected-error@-1 {{type 'MyEnum' has no member 'co'}}
23+
}
24+
}
25+
26+
let _ = {
27+
if let .co = optResult { // expected-error 2 {{pattern matching in a condition requires the 'case' keyword}}
28+
// expected-error@-1 {{type 'MyEnum?' has no member 'co'}}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)