Swift 6.4 (SE-0521) lets us write an optional existential without the parentheses, so any Error? now means (any Error)? and some View? means (some View)?, which is how most of us read them anyway. I moved one of my side projects, an iOS app built with SwiftUI and TCA, over to the new spelling, and this is a note about the part that took longer than the rewrite, which was finding out how many things besides the compiler parse that code.
The rewrite itself is mechanical:
// before
var lastError: (any Error)?
func makeClock() -> (any Clock<Duration>)?
// after, Swift 6.4
var lastError: any Error?
func makeClock() -> any Clock<Duration>?
For that project it was 137 sites in 58 files, and 104 of them were (any Error)?, which says something about how much of an app is error handling.
The compiler is not the only parser
The compiler has its own parser, and it is the one that learned the new rule. But a modern Swift project usually has a few more parsers in it, since lint tools, code generators and the macro plugins that come from packages are all built on swift-syntax. A package’s macro plugin is a separate program that SwiftPM builds against the swift-syntax version the package graph resolved, and when the compiler expands the macro, it hands the plugin the source of the code the macro receives (the declaration it is attached to, or a freestanding macro’s arguments), and the plugin parses it again with its own copy of swift-syntax. So what any Error? means to a package’s macro depends on which swift-syntax ended up in Package.resolved, and the Xcode version only decides it for the macros that ship with the toolchain (@Observable, #Predicate and friends), which are built against the toolchain’s own swift-syntax.
We can see the difference with a few lines of SwiftParser:
import SwiftParser
import SwiftSyntax
let file = Parser.parse(source: "let e: any Error?")
let type = file.statements.first!.item
.as(VariableDeclSyntax.self)!.bindings.first!.typeAnnotation!.type
print(type.debugDescription)
With swift-syntax 603.0.1:
SomeOrAnyTypeSyntax
├─someOrAnySpecifier: keyword(SwiftSyntax.Keyword.any)
╰─constraint: OptionalTypeSyntax
├─wrappedType: IdentifierTypeSyntax
│ ╰─name: identifier("Error")
╰─questionMark: postfixQuestionMark
With 604.0.0:
OptionalTypeSyntax
├─wrappedType: SomeOrAnyTypeSyntax
│ ├─someOrAnySpecifier: keyword(SwiftSyntax.Keyword.any)
│ ╰─constraint: IdentifierTypeSyntax
│ ╰─name: identifier("Error")
╰─questionMark: postfixQuestionMark
So 603 reads any Error? as any (Error?), an existential of an optional, which isn’t a type the compiler would accept, and 604 reads it the way the compiler does. some View? behaves the same way, and compositions are the odd one out, because any P & Q? parses on 603 (with the ? on Q alone) and is a parse error on 604, where a composition still needs its parentheses.
What 603 does to a macro
Macro plugins make decisions based on that tree. swift-dependencies’ @DependencyClient is a good example, because it requires a default value for every non-throwing endpoint unless the endpoint returns Void or an optional, and this is how it decides that something is an optional:
var isOptional: Bool {
self.returnClause.type.is(OptionalTypeSyntax.self)
|| self.returnClause.type.as(IdentifierTypeSyntax.self)
.map { ["Optional"].qualified("Swift").contains($0.name.text) }
?? false
}
Under 603, the return type of () -> any Error? is a SomeOrAnyTypeSyntax, so the check says no. To see that in a build rather than trust a reading of the source, we can make a scratch package with swift-dependencies 1.17.2, pin swift-syntax exactly (.package(url: "https://github.com/swiftlang/swift-syntax", exact: "603.0.1")), and put two clients in it:
import DependenciesMacros
@DependencyClient
struct ParenthesisedClient {
var lastError: @Sendable () -> (any Error)?
}
@DependencyClient
struct BareClient {
var lastError: @Sendable () -> any Error?
}
With swift-syntax 604.0.0 the package builds. With 603.0.1 it fails, and the only error is on BareClient (trimmed here, the path and the long explanation are cut):
.../Probe.swift:10:7: error: Default value required for non-throwing closure 'lastError'
...
| `- note: Insert '= { <#any Error?#> }'
It’s the same compiler and the same source, and the only difference is the swift-syntax line in Package.resolved. This one at least fails loudly, and filling in the fix-it with a real default (= { nil }) makes it build, so it’s easy to “fix” without noticing that the macro misread the type. A macro that branches on the tree without emitting an error would just produce different code. In that project none of the 137 rewritten sites sat inside a macro’s input, and none of the app’s @DependencyClient endpoints returned an optional existential, so the build stayed green and the rule below is for the code written after it.
In code that a package’s macro receives, keep the parentheses ((any X)?) until Package.resolved shows swift-syntax 604 or newer.
Why the pin can’t just move
The obvious fix is to bump swift-syntax to 604, and that was the first plan anyway (for a different reason, I assumed the project’s own swift-syntax lint rules would need the new tree, and they turned out not to care). The packages that obviously use swift-syntax were fine (swift-dependencies and TCA both allow "509.0.0" ..< "605.0.0"), so the pins went up, and resolution failed with exit 74, with SwiftPM pointing at a package that wasn’t on the list at all:
'mlx-swift-lm' 3.32.3 depends on 'swift-syntax' 602.0.0..<604.0.0
mlx-swift-lm is one of the app’s dependencies, and it has a macro target of its own, so it depends on swift-syntax like the others do, and as of this writing (November 2026) its newest tag, 3.32.3, and its main branch both stop below 604. SwiftPM resolves one version of a package for the whole graph, which means the most conservative upper bound anywhere in the graph decides which swift-syntax every package’s macro plugin gets, and there is no way to give one plugin 604 and another 603, so the parentheses stay where a macro can see them until that range moves.
So the new spelling is a compiler feature, but whether it means the same thing everywhere depends on every parser that sees the code, and for a package’s macros that’s the swift-syntax in Package.resolved, not the Xcode version. Before dropping the parentheses in code a macro receives, check which swift-syntax the graph resolved, and if it’s below 604, look for the package whose upper bound is holding it there.