Skip to content

Commit b4c5bba

Browse files
committed
Sema: Don't generate OneWayEqual constraints for pattern bindings
I had to revert #78301 to fix rdar://143338891. This now brings back the change, but without deleting code; instead, it's guarded by the -disable-optimized-restrictions flag. Once the flag is removed, I will once again completely delete OneWayEqual constraints.
1 parent eea62b1 commit b4c5bba

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2704,7 +2704,8 @@ namespace {
27042704
// type variable and a one-way constraint to assign it to either the
27052705
// deduced type or the externally-imposed type.
27062706
Type oneWayVarType;
2707-
if (bindPatternVarsOneWay) {
2707+
if (CS.getASTContext().TypeCheckerOpts.DisableOptimizedRestrictions &&
2708+
bindPatternVarsOneWay) {
27082709
oneWayVarType = CS.createTypeVariable(
27092710
CS.getConstraintLocator(locator), TVO_CanBindToNoEscape);
27102711

test/expr/closure/closures_swift6.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,18 @@ class TestGithubIssue70089 {
501501
}
502502

503503
doVoidStuff { [weak self] in
504-
doVoidStuff { [self] in
505-
x += 1 // expected-error {{explicit use of 'self' is required when 'self' is optional, to make control flow explicit}} expected-note{{reference 'self?.' explicitly}}
504+
doVoidStuff { [self] in // expected-error {{value of optional type 'TestGithubIssue70089?' must be unwrapped to a value of type 'TestGithubIssue70089'}}
505+
// expected-note@-1 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
506+
// expected-note@-2 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
507+
x += 1
506508
}
507509
}
508510

509511
doVoidStuff { [weak self] in
510-
doVoidStuff { [self] in
511-
self.x += 1 // expected-error {{value of optional type 'TestGithubIssue70089?' must be unwrapped to refer to member 'x' of wrapped base type 'TestGithubIssue70089'}} expected-note {{chain the optional using '?' to access member 'x' only for non-'nil' base values}} expected-note{{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
512+
doVoidStuff { [self] in // expected-error {{value of optional type 'TestGithubIssue70089?' must be unwrapped to a value of type 'TestGithubIssue70089'}}
513+
// expected-note@-1 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
514+
// expected-note@-2 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
515+
self.x += 1
512516
}
513517
}
514518

0 commit comments

Comments
 (0)