Skip to content

Commit 244f7f7

Browse files
committed
Consolidate and update higherKindedTypes tests.
1 parent 9f8b5d6 commit 244f7f7

20 files changed

+1604
-1611
lines changed

tests/baselines/reference/higherKindedTypes.errors.txt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
tests/cases/compiler/higherKindedTypes.ts(37,5): error TS2719: Type 'F' is not assignable to type 'F'. Two different types with this name exist, but they are unrelated.
2-
Type 'Functor<F, A>' is not assignable to type 'F'.
2+
Type 'Functor<A, F>' is not assignable to type 'F'.
33
Types of property 'map' are incompatible.
44
Type '<B>(f: (a: A) => B) => F' is not assignable to type '<B>(f: (a: B) => B) => F'.
55
Types of parameters 'f' and 'f' are incompatible.
66
Types of parameters 'a' and 'a' are incompatible.
77
Type 'A' is not assignable to type 'B'.
8+
tests/cases/compiler/higherKindedTypes.ts(42,23): error TS2339: Property 'map' does not exist on type 'F'.
89

910

10-
==== tests/cases/compiler/higherKindedTypes.ts (1 errors) ====
11-
interface Functor<Container<_T>, A> {
11+
==== tests/cases/compiler/higherKindedTypes.ts (2 errors) ====
12+
interface Functor<A, Container<_T>> {
1213
map<B>(f: (a: A) => B): Container<B>;
1314
}
1415

15-
interface FunctorX<A> extends Functor<FunctorX, A> {
16+
interface FunctorX<A> extends Functor<A, FunctorX> {
1617
map<B>(f: (a: A) => B): FunctorX<B>;
1718
xVal: string;
1819
}
1920

20-
interface FunctorY<A> extends Functor<FunctorY, A> {
21+
interface FunctorY<A> extends Functor<A, FunctorY> {
2122
map<B>(f: (a: A) => B): FunctorY<B>;
2223
yVal: A;
2324
}
@@ -38,23 +39,31 @@ tests/cases/compiler/higherKindedTypes.ts(37,5): error TS2719: Type 'F' is not a
3839
const expectY2: FunctorY<string[]> = resultY2;
3940

4041

41-
function staticMap<F<_T> extends Functor<F, _T>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
42+
function staticMap<F<_T> extends Functor<_T, F>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
4243
const result = fa.map(f);
4344
return result;
4445
}
4546

46-
function staticMapBadImplementation<F<_T> extends Functor<F, _T>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
47+
function staticMapBadImplementation<F<_T> extends Functor<_T, F>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
4748
return fa;
4849
~~~~~~~~~~
4950
!!! error TS2719: Type 'F' is not assignable to type 'F'. Two different types with this name exist, but they are unrelated.
50-
!!! error TS2719: Type 'Functor<F, A>' is not assignable to type 'F'.
51+
!!! error TS2719: Type 'Functor<A, F>' is not assignable to type 'F'.
5152
!!! error TS2719: Types of property 'map' are incompatible.
5253
!!! error TS2719: Type '<B>(f: (a: A) => B) => F' is not assignable to type '<B>(f: (a: B) => B) => F'.
5354
!!! error TS2719: Types of parameters 'f' and 'f' are incompatible.
5455
!!! error TS2719: Types of parameters 'a' and 'a' are incompatible.
5556
!!! error TS2719: Type 'A' is not assignable to type 'B'.
5657
}
5758

59+
function staticMapNoConstraint<F<_T>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
60+
// expect error here since F has no constraint so we have no idea what shape it will be
61+
const result = fa.map(f);
62+
~~~
63+
!!! error TS2339: Property 'map' does not exist on type 'F'.
64+
return result;
65+
}
66+
5867
const resultX3 = staticMap(initialX, val => val.length);
5968
const expectX3: FunctorX<number> = resultX3;
6069

