Files
swift-mirror/test/Parse/ConditionalCompilation/sequence_version.swift
Rintaro Ishizaki b56ab17fa5 [Parse] Separate compilation condition validation and evaluation
Fixes:
https://bugs.swift.org/browse/SR-3455
https://bugs.swift.org/browse/SR-3663
https://bugs.swift.org/browse/SR-4032
https://bugs.swift.org/browse/SR-4031

Now, compilation conditions are validated at first, then evaluated. Also,
in non-Swift3 mode, '&&' now has higher precedence than '||'.
'A || B && C || D' are evaluated as 'A || (B && C) || D'.

Swift3 source breaking changes:

* [SR-3663] This used to be accepted and evaluate to 'true' because of short
  circuit without any validation.

  #if true || true * 12 = try Anything is OK?
  print("foo")
  #endif

  In this change, remaining expressions are properly validated and
  diagnosed if it's invalid.

* [SR-4031] Compound name references are now diagnosed as errors.
  e.g. `#if os(foo:bar:)(macOS)` or `#if FLAG(x:y:)`

Swift3 compatibility:

* [SR-3663] The precedence of '||' and '&&' are still the same and the
  following code evaluates to 'true'.

  #if false || true && false
  print("foo")
  #endif
2017-03-23 01:25:29 +09:00

50 lines
1.0 KiB
Swift

// RUN: %target-typecheck-verify-swift -swift-version 4 -D FOO
#if !swift(>=2.2)
// There should be no error here.
foo bar
#else
let _: Int = 1
#endif
#if (swift(>=2.2))
let _: Int = 1
#else
// There should be no error here.
foo bar
#endif
#if swift(>=99.0) || swift(>=88.1.1)
// There should be no error here.
foo bar baz
#else
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
#endif
#if swift(>=99.0) || FOO
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
#else
undefinedElse()
#endif
#if swift(>=99.0) && FOO
// There should be no error here.
foo bar baz
#else
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
#endif
#if FOO && swift(>=2.2)
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
#else
// There should be no error here.
foo bar baz
#endif
#if swift(>=2.2) && swift(>=1)
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
#else
// There should be no error here.
foo bar baz
#endif