Skip to content

Commit 66b1149

Browse files
committed
[CSGen] Don't apply one-way requirement to typed patterns
Typed patterns are represented by a name and a fixed contextual type, let's not use intermediary type variable and one-way constraint as its type because that variable would be bound right away to contextual type. Also setting type of a variable declaration to a type variable when contextual type is IUO doesn't play well with overload resolution because it expects an optional type for declarations with IUO attribute. Resolves: rdar://80271666
1 parent 191dc14 commit 66b1149

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2246,7 +2246,7 @@ namespace {
22462246
Type subPatternType = getTypeForPattern(
22472247
subPattern,
22482248
locator.withPathElement(LocatorPathElt::PatternMatch(subPattern)),
2249-
openedType, bindPatternVarsOneWay);
2249+
openedType, /*bindPatternVarsOneWay*/false);
22502250

22512251
if (!subPatternType)
22522252
return Type();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5
2+
3+
// REQUIRES: OS=macosx
4+
5+
enum Category {
6+
case first
7+
}
8+
9+
protocol View {}
10+
11+
extension View {
12+
func test(_ tag: Category) -> some View {
13+
Image()
14+
}
15+
}
16+
17+
@resultBuilder struct ViewBuilder {
18+
static func buildBlock<Content>(_ content: Content) -> Content where Content : View { fatalError() }
19+
}
20+
21+
struct Image : View {
22+
}
23+
24+
struct MyView {
25+
@ViewBuilder var body: some View {
26+
let icon: Category! = Category.first // expected-error {{using '!' is not allowed here; perhaps '?' was intended?}} {{23-24=?}}
27+
Image().test(icon)
28+
}
29+
}

0 commit comments

Comments
 (0)