Skip to content

[SR-4196] Allow #if (conditional compilation) to guard switch cases #46779

@belkadan

Description

@belkadan
Previous ID SR-4196
Radar rdar://problem/16980851
Original Reporter @belkadan
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, LanguageFeatureRequest, StarterProposal
Assignee @rintaro
Priority Medium

md5: c3d4da1a290a1496adc214b1fce9223b

relates to:

  • SR-4079 Availability of enum case does not propagate to its switch case scope.
  • SR-2 Build configuration directives can not wrap switch cases

Issue Description:

Currently #if can only be used to guard complete declarations or complete statements, due to the (deliberate) modeling as part of the AST rather than as a textual preprocessing step. However, there's one more place where it would structurally make sense to allow #if: switch cases. This may be important if a new case is added in a new version of Swift. Right now you'd have to write the switch twice.

Metadata

Metadata

Assignees

Labels

#ifFeature → compiler control statements: Conditional compilation blockscompilerThe Swift compiler itselfcompiler control statementsFeature: compiler control statementsimprovementparserArea → compiler: The legacy C++ parser

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions