File tree Expand file tree Collapse file tree 2 files changed +75
-0
lines changed
validation-test/Sema/SwiftUI Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -1005,6 +1005,12 @@ bool ConstraintSystem::isInResultBuilderContext(ClosureExpr *closure) const {
10051005 if (!closure->hasSingleExpressionBody ()) {
10061006 auto *DC = closure->getParent ();
10071007 do {
1008+ // Result builder is applied to a function/getter body.
1009+ if (auto *AFD = dyn_cast<AbstractFunctionDecl>(DC)) {
1010+ if (resultBuilderTransformed.count (AFD))
1011+ return true ;
1012+ }
1013+
10081014 if (auto *parentClosure = dyn_cast<ClosureExpr>(DC)) {
10091015 if (resultBuilderTransformed.count (parentClosure))
10101016 return true ;
Original file line number Diff line number Diff line change 1+ // RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5
2+ // REQUIRES: objc_interop
3+ // REQUIRES: OS=macosx
4+
5+ import SwiftUI
6+ import Foundation
7+
8+ protocol P {
9+ var info : Info ? { get }
10+ }
11+
12+ protocol Q : P {
13+ func makeView( ) -> AnyView
14+ }
15+
16+ struct Info {
17+ var kind : Kind
18+
19+ var size : CGSize { fatalError ( ) }
20+ }
21+
22+ enum Kind {
23+ case supported( [ Int ] )
24+ case unsupported
25+ }
26+
27+ struct Settings {
28+ var setting = Setting . defaultValue
29+ }
30+
31+ struct Setting {
32+ static let defaultValue = Setting ( )
33+
34+ func scale( _: CGFloat ) -> Setting {
35+ fatalError ( )
36+ }
37+
38+ func scale( _: CGSize ) -> CGSize {
39+ fatalError ( )
40+ }
41+ }
42+
43+ struct Test : View {
44+ var res : P
45+ var enable : Bool
46+ var settings : Settings
47+
48+ var body : some View {
49+ if let result = res as? Q {
50+ let view = result. makeView ( )
51+
52+ if let info = result. info {
53+ let show : Bool = {
54+ guard enable else { return false }
55+
56+ switch info. kind {
57+ case . supported: return true
58+ case . unsupported: return false
59+ }
60+ } ( )
61+
62+ if show {
63+ let size = settings. setting. scale ( info. size)
64+ view. frame ( width: size. width, height: size. height)
65+ }
66+ }
67+ }
68+ }
69+ }
You can’t perform that action at this time.
0 commit comments