tests/baselines/reference/higherKindedTypes.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//// [higherKindedTypes.ts]
2-
interface Functor<Container<_T>, A> {
2+
interface Functor<A, Container<_T>> {
33
map<B>(f: (a: A) => B): Container<B>;
44
}
55

6-
interface FunctorX<A> extends Functor<FunctorX, A> {
6+
interface FunctorX<A> extends Functor<A, FunctorX> {
77
map<B>(f: (a: A) => B): FunctorX<B>;
88
xVal: string;
99
}
1010

11-
interface FunctorY<A> extends Functor<FunctorY, A> {
11+
interface FunctorY<A> extends Functor<A, FunctorY> {
1212
map<B>(f: (a: A) => B): FunctorY<B>;
1313
yVal: A;
1414
}
@@ -29,15 +29,21 @@ const resultY2 = initialY.map(val => [val]);
2929
const expectY2: FunctorY<string[]> = resultY2;
3030

3131

32-
function staticMap<F<_T> extends Functor<F, _T>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
32+
function staticMap<F<_T> extends Functor<_T, F>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
3333
const result = fa.map(f);
3434
return result;
3535
}
3636

37-
function staticMapBadImplementation<F<_T> extends Functor<F, _T>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
37+
function staticMapBadImplementation<F<_T> extends Functor<_T, F>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
3838
return fa;
3939
}
4040

41+
function staticMapNoConstraint<F<_T>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
42+
// expect error here since F has no constraint so we have no idea what shape it will be
43+
const result = fa.map(f);
44+
return result;
45+
}
46+
4147
const resultX3 = staticMap(initialX, val => val.length);
4248
const expectX3: FunctorX<number> = resultX3;
4349

