Skip to content

Commit 956e918

Browse files
authored
[CSSimplify] Move property wrapper fix check after check for conversion restrictions (swiftlang#30129)
1 parent e8dfdf3 commit 956e918

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,6 +2542,9 @@ static ConstraintFix *fixPropertyWrapperFailure(
25422542
if (baseTy->isEqual(type))
25432543
return nullptr;
25442544

2545+
if (baseTy->is<TypeVariableType>() || type->is<TypeVariableType>())
2546+
return nullptr;
2547+
25452548
if (!attemptFix(*resolvedOverload, decl, type))
25462549
return nullptr;
25472550

@@ -3286,24 +3289,6 @@ bool ConstraintSystem::repairFailures(
32863289
if (elt.getKind() != ConstraintLocator::ApplyArgToParam)
32873290
break;
32883291

3289-
if (auto *fix = fixPropertyWrapperFailure(
3290-
*this, lhs, loc,
3291-
[&](SelectedOverload overload, VarDecl *decl, Type newBase) {
3292-
// FIXME: There is currently no easy way to avoid attempting
3293-
// fixes, matchTypes do not propagate `TMF_ApplyingFix` flag.
3294-
llvm::SaveAndRestore<ConstraintSystemOptions> options(
3295-
Options, Options - ConstraintSystemFlags::AllowFixes);
3296-
3297-
TypeMatchOptions flags;
3298-
return matchTypes(newBase, rhs, ConstraintKind::Subtype, flags,
3299-
getConstraintLocator(locator))
3300-
.isSuccess();
3301-
},
3302-
rhs)) {
3303-
conversionsOrFixes.push_back(fix);
3304-
break;
3305-
}
3306-
33073292
// If argument in l-value type and parameter is `inout` or a pointer,
33083293
// let's see if it's generic parameter matches and suggest adding explicit
33093294
// `&`.
@@ -3373,6 +3358,24 @@ bool ConstraintSystem::repairFailures(
33733358
}))
33743359
break;
33753360

3361+
if (auto *fix = fixPropertyWrapperFailure(
3362+
*this, lhs, loc,
3363+
[&](SelectedOverload overload, VarDecl *decl, Type newBase) {
3364+
// FIXME: There is currently no easy way to avoid attempting
3365+
// fixes, matchTypes do not propagate `TMF_ApplyingFix` flag.
3366+
llvm::SaveAndRestore<ConstraintSystemOptions> options(
3367+
Options, Options - ConstraintSystemFlags::AllowFixes);
3368+
3369+
TypeMatchOptions flags;
3370+
return matchTypes(newBase, rhs, ConstraintKind::Subtype, flags,
3371+
getConstraintLocator(locator))
3372+
.isSuccess();
3373+
},
3374+
rhs)) {
3375+
conversionsOrFixes.push_back(fix);
3376+
break;
3377+
}
3378+
33763379
// If this is an implicit 'something-to-pointer' conversion
33773380
// it's going to be diagnosed by specialized fix which deals
33783381
// with generic argument mismatches.

test/decl/var/property_wrappers.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,3 +1880,18 @@ open class OpenPropertyWrapperWithPublicInit {
18801880

18811881
open var wrappedValue: String = "Hello, world"
18821882
}
1883+
1884+
// SR-11654
1885+
1886+
struct SR_11654_S {}
1887+
1888+
class SR_11654_C {
1889+
@Foo var property: SR_11654_S?
1890+
}
1891+
1892+
func sr_11654_generic_func<T>(_ argument: T?) -> T? {
1893+
return argument
1894+
}
1895+
1896+
let sr_11654_c = SR_11654_C()
1897+
_ = sr_11654_generic_func(sr_11654_c.property) // Okay

0 commit comments

Comments
 (0)