Skip to content

Commit 62bc0ea

Browse files
Merge pull request #63145 from LucianoPAlmeida/nil-placeholders
[Sema] Record specify contextual type for nil in placeholder context
2 parents a0ee5c5 + 6e17e7b commit 62bc0ea

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,14 @@ TypeVariableBinding::fixForHole(ConstraintSystem &cs) const {
21472147
}
21482148

21492149
if (srcLocator->isLastElement<LocatorPathElt::PlaceholderType>()) {
2150+
// When a 'nil' has a placeholder as contextual type there is not enough
2151+
// information to resolve it, so let's record a specify contextual type for
2152+
// nil fix.
2153+
if (isExpr<NilLiteralExpr>(srcLocator->getAnchor())) {
2154+
ConstraintFix *fix = SpecifyContextualTypeForNil::create(cs, dstLocator);
2155+
return std::make_pair(fix, /*impact=*/(unsigned)10);
2156+
}
2157+
21502158
ConstraintFix *fix = SpecifyTypeForPlaceholder::create(cs, srcLocator);
21512159
return std::make_pair(fix, defaultImpact);
21522160
}

test/Sema/placeholder_type.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,7 @@ func deferredInit(_ c: Bool) {
266266
x = "Goodbye"
267267
}
268268
}
269+
270+
// https://github.com/apple/swift/issues/63130
271+
let _: _ = nil // expected-error{{'nil' requires a contextual type}}
272+
let _: _? = nil // expected-error{{'nil' requires a contextual type}}

0 commit comments

Comments
 (0)