swiftlang/swift
Auf GitHub ansehenOffer additional note for why method with Self reference cannot be used on `any SomeType`
Open
#76.320 geöffnet am 6. Sept. 2024
compilerdiagnostics qualityexistentialsgood first issueimprovementswift 6.2type checker
Repository-Metriken
- Stars
- (69.989 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 7T 6h) (556 gemergte PRs in 30 T)
Beschreibung
Motivation
The following snippet;
protocol Base {
associatedtype SomeID: Hashable
}
protocol Alpha: Base {
func take(id: Self.SomeID)
}
struct Use {
let alpha: any Alpha
func test() {
alpha.take(id: 12) // error: Member 'take' cannot be used on value of type 'any Alpha'; consider using a generic constraint instead
}
}
is correct in rejecting the line, since we need Self.SomeID to be well typed, but we dont know what its type is via the any.
It'd be helpful if we can point out that "why" the method can't be used via a note, in a method with many parameters one can sometimes miss the Self reference.
Proposed solution
Adding a note on the offending parameter would be good
Alternatives considered
No response
Additional information
No response