Skip to content

Commit 1cb0764

Browse files
Merge pull request #60972 from AnthonyLatsis/typealias-test
tests: Add a missing `typealias` test case and verifications for a few FIXMEs
2 parents f1e0dc0 + 5d61a5d commit 1cb0764

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

test/decl/typealias/generic.swift

+36-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
struct MyType<TyA, TyB> { // expected-note {{generic type 'MyType' declared here}}
44
// expected-note @-1 {{arguments to generic parameter 'TyB' ('S' and 'Int') are expected to be equal}}
5-
// expected-note @-2 4 {{arguments to generic parameter 'TyA' ('Float' and 'Int') are expected to be equal}}
5+
// expected-note @-2 6 {{arguments to generic parameter 'TyA' ('Float' and 'Int') are expected to be equal}}
6+
// expected-note @-3 2 {{arguments to generic parameter 'TyA' ('Float' and 'Double') are expected to be equal}}
7+
// expected-note @-4 2 {{arguments to generic parameter 'TyB' ('Int' and 'Float') are expected to be equal}}
8+
// expected-note @-5 2 {{arguments to generic parameter 'TyB' ('Double' and 'Float') are expected to be equal}}
69
var a : TyA, b : TyB
710
}
811

@@ -24,6 +27,22 @@ let _: OurType<Int, String>
2427
let _: YourType<Int>
2528
let _: Container.YourType<Int>
2629

30+
// The question of whether a type alias is implicitly generic should not
31+
// arise until after we attempt to resolve the underlying type.
32+
do {
33+
struct Outer<T> {
34+
typealias NotGeneric = Outer
35+
struct Inner<U> {
36+
typealias NotGeneric = Outer
37+
}
38+
}
39+
40+
let _: Outer<Int>.NotGeneric<Bool>
41+
// expected-error@-1 {{cannot specialize non-generic type 'Outer<Int>.NotGeneric' (aka 'Outer<Int>')}}
42+
let _: Outer<Int>.Inner<Never>.NotGeneric<Bool>
43+
// expected-error@-1 {{cannot specialize non-generic type 'Outer<Int>.Inner<Never>.NotGeneric' (aka 'Outer<Int>')}}
44+
}
45+
2746
//
2847
// Bona-fide generic type aliases
2948
//
@@ -246,8 +265,14 @@ let _: ConcreteStruct.O<Int> = ConcreteStruct.O<Int>(123)
246265
// In the other cases, we manage to fold the UnresolvedSpecializeExpr in the
247266
// precheckExpression() phase, which handles generic typealiases correctly.
248267

249-
let _ = GenericClass.TA<Float>(a: 4.0, b: 1) // FIXME
250-
let _ = GenericClass.TA<Float>(a: 1, b: 4.0)
268+
do {
269+
let x1 = GenericClass.TA<Float>(a: 4.0, b: 1) // FIXME
270+
let x2 = GenericClass.TA<Float>(a: 1, b: 4.0) // FIXME
271+
272+
// FIXME: Should not diagnose
273+
let _: MyType<Double, Float> = x1 // expected-error {{cannot assign value of type 'MyType<Float, Int>' to type 'MyType<Double, Float>'}}
274+
let _: MyType<Int, Float> = x2 // expected-error {{cannot assign value of type 'MyType<Float, Double>' to type 'MyType<Int, Float>'}}
275+
}
251276

252277
let _ = GenericClass<Int>.TA(a: 4.0, b: 1) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
253278
let _ = GenericClass<Int>.TA(a: 1, b: 4.0)
@@ -258,8 +283,14 @@ let _ = GenericClass<Int>.TA<Float>(a: 1, b: 4.0)
258283
let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1)
259284
let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0)
260285

261-
let _: GenericClass.TA = GenericClass.TA<Float>(a: 4.0, b: 1) // FIXME
262-
let _: GenericClass.TA = GenericClass.TA<Float>(a: 1, b: 4.0)
286+
do {
287+
let x1: GenericClass.TA = GenericClass.TA<Float>(a: 4.0, b: 1) // FIXME
288+
let x2: GenericClass.TA = GenericClass.TA<Float>(a: 1, b: 4.0) // FIXME
289+
290+
// FIXME: Should not diagnose
291+
let _: MyType<Double, Float> = x1 // expected-error {{cannot assign value of type 'MyType<Float, Int>' to type 'MyType<Double, Float>'}}
292+
let _: MyType<Int, Float> = x2 // expected-error {{cannot assign value of type 'MyType<Float, Double>' to type 'MyType<Int, Float>'}}
293+
}
263294

264295
let _: GenericClass.TA = GenericClass<Int>.TA(a: 4.0, b: 1) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
265296
let _: GenericClass.TA = GenericClass<Int>.TA(a: 1, b: 4.0)

0 commit comments

Comments
 (0)