Skip to content

Commit f25925f

Browse files
committed
Parser: suppress diagnostics when parsing inside inactive code
1 parent c8dd6a9 commit f25925f

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

lib/Parse/ParseIfConfig.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/Parse/Parser.h"
1818

1919
#include "swift/AST/ASTVisitor.h"
20+
#include "swift/AST/DiagnosticSuppression.h"
2021
#include "swift/Basic/Defer.h"
2122
#include "swift/Basic/LangOptions.h"
2223
#include "swift/Basic/Version.h"
@@ -641,6 +642,7 @@ ParserResult<IfConfigDecl> Parser::parseIfConfig(
641642
} else if (SyntaxContext->isEnabled()) {
642643
// We shouldn't skip code if we are building syntax tree.
643644
// The parser will keep running and we just discard the AST part.
645+
DiagnosticSuppression suppression(Context.Diags);
644646
SmallVector<ASTNode, 16> dropedElements;
645647
parseElements(dropedElements, false);
646648
} else {

test/Syntax/diagnostics_verify.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ class { // expected-error {{unknown declaration syntax exists in the source}}
2222

2323
#if swift(<1)
2424
print("Wat")
25+
class { // expected-error {{unknown declaration syntax exists in the source}}
26+
27+
}
2528
#endif

0 commit comments

Comments
 (0)