Skip to content

Commit 7166f19

Browse files
committed
[ConstraintSystem] Reject property wrapper transform on func parameters in pattern context
The transform is not currently supported on anything but regular calls.
1 parent 9774e98 commit 7166f19

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,15 @@ unwrapPropertyWrapperParameterTypes(ConstraintSystem &cs, AbstractFunctionDecl *
14031403
return functionType;
14041404
}
14051405

1406+
// This transform is not applicable to pattern matching context.
1407+
//
1408+
// Note: If the transform is ever enabled for patterns - new branch
1409+
// would have to be added to `nameLoc` selection.
1410+
if (auto last = locator.last()) {
1411+
if (last->is<LocatorPathElt::PatternMatch>())
1412+
return functionType;
1413+
}
1414+
14061415
auto *paramList = funcDecl->getParameters();
14071416
auto paramTypes = functionType->getParams();
14081417
SmallVector<AnyFunctionType::Param, 4> adjustedParamTypes;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5 -enable-experimental-feature ResultBuilderASTTransform -
2+
3+
// REQUIRES: objc_interop
4+
// REQUIRES: OS=macosx
5+
6+
import SwiftUI
7+
8+
struct Person {
9+
var fullName: String
10+
}
11+
12+
enum State<Input, Output, Failure: Error> {
13+
case success(Input, Output)
14+
case failure(Input, Failure)
15+
}
16+
17+
// Type-checker finds this overload based on
18+
// `extension Optional : View where Wrapped : View { ... }`
19+
extension View {
20+
func failure(_: String) -> some View { EmptyView() }
21+
}
22+
23+
struct MyTest : View {
24+
var state: State<Person, UUID, Error>?
25+
26+
// `switch` has to be anchored on `AccessorDecl` to reproduce
27+
// a crash.
28+
var body: some View {
29+
switch state {
30+
case nil:
31+
Text("nil")
32+
case .success(let person, _), .failure(let person, _):
33+
Text(person.fullName)
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)