Skip to content

Commit 5096fd8

Browse files
committed
Sema: Allow parameterized existential compositions
1 parent 797d0bf commit 5096fd8

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5680,11 +5680,7 @@ TypeResolver::resolveCompositionType(CompositionTypeRepr *repr,
56805680
continue;
56815681
}
56825682

5683-
// FIXME: Support compositions involving parameterized protocol types,
5684-
// like 'any Collection<String> & Sendable', etc.
5685-
if (ty->is<ParameterizedProtocolType>() &&
5686-
!options.isConstraintImplicitExistential() &&
5687-
options.getContext() != TypeResolverContext::ExistentialConstraint) {
5683+
if (ty->is<ParameterizedProtocolType>()) {
56885684
checkMember(tyR->getStartLoc(), ty);
56895685
Members.push_back(ty);
56905686
continue;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
func f1(_ s: any Sequence<Int> & Hashable) -> any Sequence<Int> {
4+
return s
5+
}
6+
7+
func f2(_ s: any Sequence<Int> & Hashable) -> any Hashable {
8+
return s
9+
}
10+
11+
func f3(_ s: any Sequence<Int> & Hashable) -> any Sequence {
12+
return s
13+
}
14+
15+
func f4(_ s: any Sequence<Int> & Hashable) -> any Sequence & Hashable {
16+
return s
17+
}
18+
19+
func f5(_ s: any Sequence<Int> & Hashable) -> any Sequence<Int> & Equatable {
20+
return s
21+
}
22+
23+
func f6(_ s: any Sequence<Int> & Hashable) -> any Sequence<String> & Hashable {
24+
return s // expected-error {{cannot convert return expression of type 'Int' to return type 'String'}}
25+
}
26+
27+
func f7(_ s: any Sequence<Int> & Hashable) -> any Sequence<String> {
28+
return s // expected-error {{cannot convert return expression of type 'Int' to return type 'String'}}
29+
}
30+
31+
func f8(_ s: any Collection<Int> & Hashable) -> any Sequence<Int> & Hashable {
32+
return s
33+
}

test/decl/protocol/existential_member_accesses_self_assoctype.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ protocol P1 {
8181
func invariantSelf11() -> Struct<Self>.InnerGeneric<Void>
8282
// https://github.com/apple/swift/issues/61934
8383
func invariantSelf12() -> any Sequence<Self>
84-
// FIXME
85-
// expected-error@+1 {{non-protocol, non-class type 'Sequence<Self>' cannot be used within a protocol-constrained type}}
8684
func invariantSelf13() -> any P1 & Sequence<Self>
8785
func invariantSelf14() -> (any Sequence<Self>).Type
8886
func invariantAssoc1(_: inout Q)
@@ -97,10 +95,8 @@ protocol P1 {
9795
func invariantAssoc10(_: any P1 & Class<Q>)
9896
func invariantAssoc11() -> Struct<Q>.InnerGeneric<Void>
9997
func invariantAssoc12() -> any Sequence<Q>
100-
// FIXME
101-
// expected-error@+1 {{non-protocol, non-class type 'Sequence<Self.Q>' cannot be used within a protocol-constrained type}}
10298
func invariantAssoc13() -> any P1 & Sequence<Q>
103-
func invariantAssoc14() -> (any Sequence<Q>).Type
99+
func invariantAssoc14() -> (any Sequence<Q>).Type
104100

105101
// Properties
106102
var covariantSelfProp1: Self { get }

test/type/parameterized_existential.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,6 @@ func typeExpr() {
8282
_ = (any Sequence<Int>).self
8383
}
8484

85-
/// Not supported as a protocol composition term for now
86-
87-
protocol SomeProto {}
88-
89-
func protocolCompositionNotSupported1(_: SomeProto & Sequence<Int>) {}
90-
// expected-error@-1 {{non-protocol, non-class type 'Sequence<Int>' cannot be used within a protocol-constrained type}}
91-
92-
func protocolCompositionNotSupported2(_: any SomeProto & Sequence<Int>) {}
93-
// expected-error@-1 {{non-protocol, non-class type 'Sequence<Int>' cannot be used within a protocol-constrained type}}
94-
9585
func increment(_ n : any Collection<Float>) {
9686
for value in n {
9787
_ = value + 1

0 commit comments

Comments
 (0)