-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
#ifFeature → compiler control statements: Conditional compilation blocksFeature → compiler control statements: Conditional compilation blocksbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfcompiler control statementsFeature: compiler control statementsFeature: compiler control statementsparserArea → compiler: The legacy C++ parserArea → compiler: The legacy C++ parserswift 5.8unexpected errorBug: Unexpected errorBug: Unexpected error
Description
The following code produces an error in Swift 5.8 and swift-DEVELOPMENT-SNAPSHOT-2023-03-23-a
:
#if compiler(>=5.8)
#if hasFeature(VariadicGenerics)
func f<each T>(_: repeat each T) {}
#else
// Code for supporting older compilers
#endif
#else
// Repeat the code for supporting older compilers
#endif
$ swift test.swift
test.swift:3:13: error: expected '>' to complete generic parameter list
func f<each T>(_: repeat each T) {}
^
To support compilers older than 5.8, one must write:
#if compiler(>=5.8)
#if compiler(>=5.8) && hasFeature(VariadicGenerics)
func f<each T>(_: repeat each T) {}
#else
// Code for supporting older compilers
#endif
#else
// Repeat the code for supporting older compilers
#endif
This is awkward and requires inline comments to avoid confusion. It's already ugly enough to have to repeat the else branch when supporting 5.7 and earlier.
Metadata
Metadata
Assignees
Labels
#ifFeature → compiler control statements: Conditional compilation blocksFeature → compiler control statements: Conditional compilation blocksbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfcompiler control statementsFeature: compiler control statementsFeature: compiler control statementsparserArea → compiler: The legacy C++ parserArea → compiler: The legacy C++ parserswift 5.8unexpected errorBug: Unexpected errorBug: Unexpected error