Skip to content

[CSFix] Allow invalid property wrapper type to be diagnosed in ambi… #69617

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
Nov 3, 2023
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
4 changes: 4 additions & 0 deletions include/swift/Sema/CSFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,10 @@ class AllowInvalidPropertyWrapperType final : public ConstraintFix {
return "allow invalid property wrapper type";
}

bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
return diagnose(*commonFixes.front().first);
}

bool diagnose(const Solution &solution, bool asNote = false) const override;

static bool classof(const ConstraintFix *fix) {
Expand Down
12 changes: 12 additions & 0 deletions test/Sema/property_wrapper_parameter_invalid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,15 @@ func testInvalidWrapperInference() {
// expected-error@+1 {{contextual closure type '() -> Void' expects 0 arguments, but 1 was used in closure body}}
testExtraParameter { $value in }
}

// rdar://116522161 - failed to produce a diagnostic on invalid projection use
func testInvalidProjectionInAmbiguousContext() {
func test<T>(_: [T], _: (T) -> Void) {}

func ambiguous() -> Int { 42 }
func ambiguous() -> String { "" }

test([42]) { $v in // expected-error {{inferred projection type 'Int' is not a property wrapper}}
ambiguous()
}
}