swiftlang / swift-syntax

A set of Swift libraries for parsing, inspecting, generating, and transforming Swift source code.
Apache License 2.0
3.2k stars 405 forks source link

Add support for parsing and emitting diagnostics for #if defined(...) #2809

Closed j-f1 closed 3 weeks ago

j-f1 commented 4 weeks ago

SwiftIfConfig now supports parsing defined(FOO) and interpreting it as just FOO for the purposes of active/inactive evaluation. All uses of defined() will produce an error with a fix-it that removes the defined() call and replaces it with its argument.

This produces a much clearer error message than the current version of Swift. It also un-suppresses syntax errors from the contents of the #if block.

#if defined(FOO)
// before: error: Unexpected platform condition (expected 'os', 'arch', or 'swift')
// after:  error: compilation conditions in Swift are always boolean and do not need to be checked for existence with 'defined()'
//         fix-it: remove 'defined()'
j-f1 commented 4 weeks ago

@swift-ci please test

j-f1 commented 4 weeks ago

@swift-ci please test

ahoppen commented 3 weeks ago

@swift-ci Please test Windows