Skip to content

Commit 0482af2

Browse files
authored
Merge pull request #62843 from xedin/rdar-103739206-5.8
[5.8][Diagnostics] Relax contextual type presence from assertion to a check
2 parents 7a8eb60 + 815a92f commit 0482af2

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,11 @@ class Solution {
16691669
Type getContextualType(ASTNode anchor) const {
16701670
for (const auto &entry : contextualTypes) {
16711671
if (entry.first == anchor) {
1672-
return simplifyType(entry.second.getType());
1672+
// The contextual information record could contain the purpose
1673+
// without a type i.e. when the context is an optional-some or
1674+
// an invalid pattern binding.
1675+
if (auto contextualTy = entry.second.getType())
1676+
return simplifyType(contextualTy);
16731677
}
16741678
}
16751679
return Type();

lib/Sema/ConstraintSystem.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4335,7 +4335,15 @@ static bool diagnoseAmbiguityWithContextualType(
43354335
auto name = result->choices.front().getName();
43364336
auto contextualTy = solution.getContextualType(anchor);
43374337

4338-
assert(contextualTy);
4338+
// In some situations `getContextualType` for a contextual type
4339+
// locator is going to return then empty type. This happens because
4340+
// e.g. optional-some patterns and patterns with incorrect type don't
4341+
// have a contextual type for initialization expression but use
4342+
// a conversion with contextual locator nevertheless to indicate
4343+
// the purpose. This doesn't affect non-ambiguity diagnostics
4344+
// because mismatches carry both `from` and `to` types.
4345+
if (!contextualTy)
4346+
return false;
43394347

43404348
DE.diagnose(getLoc(anchor),
43414349
contextualTy->is<ProtocolType>()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: not %target-swift-frontend %s -typecheck
2+
3+
protocol RawTokenKindSubset {}
4+
5+
struct Parser {
6+
func canRecoverTo<Subset: RawTokenKindSubset>(anyIn subset: Subset.Type) {
7+
if let (kind, handle) = self.at(anyIn: subset) {
8+
}
9+
}
10+
11+
func at(_ keyword: Int) -> Bool {}
12+
13+
func at(
14+
<<<<<<< HEAD (Note: diff markers are required for reproduction of the crash)
15+
) -> Bool {
16+
=======
17+
) -> Bool {
18+
>>>>>>> My commit message (don't remove)
19+
}
20+
}

0 commit comments

Comments
 (0)