Skip to content

Commit 6b3a17b

Browse files
authored
Merge pull request #65048 from xedin/rdar-107835060
[CSSyntaticElement] Desugar types before collecting "in scope" type v…
2 parents bb2fc82 + ca14ab7 commit 6b3a17b

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

lib/Sema/CSSyntacticElement.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ class TypeVariableRefFinder : public ASTWalker {
211211
return;
212212
}
213213

214+
// Desugar type before collecting type variables, otherwise
215+
// we can bring in scope unrelated type variables passed
216+
// into the closure (via parameter/result) from contextual type.
217+
// For example `Typealias<$T, $U>.Context` which desugars into
218+
// `_Context<$U>` would bring in `$T` that could be inferrable
219+
// only after the body of the closure is solved.
220+
type = type->getDesugaredType();
221+
214222
// Don't walk into the opaque archetypes because they are not
215223
// transparent in this context - `some P` could reference a
216224
// type variables as substitutions which are visible only to
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5 -disable-availability-checking
2+
3+
// REQUIRES: objc_interop
4+
// REQUIRES: OS=macosx
5+
6+
import SwiftUI
7+
8+
protocol Model<ReturnType> {
9+
associatedtype ReturnType
10+
}
11+
12+
struct AnyModel<ReturnType>: Model {
13+
}
14+
15+
protocol ContentProtocol : View {
16+
associatedtype _Context
17+
}
18+
19+
struct CollectionContext<Data: RandomAccessCollection> {
20+
let offset: Data.Index
21+
}
22+
23+
struct ContinuousContent<Data: RandomAccessCollection, Content: View> : ContentProtocol
24+
where Data.Element: Model, Data.Element.ReturnType: Sequence, Data.Index: Hashable {
25+
26+
typealias _Context = CollectionContext<Data>
27+
28+
var body: some View { EmptyView() }
29+
}
30+
31+
struct TestView<Data, Content: View> : View {
32+
typealias Context = Content._Context where Content: ContentProtocol
33+
34+
init<R, C>(_ data: Data,
35+
@ViewBuilder shelfContent: @escaping (Context) -> C)
36+
where Data.Element == any Model<R>,
37+
Content == ContinuousContent<LazyMapCollection<Data, AnyModel<R>>, C> {
38+
}
39+
40+
var body: some View { EmptyView() }
41+
}
42+
43+
@ViewBuilder
44+
func test(values: [any Model<[Int]>]) -> some View {
45+
TestView(values) { context in
46+
VStack {
47+
if context.offset == 0 {
48+
}
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)