-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
bugA 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 itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of ImplementationexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesfix-itsFeature: diagnostic fix-itsFeature: diagnostic fix-itsprotocol compositionsFeature → types: protocol composition typesFeature → types: protocol composition typesswift 6.0type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistypesFeature: typesFeature: typesunexpected behaviorBug: Unexpected behavior or incorrect outputBug: Unexpected behavior or incorrect output
Description
Description
In Swift 5.8, SE-0335 "Introduce existential any" can be enabled by SE-0362 "Piecemeal adoption of upcoming language improvements". In that case, if the existential type is not given the any
keyword, it causes a build error.
That build error contains a suggested fix, but it suggests a fix that seems incorrect when using protocol composition types.
Steps to reproduce
- Create a Swift Package and open it Xcode 14.3.
% mkdir ExistentialAnySample
% cd ExistentialAnySample
% swift package init --type executable
Creating executable package: ExistentialAnySample
Creating Package.swift
Creating .gitignore
Creating Sources/
Creating Sources/main.swift
% xed .
- Enable upcoming feature
ExistentialAny
.
// swift-tools-version: 5.8
import PackageDescription
let package = Package(
name: "ExistentialAnySample",
targets: [
.executableTarget(
name: "ExistentialAnySample",
path: "Sources",
swiftSettings: [
.enableUpcomingFeature("ExistentialAny"),
]),
]
)
- Write the following code in
main.swift
and build it (we will get some errors).
//
// main.swift
// ExistentialAnySample
//
// Created by treastrain on 2023/04/08.
//
class C {}
protocol P {}
protocol Q {}
func f1(_ v: C & P) {} // ❌ Use of protocol 'P' as a type must be written 'any P'
func f2(_ v: P & Q) {} // ❌ Use of protocol 'P' as a type must be written 'any P'
// ❌ Use of protocol 'Q' as a type must be written 'any Q'
-
In the Xcode menu bar, "Editor" > "Fix all issues (Cmd + Ctrl + Option + F)".
-
The error continues and the build fails.
Expected behavior
After "Fix all issues (Cmd + Ctrl + Option + F)", C & P
should be replaced with any C & P
, and P & Q
should be replaced with any P & Q
in one shot.
Environment
- Swift compiler version info
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100) Target: arm64-apple-macosx13.0
- Xcode version info
Xcode 14.3 Build version 14E222b
- Deployment target: iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
Metadata
Metadata
Assignees
Labels
bugA 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 itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of ImplementationexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesfix-itsFeature: diagnostic fix-itsFeature: diagnostic fix-itsprotocol compositionsFeature → types: protocol composition typesFeature → types: protocol composition typesswift 6.0type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistypesFeature: typesFeature: typesunexpected behaviorBug: Unexpected behavior or incorrect outputBug: Unexpected behavior or incorrect output