File tree Expand file tree Collapse file tree 2 files changed +41
-4
lines changed Expand file tree Collapse file tree 2 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 14
14
#include " swift/AST/ASTWalker.h"
15
15
#include " swift/AST/ASTNode.h"
16
16
#include " swift/AST/Decl.h"
17
+ #include " swift/AST/Expr.h"
17
18
#include " swift/Parse/Lexer.h"
18
19
19
20
#include " llvm/ADT/SmallVector.h"
@@ -92,9 +93,15 @@ struct ExtractInactiveRanges : public ASTWalker {
92
93
return false ;
93
94
}
94
95
95
- // Ignore range from beginning of '#if' to the beginning of the elements
96
- // of this clause.
97
- addRange (start, Lexer::getLocForEndOfLine (sourceMgr, clause->Loc ));
96
+ // Ignore range from beginning of '#if', '#elseif', or '#else' to the
97
+ // beginning of the elements of this clause.
98
+ auto elementsBegin = clause->Loc ;
99
+ // If there's a condition (e.g. this isn't a '#else' block), then ignore
100
+ // everything up to the end of the condition.
101
+ if (auto cond = clause->Cond ) {
102
+ elementsBegin = cond->getEndLoc ();
103
+ }
104
+ addRange (start, Lexer::getLocForEndOfLine (sourceMgr, elementsBegin));
98
105
99
106
// Ignore range from effective end of the elements of this clause to the
100
107
// end of the '#endif'
Original file line number Diff line number Diff line change @@ -69,6 +69,37 @@ public func hasClosureDefaultArgWithComplexPoundIf(_ x: () -> Void = {
69
69
} ) {
70
70
}
71
71
72
+ // CHECK: func hasClosureDefaultArgWithMultilinePoundIfCondition(_ x: () -> Void = {
73
+ // CHECK-NOT: #if (
74
+ // CHECK-NOT: !false && true
75
+ // CHECK-NOT: )
76
+ // CHECK: print("should appear")
77
+ // CHECK-NOT: #endif
78
+ // CHECK-NOT: #if (
79
+ // CHECK-NOT: !true
80
+ // CHECK-NOT: )
81
+ // CHECK-NOT: print("should not appear")
82
+ // CHECK-NOT: #else
83
+ // CHECK: print("also should appear")
84
+ // CHECK-NOT: #endif
85
+ // CHECK-NEXT: })
86
+ public func hasClosureDefaultArgWithMultilinePoundIfCondition( _ x: ( ) -> Void = {
87
+ #if (
88
+ !false && true
89
+ )
90
+ print ( " should appear " )
91
+ #endif
92
+
93
+ #if (
94
+ !true
95
+ )
96
+ print ( " should not appear " )
97
+ #else
98
+ print ( " also should appear " )
99
+ #endif
100
+ } ) {
101
+ }
102
+
72
103
// CHECK: func hasClosureDefaultArgWithSinglePoundIf(_ x: () -> Void = {
73
104
// CHECK-NOT: #if true
74
105
// CHECK: print("true")
@@ -85,7 +116,6 @@ public func hasClosureDefaultArgWithSinglePoundIf(_ x: () -> Void = {
85
116
} ) {
86
117
}
87
118
88
-
89
119
// CHECK: func hasSimpleDefaultArgs(_ x: Int = 0, b: Int = 1)
90
120
public func hasSimpleDefaultArgs( _ x: Int = 0 , b: Int = 1 ) {
91
121
}
You can’t perform that action at this time.
0 commit comments