Skip to content

Commit f6f80be

Browse files
committed
[Constraint system] Handle implicit tupling during pattern matching.
SE-0110 strikes again!
1 parent d607d3a commit f6f80be

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,12 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
16581658
implodeParams(func2Params);
16591659
}
16601660
}
1661+
} else if (last->getKind() == ConstraintLocator::PatternMatch &&
1662+
isa<EnumElementPattern>(
1663+
last->castTo<LocatorPathElt::PatternMatch>().getPattern()) &&
1664+
isSingleTupleParam(ctx, func1Params) &&
1665+
canImplodeParams(func2Params)) {
1666+
implodeParams(func2Params);
16611667
}
16621668
}
16631669

test/stmt/if_while_var.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func testWhileScoping(_ a: Int?) {// expected-note {{did you mean 'a'?}}
148148
public enum SomeParseResult<T> {
149149
case error(length: Int)
150150
case repeated(value: String, repetitions: Int)
151+
// expected-note@-1{{'repeated(value:repetitions:)' declared here}}
151152

152153
var _error: Int? {
153154
if case .error(let result) = self { return result }
@@ -199,3 +200,9 @@ public enum SomeParseResult<T> {
199200
return nil
200201
}
201202
}
203+
204+
func matchImplicitTupling(pr: SomeParseResult<Int>) {
205+
if case .repeated(let x) = pr { // expected-warning{{enum case 'repeated' has 2 associated values; matching them as a tuple is deprecated}}
206+
let y: Int = x // expected-error{{cannot convert value of type '(value: String, repetitions: Int)' to specified type 'Int'}}
207+
}
208+
}

0 commit comments

Comments
 (0)