Skip to content

sourcekit: avoid evaluating pound conditions while perform syntactic parsing. rdar://46143404 #20981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/SourceKit/SyntaxTree/pound_if.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-swift-frontend -emit-syntax %s > %t.emit
// RUN: %sourcekitd-test -req=syntax-tree %s > %t.sourcekit
// RUN: diff %t.emit %t.sourcekit

#if swift(<4)
print(1)
#endif
3 changes: 3 additions & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,9 @@ class SwiftDocumentSyntaxInfo {

Parser->getDiagnosticEngine().addConsumer(DiagConsumer);

// Collecting syntactic information shouldn't evaluate # conditions.
Parser->getParser().State->PerformConditionEvaluation = false;

// If there is a syntax parsing cache, incremental syntax parsing is
// performed and thus the generated AST may not be up-to-date.
HasUpToDateAST = CompInv.getMainFileSyntaxParsingCache() == nullptr;
Expand Down