Files
swift-mirror/test/decl/protocol/resilient_defaults.swift
Slava Pestov 8372258215 Sema: Fix crash in default witness table checking for associated conformances
It is possible to state an associated requirement on a protocol such
that a default associated type in another protocol no longer satifies
this requirement. If the other protocol was from a serialized module,
we would crash while getting the TypeRepr for its default type.

Fix this by checking if the TypeRepr is set, and if not set, just emit
a note at the associated type declaration without highlighting the
default type.

Fixes rdar://180489587.
2026-07-03 16:44:59 -04:00

24 lines
1019 B
Swift

// RUN: %target-typecheck-verify-swift -enable-library-evolution -verify-additional-file Swift.Collection.SubSequence
public struct Wrapper<T: P>: P { }
extension Wrapper: Q where T: Q { }
public protocol PBase {
associatedtype AssocType
}
public protocol P: PBase {
override associatedtype AssocType: P = Wrapper<Self>
// expected-note@-1{{associated type 'AssocType' has default type 'Wrapper<Self>' written here}}
}
public protocol Q: P where Self.AssocType: Q { }
public protocol R: Q where Self.AssocType: R { }
// expected-warning@-1{{default type 'Wrapper<Self>' for associated type 'AssocType' does not satisfy constraint 'Self.AssocType': 'R'}}
public struct E {}
public protocol P1: RandomAccessCollection where SubSequence: P1 {}
// expected-warning@-1{{default type 'Slice<Self>' for associated type 'SubSequence' does not satisfy constraint 'Self.SubSequence': 'P1'}}
// expected-note@Swift.Collection.SubSequence:2 {{associated type 'SubSequence' has default type 'Slice<Self>' written here}}