Skip to content

Commit f5456bd

Browse files
committed
[CSGen] Adjust locators for sub-patterns of parens
In cases like `.<name>(_)`, the `_` sub-pattern should not assume locator of the parent paren, just like it doesn't in case of tuple i.e. `.<name>(_, ...)` where each element gets a `PatternMatch(<elt>)` locator.
1 parent e66aa61 commit f5456bd

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/Sema/CSGen.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,9 +2265,11 @@ namespace {
22652265
->getUnderlyingType();
22662266
}
22672267

2268-
auto underlyingType =
2269-
getTypeForPattern(paren->getSubPattern(), locator,
2270-
externalPatternType, bindPatternVarsOneWay);
2268+
auto *subPattern = paren->getSubPattern();
2269+
auto underlyingType = getTypeForPattern(
2270+
subPattern,
2271+
locator.withPathElement(LocatorPathElt::PatternMatch(subPattern)),
2272+
externalPatternType, bindPatternVarsOneWay);
22712273

22722274
if (!underlyingType)
22732275
return Type();
@@ -2694,7 +2696,9 @@ namespace {
26942696
// and we're matching the type of that subpattern to the parameter
26952697
// types.
26962698
Type subPatternType = getTypeForPattern(
2697-
subPattern, locator, Type(), bindPatternVarsOneWay);
2699+
subPattern,
2700+
locator.withPathElement(LocatorPathElt::PatternMatch(subPattern)),
2701+
Type(), bindPatternVarsOneWay);
26982702

26992703
if (!subPatternType)
27002704
return Type();

test/Constraints/patterns.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ func rdar63510989() {
486486
}
487487

488488
func test(e: E) {
489+
if case .single(_) = e {} // Ok
489490
if case .single(_ as Value) = e {} // Ok
490491
if case .single(let v as Value) = e {} // Ok
491492
// expected-warning@-1 {{immutable value 'v' was never used; consider replacing with '_' or removing it}}

0 commit comments

Comments
 (0)