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 @@ -1669,7 +1669,11 @@ class Solution {
1669
1669
Type getContextualType (ASTNode anchor) const {
1670
1670
for (const auto &entry : contextualTypes) {
1671
1671
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);
1673
1677
}
1674
1678
}
1675
1679
return Type ();
Original file line number Diff line number Diff line change @@ -4335,7 +4335,15 @@ static bool diagnoseAmbiguityWithContextualType(
4335
4335
auto name = result->choices .front ().getName ();
4336
4336
auto contextualTy = solution.getContextualType (anchor);
4337
4337
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 ;
4339
4347
4340
4348
DE.diagnose (getLoc (anchor),
4341
4349
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