Skip to content

Commit 7a0b895

Browse files
authored
Merge pull request swiftlang#25904 from xedin/dont-fix-wrapper-if-generic-args-didnt-line-up
[ConstraintSystem] Don't try fixes while matching types for property …
2 parents cb97132 + f7913f8 commit 7a0b895

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,9 +2241,14 @@ bool ConstraintSystem::repairFailures(
22412241
*this, lhs, anchor, loc,
22422242
[&](ResolvedOverloadSetListItem *overload, VarDecl *decl,
22432243
Type newBase) {
2244-
return matchTypes(newBase, rhs, ConstraintKind::Subtype,
2245-
TypeMatchFlags::TMF_ApplyingFix,
2246-
overload->Locator)
2244+
// FIXME: There is currently no easy way to avoid attempting
2245+
// fixes, matchTypes do not propagate `TMF_ApplyingFix` flag.
2246+
llvm::SaveAndRestore<ConstraintSystemOptions> options(
2247+
Options, Options - ConstraintSystemFlags::AllowFixes);
2248+
2249+
TypeMatchOptions flags;
2250+
return matchTypes(newBase, rhs, ConstraintKind::Subtype, flags,
2251+
getConstraintLocator(locator))
22472252
.isSuccess();
22482253
},
22492254
rhs)) {

test/decl/var/property_wrappers.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ struct TestComposition {
932932
// Missing Property Wrapper Unwrap Diagnostics
933933
// ---------------------------------------------------------------------------
934934
@propertyWrapper
935-
struct Foo<T> {
935+
struct Foo<T> { // expected-note {{arguments to generic parameter 'T' ('W' and 'Int') are expected to be equal}}
936936
var wrappedValue: T
937937

938938
var prop: Int = 42
@@ -987,6 +987,7 @@ struct MissingPropertyWrapperUnwrap {
987987
func b(_: Foo<Int>) {}
988988
func c(_: V) {}
989989
func d(_: W) {}
990+
func e(_: Foo<W>) {}
990991

991992
func baz() {
992993
self.x.foo() // expected-error {{referencing instance method 'foo()' requires wrapper 'Foo<Int>'}}{{10-10=_}}
@@ -1005,7 +1006,10 @@ struct MissingPropertyWrapperUnwrap {
10051006

10061007
a(self.w) // expected-error {{cannot convert value 'w' of type 'W' to expected type 'Foo<W>', use wrapper instead}}{{12-12=_}}
10071008
b(self.x) // expected-error {{cannot convert value 'x' of type 'Int' to expected type 'Foo<Int>', use wrapper instead}}{{12-12=_}}
1008-
b(self.w) // expected-error {{cannot convert value 'w' of type 'W' to expected type 'Foo<Int>', use wrapper instead}}{{12-12=_}}
1009+
b(self.w) // expected-error {{cannot convert value of type 'W' to expected argument type 'Foo<Int>'}}
1010+
e(self.w) // expected-error {{cannot convert value 'w' of type 'W' to expected type 'Foo<W>', use wrapper instead}}{{12-12=_}}
1011+
b(self._w) // expected-error {{cannot convert value of type 'Foo<W>' to expected argument type 'Foo<Int>'}}
1012+
10091013
c(self.usesProjectedValue) // expected-error {{cannot convert value 'usesProjectedValue' of type 'W' to expected type 'V', use wrapper instead}}{{12-12=$}}
10101014
d(self.$usesProjectedValue) // expected-error {{cannot convert value '$usesProjectedValue' of type 'V' to expected type 'W', use wrapped value instead}}{{12-13=}}
10111015
d(self._usesProjectedValue) // expected-error {{cannot convert value '_usesProjectedValue' of type 'Baz<W>' to expected type 'W', use wrapped value instead}}{{12-13=}}

0 commit comments

Comments
 (0)