Skip to content

Commit ce2a345

Browse files
committed
Sema: Allow parameterized protocol types without 'any' as the underlying type of a typealias
Just as with an unconstrained protocol type appearing here, such a typealias can only be used on the right hand side of a conformance requirement, or as the base of an 'any' type.
1 parent 6d1f654 commit ce2a345

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/Sema/TypeCheckType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,13 @@ class TypeResolutionOptions {
288288
switch (context) {
289289
case Context::Inherited:
290290
case Context::ExtensionBinding:
291+
case Context::TypeAliasDecl:
292+
case Context::GenericTypeAliasDecl:
291293
case Context::GenericRequirement:
292294
case Context::ExistentialConstraint:
293295
case Context::MetatypeBase:
294296
return true;
295297
case Context::None:
296-
case Context::TypeAliasDecl:
297-
case Context::GenericTypeAliasDecl:
298298
case Context::InExpression:
299299
case Context::ExplicitCastExpr:
300300
case Context::ForEachStmt:

test/type/parameterized_protocol.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,19 @@ extension Sequence<Int> {
180180
}
181181

182182

183+
/// Constraint aliases
184+
185+
typealias SequenceOfInt = Sequence<Int>
186+
typealias SequenceOf<T> = Sequence<T>
187+
188+
// CHECK-LABEL: .testConstraintAlias1@
189+
// CHECK-NEXT: Generic signature: <T where T : Sequence, T.[Sequence]Element == Int>
190+
func testConstraintAlias1<T : SequenceOfInt>(_: T) {}
191+
192+
// CHECK-LABEL: .testConstraintAlias2@
193+
// CHECK-NEXT: Generic signature: <T where T : Sequence, T.[Sequence]Element == String>
194+
func testConstraintAlias2<T : SequenceOf<String>>(_: T) {}
195+
183196
/// Protocol compositions
184197

185198
// CHECK-LABEL: .testComposition1@

0 commit comments

Comments
 (0)