swift condition compile block always check statements syntax

Viewed 71

Background:

we know swift support compile condition "swift(>=version)" ref: https://github.com/apple/swift-evolution/blob/master/proposals/0020-if-swift-version.md

Mentions:

#if swift(>=2.2)
  print("Active!")
#else
  this! code! will! not! parse! or! produce! diagnostics!
#endif

“Each statement in the body of a conditional compilation block is parsed even if it’s not compiled. However, there’s an exception if the compilation condition includes a swift() platform condition: The statements are parsed only if the compiler’s version of Swift matches what is specified in the platform condition. This exception ensures that an older compiler doesn’t attempt to parse syntax introduced in a newer version of Swift.”

From: Apple Inc. “The Swift Programming Language (Swift 5.3)。” Apple Books.

Enivronment: xcode11 with swift5 compiler

#if swift(<2.2)
  this! code! will! not! parse! or! produce! diagnostics!
#else
  print("Active!")
#endif

While running that code snippet, xcode prompt error: Consecutive statements on a line must be separated by ';'

Indicate swift compiler parse all code content even if exclude by "#if #else" compile condition ?

clang should not compile code in condition swift(<2.2), dosen't it ?

As apple says: The statements are parsed only if the compiler’s version of Swift matches what is specified in the platform condition

Any body can explain reason? Thanks!

0 Answers
Related