Skip to content

Commit b6cb886

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 ab7f8da commit b6cb886

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
@@ -2696,7 +2696,8 @@ namespace {
26962696
// type variable and a one-way constraint to assign it to either the
26972697
// deduced type or the externally-imposed type.
26982698
Type oneWayVarType;
2699-
if (bindPatternVarsOneWay) {
2699+
if (CS.getASTContext().TypeCheckerOpts.DisableOptimizedRestrictions &&
2700+
bindPatternVarsOneWay) {
27002701
oneWayVarType = CS.createTypeVariable(
27012702
CS.getConstraintLocator(locator), TVO_CanBindToNoEscape);
27022703

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)