Skip to content

Commit eedae5a

Browse files
jopamertkremenek
authored andcommitted
When converting potential IUO bindings to optional (#2851)
ones, look through any lvalue types. Doing so can prevent improper double-optional binds, which can cause unexpected runtime behavior. (rdar://problem/26360502)
1 parent 55671fb commit eedae5a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,9 @@ static PotentialBindings getPotentialBindings(ConstraintSystem &cs,
880880
if (kind == AllowedBindingKind::Supertypes &&
881881
constraint->getKind() >= ConstraintKind::Conversion &&
882882
constraint->getKind() <= ConstraintKind::OperatorArgumentConversion) {
883+
auto innerType = type->getLValueOrInOutObjectType();
883884
if (auto objectType =
884-
cs.lookThroughImplicitlyUnwrappedOptionalType(type)) {
885+
cs.lookThroughImplicitlyUnwrappedOptionalType(innerType)) {
885886
type = OptionalType::get(objectType);
886887
alternateType = objectType;
887888
}

test/ClangModules/cvars_parse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func getPI() -> Float {
88

99
func testPointers() {
1010
let cp = globalConstPointer
11-
cp.abcde() // expected-error {{value of type 'UnsafePointer<Void>' (aka 'UnsafePointer<()>') has no member 'abcde'}}
11+
cp.abcde() // expected-error {{value of type 'UnsafePointer<Void>?' has no member 'abcde'}}
1212
let mp = globalPointer
13-
mp.abcde() // expected-error {{value of type 'UnsafeMutablePointer<Void>' (aka 'UnsafeMutablePointer<()>') has no member 'abcde'}}
13+
mp.abcde() // expected-error {{value of type 'UnsafeMutablePointer<Void>?' has no member 'abcde'}}
1414
}

0 commit comments

Comments
 (0)