Skip to content

Commit 2dd9774

Browse files
committed
[CSGen] Use correct locator for member references in enum element patterns
Referencing a member in pattern context is not a regular member reference, it should use only enum element declarations, just like leading-dot syntax does, so both locators should end with `pattern matching` element to indicate that to the member lookup. Resolves: rdar://90347159
1 parent 8c21aaf commit 2dd9774

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,8 +2584,7 @@ namespace {
25842584
parentMetaType, enumPattern->getName(), memberType, CurDC,
25852585
functionRefKind, {},
25862586
CS.getConstraintLocator(locator,
2587-
{LocatorPathElt::PatternMatch(pattern),
2588-
ConstraintLocator::Member}));
2587+
LocatorPathElt::PatternMatch(pattern)));
25892588

25902589
// Parent type needs to be convertible to the pattern type; this
25912590
// accounts for cases where the pattern type is existential.

test/expr/closure/multi_statement.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,26 @@ func test_taps_type_checked_with_correct_decl_context() {
249249
return false
250250
}
251251
}
252+
253+
// rdar://90347159 - in pattern matching context `case` should be preferred over static declarations
254+
func test_pattern_matches_only_cases() {
255+
enum ParsingError : Error {
256+
case ok(Int)
257+
case failed([Error], Int)
258+
259+
static var ok: Int { 42 }
260+
static func failed(_: [Error], at: Any) -> Self { fatalError() }
261+
}
262+
263+
let _: (ParsingError) -> Void = {
264+
switch $0 {
265+
case let ParsingError.failed(errors, _): print(errors) // Ok
266+
default: break
267+
}
268+
269+
switch $0 {
270+
case let ParsingError.ok(result): print(result) // Ok
271+
default: break
272+
}
273+
}
274+
}

0 commit comments

Comments
 (0)