Skip to content

[ConstraintSystem] Reject property wrapper transform on func paramete… #62490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,15 @@ unwrapPropertyWrapperParameterTypes(ConstraintSystem &cs, AbstractFunctionDecl *
return functionType;
}

// This transform is not applicable to pattern matching context.
//
// Note: If the transform is ever enabled for patterns - new branch
// would have to be added to `nameLoc` selection.
if (auto last = locator.last()) {
if (last->is<LocatorPathElt::PatternMatch>())
return functionType;
}

auto *paramList = funcDecl->getParameters();
auto paramTypes = functionType->getParams();
SmallVector<AnyFunctionType::Param, 4> adjustedParamTypes;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5 -enable-experimental-feature ResultBuilderASTTransform -

// REQUIRES: objc_interop
// REQUIRES: OS=macosx

import SwiftUI

struct Person {
var fullName: String
}

enum State<Input, Output, Failure: Error> {
case success(Input, Output)
case failure(Input, Failure)
}

// Type-checker finds this overload based on
// `extension Optional : View where Wrapped : View { ... }`
extension View {
func failure(_: String) -> some View { EmptyView() }
}

struct MyTest : View {
var state: State<Person, UUID, Error>?

// `switch` has to be anchored on `AccessorDecl` to reproduce
// a crash.
var body: some View {
switch state {
case nil:
Text("nil")
case .success(let person, _), .failure(let person, _):
Text(person.fullName)
}
}
}