File tree Expand file tree Collapse file tree 3 files changed +34
-2
lines changed
validation-test/Sema/type_checker_crashers_fixed Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -1676,7 +1676,11 @@ class Solution {
1676
1676
Type getContextualType (ASTNode anchor) const {
1677
1677
for (const auto &entry : contextualTypes) {
1678
1678
if (entry.first == anchor) {
1679
- return simplifyType (entry.second .getType ());
1679
+ // The contextual information record could contain the purpose
1680
+ // without a type i.e. when the context is an optional-some or
1681
+ // an invalid pattern binding.
1682
+ if (auto contextualTy = entry.second .getType ())
1683
+ return simplifyType (contextualTy);
1680
1684
}
1681
1685
}
1682
1686
return Type ();
Original file line number Diff line number Diff line change @@ -4372,7 +4372,15 @@ static bool diagnoseAmbiguityWithContextualType(
4372
4372
auto name = result->choices .front ().getName ();
4373
4373
auto contextualTy = solution.getContextualType (anchor);
4374
4374
4375
- assert (contextualTy);
4375
+ // In some situations `getContextualType` for a contextual type
4376
+ // locator is going to return then empty type. This happens because
4377
+ // e.g. optional-some patterns and patterns with incorrect type don't
4378
+ // have a contextual type for initialization expression but use
4379
+ // a conversion with contextual locator nevertheless to indicate
4380
+ // the purpose. This doesn't affect non-ambiguity diagnostics
4381
+ // because mismatches carry both `from` and `to` types.
4382
+ if (!contextualTy)
4383
+ return false ;
4376
4384
4377
4385
DE.diagnose (getLoc (anchor),
4378
4386
contextualTy->is <ProtocolType>()
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments