Skip to content

typechecker regression when calling protocol requirement through an existential of a refining protocol #81712

Open
@tayloraswift

Description

@tayloraswift

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

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconstrained existentialsFeature → existentials: constrained existentials such as 'any Collection<Int>'existential member accessesFeature → existentials: existential member accessesexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesgenericsFeature: generic declarations and typesregressionswift 6.1type checkerArea → compiler: Semantic analysisunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions