Misleading Diagnostics for Actors in Protocol Compositions
compilerdiagnostics qualityprotocol compositionsactordeclarations
### Motivation
Consider the following program that erroneously uses protocol composition for actor types `A` and `B`:
```swift
actor A {}
actor B {}
typealias C = A & B // ❌ error: protocol-constrained type cannot contain class 'B' because it already contains class 'A'
```
The generated diagnostic is quite confusing. According to my understanding, actors simply don't support inheritance at all.
Moreover, the following surprisingly compiles:
```swift
actor A {}
typealias B = A & CustomStringConvertible // ✅
```
We only get an error when adding:
```swift
await A().description // ❌ error: value of type 'A' has no member 'description'
```
### Proposed solution
I would expect the same message we get for structs, enums, functions and tuples:
```
❌ error: non-protocol, non-class type 'A' cannot be used within a protocol-constrained type
```
### Alternatives considered
_No response_
### Additional information
swiftc --version:
```
Swift version 6.5-dev (LLVM 18d2bfb70c14d89, Swift c13d82e5987aecb)
Target: x86_64-unknown-linux-gnu
Build config: +assertions
Compiler returned: 0
```
0 条评论