Skip to content

Commit 4a43ee8

Browse files
authored
Merge pull request swiftlang#18770 from rjmccall/select-bind-constraint-fix
Simplify to a common type variable when picking a disjunction of bindings
2 parents 96e1edb + f6d933b commit 4a43ee8

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,26 +1860,29 @@ static Constraint *selectBestBindingDisjunction(
18601860
// type variable.
18611861
SmallVector<Constraint *, 8> bindingDisjunctions;
18621862
for (auto *disjunction : disjunctions) {
1863-
llvm::Optional<TypeVariableType *> commonTypeVariable;
1863+
TypeVariableType *commonTypeVariable = nullptr;
18641864
if (llvm::all_of(
18651865
disjunction->getNestedConstraints(),
18661866
[&](Constraint *bindingConstraint) {
18671867
if (bindingConstraint->getKind() != ConstraintKind::Bind)
18681868
return false;
18691869

1870-
auto *tv =
1871-
bindingConstraint->getFirstType()->getAs<TypeVariableType>();
1870+
auto *tv = cs.simplifyType(bindingConstraint->getFirstType())
1871+
->getRValueType()
1872+
->getAs<TypeVariableType>();
18721873
// Only do this for simple type variable bindings, not for
18731874
// bindings like: ($T1) -> $T2 bind String -> Int
18741875
if (!tv)
18751876
return false;
18761877

1877-
if (!commonTypeVariable.hasValue())
1878-
commonTypeVariable = tv;
1879-
1880-
if (commonTypeVariable.getValue() != tv)
1878+
// If we've seen a variable before, make sure that this is
1879+
// the same one.
1880+
if (commonTypeVariable == tv)
1881+
return true;
1882+
if (commonTypeVariable)
18811883
return false;
18821884

1885+
commonTypeVariable = tv;
18831886
return true;
18841887
})) {
18851888
bindingDisjunctions.push_back(disjunction);

test/Sema/generalized_accessors.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,11 @@ struct Modify {
104104
nonmutating set {} // expected-note {{setter defined here}}
105105
}
106106
}
107+
108+
struct ImplicitlyUnwrapped {
109+
var x: Int!
110+
var y: Int? {
111+
_read { yield x }
112+
_modify { yield &x }
113+
}
114+
}

0 commit comments

Comments
 (0)