Skip to content

Commit bc94cba

Browse files
authored
Merge pull request #12452 from gregomni/6106
[Sema] Crash fix for key path for an optional chain to optional lvalue.
2 parents b62704b + 0188e1c commit bc94cba

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4172,7 +4172,7 @@ namespace {
41724172
if (didOptionalChain &&
41734173
baseTy &&
41744174
!baseTy->hasUnresolvedType() &&
4175-
!baseTy->isEqual(leafTy)) {
4175+
!baseTy->getWithoutSpecifierType()->isEqual(leafTy)) {
41764176
assert(leafTy->getAnyOptionalObjectType()
41774177
->isEqual(baseTy->getWithoutSpecifierType()));
41784178
auto component = KeyPathExpr::Component::forOptionalWrap(leafTy);

test/expr/unary/keypath/keypath.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,20 @@ func testImplicitConversionInSubscriptIndex() {
434434
_ = \BassSubscript.["hello"] // expected-error{{must be Hashable}}
435435
}
436436

437+
// SR-6106
438+
func sr6106() {
439+
class B {}
440+
class A {
441+
var b: B? = nil
442+
}
443+
class C {
444+
var a: A?
445+
func myFunc() {
446+
let _ = \C.a?.b
447+
}
448+
}
449+
}
450+
437451
func testSyntaxErrors() { // expected-note{{}}
438452
_ = \. ; // expected-error{{expected member name following '.'}}
439453
_ = \.a ;

0 commit comments

Comments
 (0)