Skip to content

[SR-15104] Do not require syntactic correctness for conditional compilation #57430

@swift-ci

Description

@swift-ci
Previous ID SR-15104
Radar None
Original Reporter kencarroll (JIRA User)
Type New Feature
Status Closed
Resolution Invalid
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels New Feature
Assignee None
Priority Medium

md5: fe3fe7453f0368659c15d0054060070a

Issue Description:

The macro #if os(Linux) of #if MY_FLAG requires full syntactic correctness.
For example code will compile.
#if !os(Linux)
public var x = 1
#else
@objc public var x = 1
#endif

However, the following code will not compile:

#if !os(Linux)
@objc
#endif
public var x = 1

This is compounded in protocols, classes and enums where multiple fully syntactically correct versions must exist for each class, protocol or enum to be exported to Objective C on an Apple platform.

This means that a single code base cannot be used to build for the different target platforms (Linux, Apple) necessitating either bespoke pre-build project generation or separate code branches or directories for affected libraries.

Clearly, both of these solutions are error prone and could be solved by not requiring syntactic correctness of conditionally dependent code snippets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    attributesFeature: Declaration and type attributescompilerThe Swift compiler itselfcompiler control statementsFeature: compiler control statementsfeatureA feature request or implementationswift evolution implementedFlag → feature: A feature that was approved through the Swift evolution process and implemented

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions