Skip to content

Commit 194741e

Browse files
committed
[ConstraintSystem] Allow LValues for the bindings of an IUO @optional requirement.
We were failing to bind the alternatives for an IUO @optional requirement because we forgot to set the appropriate type variable option. Fixes: rdar://problem/40868990 (cherry picked from commit 803fbee)
1 parent 6681a13 commit 194741e

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
17261726
if (choice.isImplicitlyUnwrappedValueOrReturnValue()) {
17271727
// Build the disjunction to attempt binding both T? and T (or
17281728
// function returning T? and function returning T).
1729-
Type ty = createTypeVariable(locator);
1729+
Type ty = createTypeVariable(locator, TVO_CanBindToLValue);
17301730
buildDisjunctionForImplicitlyUnwrappedOptional(ty, refType, locator);
17311731
addConstraint(ConstraintKind::Bind, boundType,
17321732
OptionalType::get(ty->getRValueType()), locator);

test/Constraints/iuo_objc.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,14 @@ func iuo_error(prop: IUOProperty) {
2828
// expected-error@-1 {{cannot invoke 'optional' with no arguments}}
2929
let _: Coat = prop.iuo!.optional!()
3030
let _: Coat = prop.iuo!.optional!()!
31+
32+
let _ = prop.iuo.name
33+
}
34+
35+
protocol X {}
36+
37+
extension X where Self : OptionalRequirements {
38+
func test() {
39+
let _ = self.name
40+
}
3141
}

test/Inputs/clang-importer-sdk/usr/include/Foundation.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,11 +1153,12 @@ void takeNullableId(__nullable id);
11531153
@interface I
11541154
@end
11551155

1156-
@protocol OptionalMethods
1156+
@protocol OptionalRequirements
11571157
@optional
11581158
- (Coat *)optional;
1159+
@property NSString *name;
11591160
@end
11601161

11611162
@interface IUOProperty
1162-
@property (readonly) id<OptionalMethods> iuo;
1163+
@property (readonly) id<OptionalRequirements> iuo;
11631164
@end

0 commit comments

Comments
 (0)