Skip to content

Commit 6b5564c

Browse files
authored
Merge pull request swiftlang#40110 from xedin/rdar-85166519
[Diagnostics] Don't assume that contextual type for optional chain is optional
2 parents 658de80 + c4b3f86 commit 6b5564c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4060,7 +4060,7 @@ bool ConstraintSystem::repairFailures(
40604060
// optionality if needed.
40614061
auto contextualTy = simplifyType(rhs)->getOptionalObjectType();
40624062
if (!lhs->getOptionalObjectType() && !lhs->hasTypeVariable() &&
4063-
!contextualTy->isTypeVariableOrMember()) {
4063+
contextualTy && !contextualTy->isTypeVariableOrMember()) {
40644064
conversionsOrFixes.push_back(IgnoreContextualType::create(
40654065
*this, lhs, rhs, getConstraintLocator(OEE->getSubExpr())));
40664066
return true;

test/Constraints/optional.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,13 @@ func rdar75514153() {
499499
test_labeled(42, x: nil) // expected-error {{no exact matches in call to local function 'test_labeled'}}
500500
test_labeled(42, x: (nil)) // expected-error {{no exact matches in call to local function 'test_labeled'}}
501501
}
502+
503+
// rdar://85166519 - Crash dereferencing Null Type In Bogus Expression
504+
func rdar85166519() {
505+
var v: Int? = nil
506+
507+
var _: [Int: AnyObject] = [ // expected-error {{dictionary of type '[Int : AnyObject]' cannot be initialized with array literal}}
508+
// expected-note@-1 {{did you mean to use a dictionary literal instead?}}
509+
v?.addingReportingOverflow(0) // expected-error {{cannot convert value of type '(partialValue: Int, overflow: Bool)?' to expected dictionary key type 'Int'}}
510+
]
511+
}

0 commit comments

Comments
 (0)