Open
Description
Description
this code (the function f
) type-checked on 6.0.2, but not on 6.1.1.
g
and h
are similar functions that typecheck successfully on both compilers.
the bug appears to be present in main
as well.
Reproduction
public protocol CacheBase<Object, ObjectEntry>: Sendable {
associatedtype ObjectEntry: Identifiable<Object.ID>
associatedtype Object: Identifiable
subscript(_: Object.ID) -> ObjectEntry? { get }
}
public protocol StoredPropertiesCache<ObjectEntry>: CacheBase
where ObjectEntry: StoredPropertyMetadataAccessible, ObjectEntry.Object == Object {
}
public protocol StoredPropertyMetadataAccessible<Object>: Identifiable, Equatable {
associatedtype Object: Identifiable where Object.ID == ID
}
struct InstrumentIdentifier: Hashable, Sendable {
}
struct Instrument: Identifiable, Sendable {
typealias ID = InstrumentIdentifier
var id: ID
}
struct MarketDataConfiguration: StoredPropertyMetadataAccessible {
typealias Object = Instrument
var id: InstrumentIdentifier
}
func f(
id: InstrumentIdentifier,
_ cache: any StoredPropertiesCache<MarketDataConfiguration>
) async {
let _: MarketDataConfiguration? = cache[id]
// Type of expression is ambiguous without a type annotation
}
func g(
id: InstrumentIdentifier,
_ cache: any CacheBase<MarketDataConfiguration, MarketDataConfiguration>
) async {
let _: MarketDataConfiguration? = cache[id]
}
func h(
id: InstrumentIdentifier,
_ cache: some StoredPropertiesCache<MarketDataConfiguration>
) async {
let _: MarketDataConfiguration? = cache[id]
}
Expected behavior
it should compile
Environment
$ swift --version
Swift version 6.1 (swift-6.1-RELEASE)
Target: x86_64-unknown-linux-gnu
Additional information
No response
Metadata
Metadata
Assignees
Labels
A deviation from expected or documented behavior. Also: expected but undesirable behavior.The Swift compiler itselfFeature → existentials: constrained existentials such as 'any Collection<Int>'Feature → existentials: existential member accessesFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesFeature: generic declarations and typesArea → compiler: Semantic analysisBug: Unexpected error