Files
swift-mirror/test/Sema/availability_define_parsing.swift
Alexis Laferrière c6fc53e844 [Sema] Define availability via compiler flag
Introduce availability macros defined by a frontend flag.
This feature makes it possible to set the availability
versions at the moment of compilation instead of having
it hard coded in the sources. It can be used by projects
with a need to change the availability depending on the
compilation context while using the same sources.

The availability macro is defined with the `-define-availability` flag:

swift MyLib.swift -define-availability "_iOS8Aligned:macOS 10.10, iOS 8.0" ..

The macro can be used in code instead of a platform name and version:
@available(_iOS8Aligned, *)
public func foo() {}

rdar://problem/65612624
2020-10-06 11:25:20 -07:00

32 lines
1.4 KiB
Swift

// RUN: not %target-swift-frontend -typecheck %s \
// RUN: -define-availability "_brokenParse:a b c d" \
// RUN: -define-availability ":a b c d" \
// RUN: -define-availability "_justAName" \
// RUN: -define-availability "_brokenPlatforms:spaceOS 10.11" \
// RUN: -define-availability "_refuseWildcard:iOS 13.0, *" \
// RUN: -define-availability "_duplicateVersion 1.0:iOS 13.0" \
// RUN: -define-availability "_duplicateVersion 1.0:iOS 13.0" \
// RUN: 2>&1 | %FileCheck %s
// Force reading the argument macros.
@available(_brokenPlatforms)
public func brokenPlaforms() {}
// CHECK: -define-availability argument:1:16: error: expected version number
// CHECK-NEXT: _brokenParse:a b c d
// CHECK: -define-availability argument:1:1: error: expected an identifier to begin an availability macro definition
// CHECK-NEXT: :a b c d
// CHECK: -define-availability argument:1:11: error: expected ':' after '_justAName' in availability macro definition
// CHECK-NEXT: _justAName
// CHECK: -define-availability argument:1:31: warning: unrecognized platform name 'spaceOS'
// CHECK-NEXT: _brokenPlatforms:spaceOS 10.11
// CHECK: -define-availability argument:1:27: error: future platforms identified by '*' cannot be used in an availability macro
// CHECK-NEXT: _refuseWildcard
// CHECK: duplicate definition of availability macro '_duplicateVersion' for version '1.0'
// CHECK-NEXT: _duplicateVersion