diff --git a/lib/AST/InlinableText.cpp b/lib/AST/InlinableText.cpp index be89869d0bf..7a805d94add 100644 --- a/lib/AST/InlinableText.cpp +++ b/lib/AST/InlinableText.cpp @@ -14,6 +14,7 @@ #include "swift/AST/ASTWalker.h" #include "swift/AST/ASTNode.h" #include "swift/AST/Decl.h" +#include "swift/AST/Expr.h" #include "swift/Parse/Lexer.h" #include "llvm/ADT/SmallVector.h" @@ -92,9 +93,15 @@ struct ExtractInactiveRanges : public ASTWalker { return false; } - // Ignore range from beginning of '#if' to the beginning of the elements - // of this clause. - addRange(start, Lexer::getLocForEndOfLine(sourceMgr, clause->Loc)); + // Ignore range from beginning of '#if', '#elseif', or '#else' to the + // beginning of the elements of this clause. + auto elementsBegin = clause->Loc; + // If there's a condition (e.g. this isn't a '#else' block), then ignore + // everything up to the end of the condition. + if (auto cond = clause->Cond) { + elementsBegin = cond->getEndLoc(); + } + addRange(start, Lexer::getLocForEndOfLine(sourceMgr, elementsBegin)); // Ignore range from effective end of the elements of this clause to the // end of the '#endif' diff --git a/test/ModuleInterface/if-configs.swift b/test/ModuleInterface/if-configs.swift index 62cf9ab7303..126939de567 100644 --- a/test/ModuleInterface/if-configs.swift +++ b/test/ModuleInterface/if-configs.swift @@ -69,6 +69,37 @@ public func hasClosureDefaultArgWithComplexPoundIf(_ x: () -> Void = { }) { } +// CHECK: func hasClosureDefaultArgWithMultilinePoundIfCondition(_ x: () -> Void = { +// CHECK-NOT: #if ( +// CHECK-NOT: !false && true +// CHECK-NOT: ) +// CHECK: print("should appear") +// CHECK-NOT: #endif +// CHECK-NOT: #if ( +// CHECK-NOT: !true +// CHECK-NOT: ) +// CHECK-NOT: print("should not appear") +// CHECK-NOT: #else +// CHECK: print("also should appear") +// CHECK-NOT: #endif +// CHECK-NEXT: }) +public func hasClosureDefaultArgWithMultilinePoundIfCondition(_ x: () -> Void = { + #if ( + !false && true + ) + print("should appear") + #endif + + #if ( + !true + ) + print("should not appear") + #else + print("also should appear") + #endif +}) { +} + // CHECK: func hasClosureDefaultArgWithSinglePoundIf(_ x: () -> Void = { // CHECK-NOT: #if true // CHECK: print("true") @@ -85,7 +116,6 @@ public func hasClosureDefaultArgWithSinglePoundIf(_ x: () -> Void = { }) { } - // CHECK: func hasSimpleDefaultArgs(_ x: Int = 0, b: Int = 1) public func hasSimpleDefaultArgs(_ x: Int = 0, b: Int = 1) { }