Skip to content

Commit 8b5e384

Browse files
committed
[CSSimplify] Fix handling of holes by OptionalObject constraint
When "optional type" is a hole the simplification logic has to simplify "object type" and mark all of its unresolved components are potential holes, otherwise hole propagation won't work since sometimes there is no other contextual information for such types but "optional type". Resolves: rdar://117871338
1 parent b74e4a2 commit 8b5e384

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9184,8 +9184,8 @@ ConstraintSystem::simplifyOptionalObjectConstraint(
91849184
}
91859185

91869186
if (optTy->isPlaceholder()) {
9187-
if (auto *typeVar = second->getAs<TypeVariableType>())
9188-
recordPotentialHole(typeVar);
9187+
// object type should be simplified because it could be already bound.
9188+
recordAnyTypeVarAsPotentialHole(simplifyType(second));
91899189
return SolutionKind::Solved;
91909190
}
91919191

test/stmt/switch_stmt2.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,25 @@ func fallthrough_not_last(i: Int) {
150150
break
151151
}
152152
}
153+
154+
// rdar://117871338 - incorrect diagnostic - type of expression is ambiguous when member is missing.
155+
func test_invalid_optional_chaining() {
156+
func test(_: (E) -> Void) {
157+
}
158+
159+
enum E {
160+
case a
161+
case b
162+
}
163+
164+
struct S {
165+
var prop: E
166+
}
167+
168+
test {
169+
switch $0.prop? { // expected-error {{value of type 'E' has no member 'prop'}}
170+
case .a: break
171+
case .b: break
172+
}
173+
}
174+
}

0 commit comments

Comments
 (0)