mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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
110 lines
3.4 KiB
Swift
110 lines
3.4 KiB
Swift
// RUN: %target-typecheck-verify-swift -D FOO -swift-version 3
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Invalid binary operation
|
|
|
|
#if FOO = false
|
|
// expected-warning @-1 {{ignoring invalid conditional compilation expression, which will be rejected in future version of Swift}}
|
|
undefinedFunc() // expected-error {{use of unresolved identifier 'undefinedFunc'}}
|
|
#else
|
|
undefinedFunc() // ignored.
|
|
#endif
|
|
|
|
#if false
|
|
|
|
#elseif !FOO ? false : true
|
|
// expected-warning @-1 {{ignoring invalid conditional compilation expression, which will be rejected in future version of Swift}}
|
|
undefinedFunc() // ignored.
|
|
#else
|
|
undefinedFunc() // expected-error {{use of unresolved identifier 'undefinedFunc'}}
|
|
#endif
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// SR-3663: The precedence and associativity of '||' and '&&'.
|
|
// See test/Parse/ConditionalCompilation/sequence.swift for Swift 4 behavior.
|
|
|
|
#if false || true && false
|
|
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
|
#else
|
|
undefinedElse()
|
|
#endif
|
|
|
|
#if false && true || true
|
|
undefinedIf()
|
|
#else
|
|
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
|
|
#endif
|
|
|
|
#if false || true && false || false
|
|
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
|
|
#else
|
|
undefinedElse()
|
|
#endif
|
|
|
|
// Accepted in Swift3. *source breaking*
|
|
#if false || true && try! Swift
|
|
// expected-error @-1 {{invalid conditional compilation expression}}
|
|
undefinedIf()
|
|
#endif
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// SR-4032: "skip parsing" in non-active branch for version checks.
|
|
// See test/Parse/ConditionalCompilation/sequence_version.swift for Swift 4 behavior.
|
|
|
|
#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 // expected-error 2 {{consecutive statements}}
|
|
#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 // expected-error 2 {{consecutive statements}}
|
|
#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 // expected-error 2 {{consecutive statements}}
|
|
#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 // expected-error 2 {{consecutive statements}}
|
|
#endif
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// SR-4031: Compound name in compilation condition
|
|
|
|
// Accepted in Swift3. *source breaking*
|
|
#if BAR(_:) // expected-error {{invalid conditional compilation expression}}
|
|
#elseif os(x:)(macOS) // expected-error {{unexpected platform condition (expected 'os', 'arch', or 'swift')}}
|
|
#elseif os(Linux(foo:bar:)) // expected-error {{unexpected platform condition argument: expected identifier}}
|
|
#endif
|