Skip to content

Commit 803fbee

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
1 parent 9ffda06 commit 803fbee

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
@@ -1763,7 +1763,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
17631763
if (choice.isImplicitlyUnwrappedValueOrReturnValue()) {
17641764
// Build the disjunction to attempt binding both T? and T (or
17651765
// function returning T? and function returning T).
1766-
Type ty = createTypeVariable(locator);
1766+
Type ty = createTypeVariable(locator, TVO_CanBindToLValue);
17671767
buildDisjunctionForImplicitlyUnwrappedOptional(ty, refType, locator);
17681768
addConstraint(ConstraintKind::Bind, boundType,
17691769
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
@@ -1158,11 +1158,12 @@ void takeNullableId(_Nullable id);
11581158
@interface I
11591159
@end
11601160

1161-
@protocol OptionalMethods
1161+
@protocol OptionalRequirements
11621162
@optional
11631163
- (Coat *)optional;
1164+
@property NSString *name;
11641165
@end
11651166

11661167
@interface IUOProperty
1167-
@property (readonly) id<OptionalMethods> iuo;
1168+
@property (readonly) id<OptionalRequirements> iuo;
11681169
@end

0 commit comments

Comments
 (0)