File tree Expand file tree Collapse file tree 3 files changed +52
-10
lines changed
validation-test/Sema/SwiftUI Expand file tree Collapse file tree 3 files changed +52
-10
lines changed Original file line number Diff line number Diff line change @@ -693,9 +693,9 @@ class BuilderClosureRewriter
693
693
declRef->setType (LValueType::get (temporaryVar->getType ()));
694
694
695
695
// Load the right-hand side if needed.
696
- if (finalCapturedExpr->getType ()->is <LValueType> ()) {
697
- auto &cs = solution. getConstraintSystem ();
698
- finalCapturedExpr = cs. addImplicitLoadExpr (finalCapturedExpr);
696
+ if (finalCapturedExpr->getType ()->hasLValueType ()) {
697
+ finalCapturedExpr =
698
+ TypeChecker:: addImplicitLoadExpr (ctx, finalCapturedExpr);
699
699
}
700
700
701
701
auto assign = new (ctx) AssignExpr (
@@ -839,9 +839,8 @@ class BuilderClosureRewriter
839
839
auto finalCondExpr = rewriteExpr (condExpr);
840
840
841
841
// Load the condition if needed.
842
- if (finalCondExpr->getType ()->is <LValueType>()) {
843
- auto &cs = solution.getConstraintSystem ();
844
- finalCondExpr = cs.addImplicitLoadExpr (finalCondExpr);
842
+ if (finalCondExpr->getType ()->hasLValueType ()) {
843
+ finalCondExpr = TypeChecker::addImplicitLoadExpr (ctx, finalCondExpr);
845
844
}
846
845
847
846
condElement.setBoolean (finalCondExpr);
Original file line number Diff line number Diff line change @@ -1074,10 +1074,13 @@ class TypeChecker final {
1074
1074
// / more complicated than simplify wrapping given root in newly created
1075
1075
// / `LoadExpr`, because `ForceValueExpr` and `ParenExpr` supposed to appear
1076
1076
// / only at certain positions in AST.
1077
- static Expr *
1078
- addImplicitLoadExpr (ASTContext &Context, Expr *expr,
1079
- std::function<Type(Expr *)> getType,
1080
- std::function<void (Expr *, Type)> setType);
1077
+ static Expr *addImplicitLoadExpr (ASTContext &Context, Expr *expr,
1078
+ std::function<Type(Expr *)> getType =
1079
+ [](Expr *E) { return E->getType (); },
1080
+ std::function<void (Expr *, Type)> setType =
1081
+ [](Expr *E, Type type) {
1082
+ E->setType (type);
1083
+ });
1081
1084
1082
1085
// / Determine whether the given type contains the given protocol.
1083
1086
// /
Original file line number Diff line number Diff line change
1
+ // RUN: %target-swift-frontend %s -target x86_64-apple-macosx10.15 -emit-sil -verify
2
+ // REQUIRES: objc_interop
3
+ // REQUIRES: OS=macosx
4
+
5
+ import SwiftUI
6
+ import Combine
7
+
8
+ struct A : View {
9
+ var body : some View {
10
+ Spacer ( )
11
+ }
12
+ }
13
+
14
+ struct B : View {
15
+ var body : some View {
16
+ Spacer ( )
17
+ }
18
+ }
19
+
20
+ class Context : ObservableObject {
21
+ @State var flag : Bool
22
+
23
+ init ( ) {
24
+ self . flag = false
25
+ }
26
+ }
27
+
28
+ struct S : View {
29
+ @EnvironmentObject var context : Context
30
+
31
+ var body : some View {
32
+ VStack {
33
+ if ( context. flag) { // Ok (shouldn't trip SIL Verifier)
34
+ A ( )
35
+ } else {
36
+ B ( )
37
+ }
38
+ }
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments