Skip to content

Commit da39eec

Browse files
authored
Merge pull request #26602 from omochi/fix-lvalue-constrain
[Sema] Fix lvalue-ness control in matchTypesBindTypeVar
2 parents 9d1470d + 47a254b commit da39eec

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,8 @@ namespace {
10601060

10611061
// Add the member constraint for a subscript declaration.
10621062
// FIXME: weak name!
1063-
auto memberTy = CS.createTypeVariable(memberLocator, TVO_CanBindToNoEscape);
1063+
auto memberTy = CS.createTypeVariable(
1064+
memberLocator, TVO_CanBindToLValue | TVO_CanBindToNoEscape);
10641065

10651066
// FIXME: synthesizeMaterializeForSet() wants to statically dispatch to
10661067
// a known subscript here. This might be cleaner if we split off a new

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,12 +2059,12 @@ ConstraintSystem::matchTypesBindTypeVar(
20592059
type.visit([&](Type t) {
20602060
if (auto *tvt = dyn_cast<TypeVariableType>(t.getPointer())) {
20612061
if (!typeVar->getImpl().canBindToLValue()) {
2062-
typeVar->getImpl().setCanBindToLValue(getSavedBindings(),
2063-
/*enabled=*/false);
2062+
tvt->getImpl().setCanBindToLValue(getSavedBindings(),
2063+
/*enabled=*/false);
20642064
}
20652065
if (!typeVar->getImpl().canBindToNoEscape()) {
2066-
typeVar->getImpl().setCanBindToNoEscape(getSavedBindings(),
2067-
/*enabled=*/false);
2066+
tvt->getImpl().setCanBindToNoEscape(getSavedBindings(),
2067+
/*enabled=*/false);
20682068
}
20692069
}
20702070
});

test/attr/attr_dynamic_member_lookup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ struct WithTrailingClosure {
619619

620620
func keypath_with_trailing_closure_subscript(_ ty: inout SubscriptLens<WithTrailingClosure>) {
621621
_ = ty[0] { 42 } // expected-error {{subscript index of type '() -> Int' in a key path must be Hashable}}
622-
_ = ty[0] { 42 } = 0
622+
_ = ty[0] { 42 } = 0 // expected-error {{cannot assign through subscript: subscript is get-only}}
623623
// expected-error@-1 {{subscript index of type '() -> Int' in a key path must be Hashable}}
624624
_ = ty[] { 42 } // expected-error {{subscript index of type '() -> Int' in a key path must be Hashable}}
625625
_ = ty[] { 42 } = 0 // expected-error {{subscript index of type '() -> Int' in a key path must be Hashable}}

0 commit comments

Comments
 (0)