Files
swift-mirror/test/Parse/availability_query.swift
Devin Coughlin d04cc58c6c Sema: Refine availability context in IfStmt guard conditions following #available()
Loosen restrictions on where #available() can appear in IfStmt guards and refine the
context for guard StmtConditionElements following an availability check.

This enables #available() to be combined with if let optional binding:

if #available(iOS 8.0, *),
   let x = someIOS8API() {
  // Do more iOS 8 stuff
}

and

if let x = someIOS7API() where #available(iOS 8.0, *),
   let y = someIOS8API() {
  // Do more iOS 8 stuff
}

Swift SVN r28096
2015-05-03 20:27:29 +00:00

76 lines
3.0 KiB
Swift

// RUN: %target-parse-verify-swift
// REQUIRES: OS=macosx
if #available(OSX 10.10, *) {
}
// Allow parenthesized check
if (#available(OSX 10.10, *)) {
}
if #available { // expected-error {{expected availability condition}} expected-error {{braced block of statements is an unused closure}} expected-error {{statement cannot begin with a closure expression}} expected-note {{explicitly discard the result of the closure by assigning to '_'}} expected-error {{type of expression is ambiguous without more context}}
}
if #available( { // expected-error {{expected platform name}} expected-error {{expected ')'}} expected-note {{to match this opening '('}}
}
if #available() { // expected-error {{expected platform name}}
}
if #available(OSX { // expected-error {{expected version number}} expected-error {{expected ')'}} expected-note {{to match this opening '('}}
}
if #available(OSX) { // expected-error {{expected version number}}
}
if #available(OSX 10.10 { // expected-error {{expected ')'}} expected-note {{to match this opening '('}} expected-error {{check must handle potential future platforms with '*'}}
}
if #available(iDishwasherOS 10.10) { // expected-error {{unrecognized platform name 'iDishwasherOS'}}
}
if #available(iDishwasherOS 10.10, *) { // expected-error {{unrecognized platform name 'iDishwasherOS'}}
}
if #available(iOS 8.0, *) {
}
// Want to make sure we can parse this. Perhaps we should not let this validate, though.
if #available(*) {
}
if #available(* { // expected-error {{expected ')' in availability query}} expected-note {{to match this opening '('}}
}
// Multiple platforms
if #available(OSX 10.10, iOS 8.0, *) {
}
if #available(OSX 10.10, iOS 8.0) { // expected-error {{check must handle potential future platforms with '*'}}
}
if #available(OSX 10.10, { // expected-error {{expected platform name}} // expected-error {{expected ')'}} expected-note {{to match this opening '('}} expected-error {{check must handle potential future platforms with '*'}}
}
if #available(OSX 10.10,) { // expected-error {{expected platform name}} expected-error {{check must handle potential future platforms with '*'}}
}
if #available(OSX 10.10, iOS { // expected-error {{expected version number}} // expected-error {{expected ')'}} expected-note {{to match this opening '('}} expected-error {{check must handle potential future platforms with '*'}}
}
if #available(OSX 10.10, iOS 8.0, iDishwasherOS 10.10) { // expected-error {{unrecognized platform name 'iDishwasherOS'}} expected-error {{check must handle potential future platforms with '*'}}
}
if #available(iDishwasherOS 10.10, OSX 10.10) { // expected-error {{unrecognized platform name 'iDishwasherOS'}} expected-error {{check must handle potential future platforms with '*'}}
}
if #available(OSX 10.10 || iOS 8.0) { // expected-error {{'||' cannot be used in an availability condition}} expected-error {{check must handle potential future platforms with '*'}}
}
// Emit Fix-It removing un-needed >=, for the moment.
if #available(OSX >= 10.10, *) { // expected-error {{version comparison not needed}} {{19-21=}}
}