Skip to content

[5.9][CSSyntaticElement] Desugar types before collecting "in scope" type v… #65049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/Sema/CSSyntacticElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ class TypeVariableRefFinder : public ASTWalker {
return;
}

// Desugar type before collecting type variables, otherwise
// we can bring in scope unrelated type variables passed
// into the closure (via parameter/result) from contextual type.
// For example `Typealias<$T, $U>.Context` which desugars into
// `_Context<$U>` would bring in `$T` that could be inferrable
// only after the body of the closure is solved.
type = type->getDesugaredType();

// Don't walk into the opaque archetypes because they are not
// transparent in this context - `some P` could reference a
// type variables as substitutions which are visible only to
Expand Down
51 changes: 51 additions & 0 deletions validation-test/Sema/SwiftUI/rdar107835060.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5 -disable-availability-checking

// REQUIRES: objc_interop
// REQUIRES: OS=macosx

import SwiftUI

protocol Model<ReturnType> {
associatedtype ReturnType
}

struct AnyModel<ReturnType>: Model {
}

protocol ContentProtocol : View {
associatedtype _Context
}

struct CollectionContext<Data: RandomAccessCollection> {
let offset: Data.Index
}

struct ContinuousContent<Data: RandomAccessCollection, Content: View> : ContentProtocol
where Data.Element: Model, Data.Element.ReturnType: Sequence, Data.Index: Hashable {

typealias _Context = CollectionContext<Data>

var body: some View { EmptyView() }
}

struct TestView<Data, Content: View> : View {
typealias Context = Content._Context where Content: ContentProtocol

init<R, C>(_ data: Data,
@ViewBuilder shelfContent: @escaping (Context) -> C)
where Data.Element == any Model<R>,
Content == ContinuousContent<LazyMapCollection<Data, AnyModel<R>>, C> {
}

var body: some View { EmptyView() }
}

@ViewBuilder
func test(values: [any Model<[Int]>]) -> some View {
TestView(values) { context in
VStack {
if context.offset == 0 {
}
}
}
}