@@ -1504,6 +1504,80 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
15041504 hasNotTypeArgument ( a , target , tp )
15051505 )
15061506 }
1507+
1508+ predicate baseTypeMatchAtTypeParameter (
1509+ Access a , AccessEnvironment e , AccessPosition apos , Declaration target , TypeParameter tp ,
1510+ TypePath prefix , TypePath requiredPrefix
1511+ ) {
1512+ exists (
1513+ TypePath pathToTypeParamInConstraint , TypePath pathToTp , TypePath pathToTypeParamInSub
1514+ |
1515+ argRootTypeSatisfiesTargetTypeCand ( _, target , pragma [ only_bind_into ] ( apos ) , tp , pathToTp ) and
1516+ SatisfiesParameterConstraint:: satisfiesConstraintAtTypeParameter ( MkRelevantAccess ( a ,
1517+ pragma [ only_bind_into ] ( apos ) , e ) ,
1518+ MkRelevantTarget ( target , pragma [ only_bind_into ] ( apos ) ) , pathToTypeParamInConstraint ,
1519+ pathToTypeParamInSub ) and
1520+ hasNotTypeArgument ( a , target , tp )
1521+ |
1522+ /*
1523+ * Example:
1524+ *
1525+ * ```swift
1526+ * class Base<B> {
1527+ * init(_ value: B) {}
1528+ * }
1529+ *
1530+ * class Derived<D>: Base<[D]> {
1531+ * init(_ value: D) { super.init([value]) }
1532+ * }
1533+ *
1534+ * func foo<T>(_ value: T, _ base: Base<T>) { }
1535+ *
1536+ * foo([2], Derived(<unknown>))
1537+ * ```
1538+ *
1539+ * - tp = T (bound by `foo`)
1540+ * - prefix = pathToTypeParamInSub = "D"
1541+ * - requiredPrefix = "Element"
1542+ * - pathToTypeParamInConstraint = "B.Element"
1543+ * - pathToTp = "B"
1544+ */
1545+
1546+ pathToTypeParamInConstraint = pathToTp .appendInverse ( requiredPrefix ) and
1547+ prefix = pathToTypeParamInSub
1548+ or
1549+ /*
1550+ * Example:
1551+ *
1552+ * ```swift
1553+ * class Base<B> {
1554+ * init(_ value: B) {}
1555+ * }
1556+ *
1557+ * class Derived<D>: Base<D> {
1558+ * override init(_ value: D) { super.init(value) }
1559+ * }
1560+ *
1561+ * func foo<T>(_ value: T, _ base: Base<T?>) {}
1562+ *
1563+ * foo(2, Derived(Optional.none))
1564+ * ```
1565+ *
1566+ * - tp = T (bound by `foo`)
1567+ * - prefix = "D.Wrapped"
1568+ * - pathToTypeParamInSub = "D"
1569+ * - requiredPrefix = ""
1570+ * - pathToTypeParamInConstraint = "B"
1571+ * - pathToTp = "B.Wrapped"
1572+ */
1573+
1574+ exists ( TypePath path0 |
1575+ pathToTp = pathToTypeParamInConstraint .appendInverse ( path0 ) and
1576+ prefix = pathToTypeParamInSub .append ( path0 ) and
1577+ requiredPrefix = TypePath:: nil ( )
1578+ )
1579+ )
1580+ }
15071581 }
15081582
15091583 private module AccessConstraint {
@@ -1745,6 +1819,16 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
17451819 )
17461820 )
17471821 or
1822+ exists (
1823+ Declaration target , TypePath prefix , TypePath requiredPrefix , TypePath suffix ,
1824+ TypeParameter tp
1825+ |
1826+ AccessBaseType:: baseTypeMatchAtTypeParameter ( a , e , apos , target , tp , prefix ,
1827+ requiredPrefix ) and
1828+ typeMatch ( a , e , target , requiredPrefix .appendInverse ( suffix ) , result , tp ) and
1829+ path = prefix .append ( suffix )
1830+ )
1831+ or
17481832 exists (
17491833 Declaration target , TypePath prefix , TypeMention constraint ,
17501834 TypePath pathToTypeParamInConstraint , TypePath pathToTypeParamInSub
0 commit comments