@@ -68,6 +74,11 @@ function staticMap(fa, f) {
6874
function staticMapBadImplementation(fa, f) {
6975
return fa;
7076
}
77+
function staticMapNoConstraint(fa, f) {
78+
// expect error here since F has no constraint so we have no idea what shape it will be
79+
var result = fa.map(f);
80+
return result;
81+
}
7182
var resultX3 = staticMap(initialX, function (val) { return val.length; });
7283
var expectX3 = resultX3;
7384
var resultY3 = staticMap(initialY, function (val) { return val.length; });

tests/baselines/reference/higherKindedTypes.symbols

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
=== tests/cases/compiler/higherKindedTypes.ts ===
2-
interface Functor<Container<_T>, A> {
2+
interface Functor<A, Container<_T>> {
33
>Functor : Symbol(Functor, Decl(higherKindedTypes.ts, 0, 0))
4-
>Container : Symbol(Container, Decl(higherKindedTypes.ts, 0, 18))
5-
>_T : Symbol(_T, Decl(higherKindedTypes.ts, 0, 28))
6-
>A : Symbol(A, Decl(higherKindedTypes.ts, 0, 32))
4+
>A : Symbol(A, Decl(higherKindedTypes.ts, 0, 18))
5+
>Container : Symbol(Container, Decl(higherKindedTypes.ts, 0, 20))
6+
>_T : Symbol(_T, Decl(higherKindedTypes.ts, 0, 31))
77

88
map<B>(f: (a: A) => B): Container<B>;
99
>map : Symbol(Functor.map, Decl(higherKindedTypes.ts, 0, 37))
1010
>B : Symbol(B, Decl(higherKindedTypes.ts, 1, 8))
1111
>f : Symbol(f, Decl(higherKindedTypes.ts, 1, 11))
1212
>a : Symbol(a, Decl(higherKindedTypes.ts, 1, 15))
13-
>A : Symbol(A, Decl(higherKindedTypes.ts, 0, 32))
13+
>A : Symbol(A, Decl(higherKindedTypes.ts, 0, 18))
1414
>B : Symbol(B, Decl(higherKindedTypes.ts, 1, 8))
15-
>Container : Symbol(Container, Decl(higherKindedTypes.ts, 0, 18))
15+
>Container : Symbol(Container, Decl(higherKindedTypes.ts, 0, 20))
1616
>B : Symbol(B, Decl(higherKindedTypes.ts, 1, 8))
1717
}
1818

19-
interface FunctorX<A> extends Functor<FunctorX, A> {
19+
interface FunctorX<A> extends Functor<A, FunctorX> {
2020
>FunctorX : Symbol(FunctorX, Decl(higherKindedTypes.ts, 2, 1))
2121
>A : Symbol(A, Decl(higherKindedTypes.ts, 4, 19))
2222
>Functor : Symbol(Functor, Decl(higherKindedTypes.ts, 0, 0))
23-
>FunctorX : Symbol(FunctorX, Decl(higherKindedTypes.ts, 2, 1))
2423
>A : Symbol(A, Decl(higherKindedTypes.ts, 4, 19))
24+
>FunctorX : Symbol(FunctorX, Decl(higherKindedTypes.ts, 2, 1))
2525

2626
map<B>(f: (a: A) => B): FunctorX<B>;
2727
>map : Symbol(FunctorX.map, Decl(higherKindedTypes.ts, 4, 52))
@@ -37,12 +37,12 @@ interface FunctorX<A> extends Functor<FunctorX, A> {
3737
>xVal : Symbol(FunctorX.xVal, Decl(higherKindedTypes.ts, 5, 40))
3838
}
3939

40-
interface FunctorY<A> extends Functor<FunctorY, A> {
40+
interface FunctorY<A> extends Functor<A, FunctorY> {
4141
>FunctorY : Symbol(FunctorY, Decl(higherKindedTypes.ts, 7, 1))
4242
>A : Symbol(A, Decl(higherKindedTypes.ts, 9, 19))
4343
>Functor : Symbol(Functor, Decl(higherKindedTypes.ts, 0, 0))
44-
>FunctorY : Symbol(FunctorY, Decl(higherKindedTypes.ts, 7, 1))
4544
>A : Symbol(A, Decl(higherKindedTypes.ts, 9, 19))
45+
>FunctorY : Symbol(FunctorY, Decl(higherKindedTypes.ts, 7, 1))
4646

4747
map<B>(f: (a: A) => B): FunctorY<B>;
4848
>map : Symbol(FunctorY.map, Decl(higherKindedTypes.ts, 9, 52))
@@ -124,13 +124,13 @@ const expectY2: FunctorY<string[]> = resultY2;
124124
>resultY2 : Symbol(resultY2, Decl(higherKindedTypes.ts, 26, 5))
125125

126126

127-
function staticMap<F<_T> extends Functor<F, _T>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
127+
function staticMap<F<_T> extends Functor<_T, F>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
128128
>staticMap : Symbol(staticMap, Decl(higherKindedTypes.ts, 27, 46))
129129
>F : Symbol(F, Decl(higherKindedTypes.ts, 30, 19))
130130
>_T : Symbol(_T, Decl(higherKindedTypes.ts, 30, 21))
131131
>Functor : Symbol(Functor, Decl(higherKindedTypes.ts, 0, 0))
132-
>F : Symbol(F, Decl(higherKindedTypes.ts, 30, 19))
133132
>_T : Symbol(_T, Decl(higherKindedTypes.ts, 30, 21))
133+
>F : Symbol(F, Decl(higherKindedTypes.ts, 30, 19))
134134
>A : Symbol(A, Decl(higherKindedTypes.ts, 30, 48))
135135
>B : Symbol(B, Decl(higherKindedTypes.ts, 30, 51))
136136
>fa : Symbol(fa, Decl(higherKindedTypes.ts, 30, 55))
@@ -154,13 +154,13 @@ function staticMap<F<_T> extends Functor<F, _T>, A, B>(fa: F<A>, f: (a: A) => B)
154154
>result : Symbol(result, Decl(higherKindedTypes.ts, 31, 9))
155155
}
156156

157-
function staticMapBadImplementation<F<_T> extends Functor<F, _T>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
157+
function staticMapBadImplementation<F<_T> extends Functor<_T, F>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
158158
>staticMapBadImplementation : Symbol(staticMapBadImplementation, Decl(higherKindedTypes.ts, 33, 1))
159159
>F : Symbol(F, Decl(higherKindedTypes.ts, 35, 36))
160160
>_T : Symbol(_T, Decl(higherKindedTypes.ts, 35, 38))
161161
>Functor : Symbol(Functor, Decl(higherKindedTypes.ts, 0, 0))
162-
>F : Symbol(F, Decl(higherKindedTypes.ts, 35, 36))
163162
>_T : Symbol(_T, Decl(higherKindedTypes.ts, 35, 38))
163+
>F : Symbol(F, Decl(higherKindedTypes.ts, 35, 36))
164164
>A : Symbol(A, Decl(higherKindedTypes.ts, 35, 65))
165165
>B : Symbol(B, Decl(higherKindedTypes.ts, 35, 68))
166166
>fa : Symbol(fa, Decl(higherKindedTypes.ts, 35, 72))
@@ -177,55 +177,81 @@ function staticMapBadImplementation<F<_T> extends Functor<F, _T>, A, B>(fa: F<A>
177177
>fa : Symbol(fa, Decl(higherKindedTypes.ts, 35, 72))
178178
}
179179

180+
function staticMapNoConstraint<F<_T>, A, B>(fa: F<A>, f: (a: A) => B): F<B> {
181+
>staticMapNoConstraint : Symbol(staticMapNoConstraint, Decl(higherKindedTypes.ts, 37, 1))
182+
>F : Symbol(F, Decl(higherKindedTypes.ts, 39, 31))
183+
>_T : Symbol(_T, Decl(higherKindedTypes.ts, 39, 33))
184+
>A : Symbol(A, Decl(higherKindedTypes.ts, 39, 37))
185+
>B : Symbol(B, Decl(higherKindedTypes.ts, 39, 40))
186+
>fa : Symbol(fa, Decl(higherKindedTypes.ts, 39, 44))
187+
>F : Symbol(F, Decl(higherKindedTypes.ts, 39, 31))
188+
>A : Symbol(A, Decl(higherKindedTypes.ts, 39, 37))
189+
>f : Symbol(f, Decl(higherKindedTypes.ts, 39, 53))
190+
>a : Symbol(a, Decl(higherKindedTypes.ts, 39, 58))
191+
>A : Symbol(A, Decl(higherKindedTypes.ts, 39, 37))
192+
>B : Symbol(B, Decl(higherKindedTypes.ts, 39, 40))
193+
>F : Symbol(F, Decl(higherKindedTypes.ts, 39, 31))
194+
>B : Symbol(B, Decl(higherKindedTypes.ts, 39, 40))
195+
196+
// expect error here since F has no constraint so we have no idea what shape it will be
197+
const result = fa.map(f);
198+
>result : Symbol(result, Decl(higherKindedTypes.ts, 41, 9))
199+
>fa : Symbol(fa, Decl(higherKindedTypes.ts, 39, 44))
200+
>f : Symbol(f, Decl(higherKindedTypes.ts, 39, 53))
201+
202+
return result;
203+
>result : Symbol(result, Decl(higherKindedTypes.ts, 41, 9))
204+
}
205+
180206
const resultX3 = staticMap(initialX, val => val.length);
181-
>resultX3 : Symbol(resultX3, Decl(higherKindedTypes.ts, 39, 5))
207+
>resultX3 : Symbol(resultX3, Decl(higherKindedTypes.ts, 45, 5))
182208
>staticMap : Symbol(staticMap, Decl(higherKindedTypes.ts, 27, 46))
183209
>initialX : Symbol(initialX, Decl(higherKindedTypes.ts, 14, 13))
184-
>val : Symbol(val, Decl(higherKindedTypes.ts, 39, 36))
210+
>val : Symbol(val, Decl(higherKindedTypes.ts, 45, 36))
185211
>val.length : Symbol(String.length, Decl(lib.d.ts, --, --))
186-
>val : Symbol(val, Decl(higherKindedTypes.ts, 39, 36))
212+
>val : Symbol(val, Decl(higherKindedTypes.ts, 45, 36))
187213
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
188214

189215
const expectX3: FunctorX<number> = resultX3;
190-
>expectX3 : Symbol(expectX3, Decl(higherKindedTypes.ts, 40, 5))
216+
>expectX3 : Symbol(expectX3, Decl(higherKindedTypes.ts, 46, 5))
191217
>FunctorX : Symbol(FunctorX, Decl(higherKindedTypes.ts, 2, 1))
192-
>resultX3 : Symbol(resultX3, Decl(higherKindedTypes.ts, 39, 5))
218+
>resultX3 : Symbol(resultX3, Decl(higherKindedTypes.ts, 45, 5))
193219

194220
const resultY3 = staticMap(initialY, val => val.length);
195-
>resultY3 : Symbol(resultY3, Decl(higherKindedTypes.ts, 42, 5))
221+
>resultY3 : Symbol(resultY3, Decl(higherKindedTypes.ts, 48, 5))
196222
>staticMap : Symbol(staticMap, Decl(higherKindedTypes.ts, 27, 46))
197223
>initialY : Symbol(initialY, Decl(higherKindedTypes.ts, 15, 13))
198-
>val : Symbol(val, Decl(higherKindedTypes.ts, 42, 36))
224+
>val : Symbol(val, Decl(higherKindedTypes.ts, 48, 36))
199225
>val.length : Symbol(String.length, Decl(lib.d.ts, --, --))
200-
>val : Symbol(val, Decl(higherKindedTypes.ts, 42, 36))
226+
>val : Symbol(val, Decl(higherKindedTypes.ts, 48, 36))
201227
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
202228

203229
const expectY3: FunctorY<number> = resultY3;
204-
>expectY3 : Symbol(expectY3, Decl(higherKindedTypes.ts, 43, 5))
230+
>expectY3 : Symbol(expectY3, Decl(higherKindedTypes.ts, 49, 5))
205231
>FunctorY : Symbol(FunctorY, Decl(higherKindedTypes.ts, 7, 1))
206-
>resultY3 : Symbol(resultY3, Decl(higherKindedTypes.ts, 42, 5))
232+
>resultY3 : Symbol(resultY3, Decl(higherKindedTypes.ts, 48, 5))
207233

208234
const resultX4 = staticMap(initialX, val => [val]);
209-
>resultX4 : Symbol(resultX4, Decl(higherKindedTypes.ts, 45, 5))
235+
>resultX4 : Symbol(resultX4, Decl(higherKindedTypes.ts, 51, 5))
210236
>staticMap : Symbol(staticMap, Decl(higherKindedTypes.ts, 27, 46))
211237
>initialX : Symbol(initialX, Decl(higherKindedTypes.ts, 14, 13))
212-
>val : Symbol(val, Decl(higherKindedTypes.ts, 45, 36))
213-
>val : Symbol(val, Decl(higherKindedTypes.ts, 45, 36))
238+
>val : Symbol(val, Decl(higherKindedTypes.ts, 51, 36))
239+
>val : Symbol(val, Decl(higherKindedTypes.ts, 51, 36))
214240

215241
const expectX4: FunctorX<string[]> = resultX4;
216-
>expectX4 : Symbol(expectX4, Decl(higherKindedTypes.ts, 46, 5))
242+
>expectX4 : Symbol(expectX4, Decl(higherKindedTypes.ts, 52, 5))
217243
>FunctorX : Symbol(FunctorX, Decl(higherKindedTypes.ts, 2, 1))
218-
>resultX4 : Symbol(resultX4, Decl(higherKindedTypes.ts, 45, 5))
244+
>resultX4 : Symbol(resultX4, Decl(higherKindedTypes.ts, 51, 5))
219245

220246
const resultY4 = staticMap(initialY, val => [val]);
221-
>resultY4 : Symbol(resultY4, Decl(higherKindedTypes.ts, 48, 5))
247+
>resultY4 : Symbol(resultY4, Decl(higherKindedTypes.ts, 54, 5))
222248
>staticMap : Symbol(staticMap, Decl(higherKindedTypes.ts, 27, 46))
223249
>initialY : Symbol(initialY, Decl(higherKindedTypes.ts, 15, 13))
224-
>val : Symbol(val, Decl(higherKindedTypes.ts, 48, 36))
225-
>val : Symbol(val, Decl(higherKindedTypes.ts, 48, 36))
250+
>val : Symbol(val, Decl(higherKindedTypes.ts, 54, 36))
251+
>val : Symbol(val, Decl(higherKindedTypes.ts, 54, 36))
226252

227253
const expectY4: FunctorY<string[]> = resultY4;
228-
>expectY4 : Symbol(expectY4, Decl(higherKindedTypes.ts, 49, 5))
254+
>expectY4 : Symbol(expectY4, Decl(higherKindedTypes.ts, 55, 5))
229255
>FunctorY : Symbol(FunctorY, Decl(higherKindedTypes.ts, 7, 1))
230-
>resultY4 : Symbol(resultY4, Decl(higherKindedTypes.ts, 48, 5))
256+
>resultY4 : Symbol(resultY4, Decl(higherKindedTypes.ts, 54, 5))
231257

0 commit comments

Comments
 (0)