1010//
1111//===----------------------------------------------------------------------===//
1212
13- //
14- // This file defines the SyntaxRewriter, a class that performs a standard walk
15- // and tree-rebuilding pattern.
16- //
17- // Subclassers of this class can override the walking behavior for any syntax
18- // node and transform nodes however they like.
19- //
20- //===----------------------------------------------------------------------===//
21-
2213import SwiftDiagnostics
2314import SwiftSyntax
2415
@@ -88,12 +79,13 @@ extension SyntaxProtocol {
8879/// than trivia).
8980class ActiveSyntaxRewriter < Configuration: BuildConfiguration > : SyntaxRewriter {
9081 let configuration : Configuration
82+ var diagnostics : [ Diagnostic ] = [ ]
9183
9284 init ( configuration: Configuration ) {
9385 self . configuration = configuration
9486 }
9587
96- private func dropInactive< List: Collection & SyntaxCollection > (
88+ private func dropInactive< List: SyntaxCollection > (
9789 _ node: List ,
9890 elementAsIfConfig: ( List . Element ) -> IfConfigDeclSyntax ?
9991 ) -> List {
@@ -105,7 +97,10 @@ class ActiveSyntaxRewriter<Configuration: BuildConfiguration>: SyntaxRewriter {
10597 // Find #ifs within the list.
10698 if let ifConfigDecl = elementAsIfConfig ( element) {
10799 // Retrieve the active `#if` clause
108- let activeClause = ifConfigDecl. activeClause ( in: configuration)
100+ let ( activeClause, localDiagnostics) = ifConfigDecl. activeClause ( in: configuration)
101+
102+ // Add these diagnostics.
103+ diagnostics. append ( contentsOf: localDiagnostics)
109104
110105 // If this is the first element that changed, note that we have
111106 // changes and add all prior elements to the list of new elements.
@@ -255,7 +250,8 @@ class ActiveSyntaxRewriter<Configuration: BuildConfiguration>: SyntaxRewriter {
255250 return dropInactive ( outerBase: base, postfixIfConfig: postfixIfConfig)
256251 }
257252
258- preconditionFailure ( " Unhandled postfix expression in #if elimination " )
253+ assertionFailure ( " Unhandled postfix expression in #if elimination " )
254+ return postfix
259255 }
260256
261257 /// Drop inactive regions from a postfix `#if` configuration, applying the
@@ -265,7 +261,10 @@ class ActiveSyntaxRewriter<Configuration: BuildConfiguration>: SyntaxRewriter {
265261 postfixIfConfig: PostfixIfConfigExprSyntax
266262 ) -> ExprSyntax {
267263 // Retrieve the active `if` clause.
268- let activeClause = postfixIfConfig. config. activeClause ( in: configuration)
264+ let ( activeClause, localDiagnostics) = postfixIfConfig. config. activeClause ( in: configuration)
265+
266+ // Record these diagnostics.
267+ diagnostics. append ( contentsOf: localDiagnostics)
269268
270269 guard case . postfixExpression( let postfixExpr) = activeClause? . elements
271270 else {
0 commit comments