Files
swift-mirror/test/Generics/rdar83768458.swift
Slava Pestov 941438d6c8 RequirementMachine: New linear order on associated type symbols
Previously we said that if P1 inherits from P2, then [P1:T] < [P2:T].

However, this didn't generalize to merged associated type symbols;
we always had [P1&P2:T] < [P3:T] even if P3 inherited from both P1
and P2.

This meant that the 'merge' operation did not preserve order, which
fired an assertion in the completion logic.

Fix this by generalizing the linear order to compare the 'support'
of protocols rather than the 'depth', where the 'support' is
defined as the size of the transitive closure of the set under
protocol inheritance.

Then, if you have something like

  protocol P1 {}
  protocol P2 {}
  protocol P3 : P1, P2 {}

The support of 'P1 & P2' is 2, and the support of 'P3' is 3,
therefore [P3:T] < [P1&P2:T] in this example.

Fixes <rdar://problem/83768458>.
2021-10-21 19:00:10 -04:00

22 lines
498 B
Swift

// RUN: %target-typecheck-verify-swift
public protocol Collection {
associatedtype Index
}
public protocol BidirectionalCollection: Collection {}
public protocol RandomAccessCollection: BidirectionalCollection {}
public protocol Numeric {
associatedtype Magnitude
}
public protocol SignedNumeric: Numeric {}
public protocol BinaryInteger: Numeric {}
public protocol SignedInteger: BinaryInteger, SignedNumeric {}
struct S<X> where X : RandomAccessCollection, X.Index : SignedInteger {}