Skip to content

Commit c2b41ac

Browse files
committed
Add test case showing buggy behavior.
1 parent 910595d commit c2b41ac

File tree

5 files changed

+285
-0
lines changed

5 files changed

+285
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
tests/cases/compiler/higherKindedTypesLift3.ts(24,7): error TS2322: Type 'LC' is not assignable to type 'number[]'.
2+
3+
4+
==== tests/cases/compiler/higherKindedTypesLift3.ts (1 errors) ====
5+
interface StaticFunctor<CS<_TS>> {
6+
<AS, BS>(csas: CS<AS>, fmapstatic: (a: AS) => BS): CS<BS>;
7+
}
8+
9+
10+
interface LiftedResult<LC<_LT>> {
11+
<LA, LB>(lmap: (a: LA) => LB): (a: LC<LA>) => LC<LB>;
12+
}
13+
14+
declare function lift<C<_T>>(fToLift: StaticFunctor<C>): LiftedResult<C>
15+
16+
17+
declare const myArrayFunctor: StaticFunctor<Array>
18+
19+
const liftedArray = lift(myArrayFunctor);
20+
21+
declare function stringLength(strarg: string): number
22+
23+
const liftedStringLength = liftedArray(stringLength);
24+
25+
declare const arrayOfStrings: Array<string>;
26+
27+
const result = liftedStringLength(arrayOfStrings);
28+
const expectedType: Array<number> = result;
29+
~~~~~~~~~~~~
30+
!!! error TS2322: Type 'LC' is not assignable to type 'number[]'.
31+
32+
const expectError = liftedStringLength(result)
33+
34+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [higherKindedTypesLift3.ts]
2+
interface StaticFunctor<CS<_TS>> {
3+
<AS, BS>(csas: CS<AS>, fmapstatic: (a: AS) => BS): CS<BS>;
4+
}
5+
6+
7+
interface LiftedResult<LC<_LT>> {
8+
<LA, LB>(lmap: (a: LA) => LB): (a: LC<LA>) => LC<LB>;
9+
}
10+
11+
declare function lift<C<_T>>(fToLift: StaticFunctor<C>): LiftedResult<C>
12+
13+
14+
declare const myArrayFunctor: StaticFunctor<Array>
15+
16+
const liftedArray = lift(myArrayFunctor);
17+
18+
declare function stringLength(strarg: string): number
19+
20+
const liftedStringLength = liftedArray(stringLength);
21+
22+
declare const arrayOfStrings: Array<string>;
23+
24+
const result = liftedStringLength(arrayOfStrings);
25+
const expectedType: Array<number> = result;
26+
27+
const expectError = liftedStringLength(result)
28+
29+
30+
31+
//// [higherKindedTypesLift3.js]
32+
"use strict";
33+
var liftedArray = lift(myArrayFunctor);
34+
var liftedStringLength = liftedArray(stringLength);
35+
var result = liftedStringLength(arrayOfStrings);
36+
var expectedType = result;
37+
var expectError = liftedStringLength(result);
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
=== tests/cases/compiler/higherKindedTypesLift3.ts ===
2+
interface StaticFunctor<CS<_TS>> {
3+
>StaticFunctor : Symbol(StaticFunctor, Decl(higherKindedTypesLift3.ts, 0, 0))
4+
>CS : Symbol(CS, Decl(higherKindedTypesLift3.ts, 0, 24))
5+
>_TS : Symbol(_TS, Decl(higherKindedTypesLift3.ts, 0, 27))
6+
7+
<AS, BS>(csas: CS<AS>, fmapstatic: (a: AS) => BS): CS<BS>;
8+
>AS : Symbol(AS, Decl(higherKindedTypesLift3.ts, 1, 5))
9+
>BS : Symbol(BS, Decl(higherKindedTypesLift3.ts, 1, 8))
10+
>csas : Symbol(csas, Decl(higherKindedTypesLift3.ts, 1, 13))
11+
>CS : Symbol(CS, Decl(higherKindedTypesLift3.ts, 0, 24))
12+
>AS : Symbol(AS, Decl(higherKindedTypesLift3.ts, 1, 5))
13+
>fmapstatic : Symbol(fmapstatic, Decl(higherKindedTypesLift3.ts, 1, 26))
14+
>a : Symbol(a, Decl(higherKindedTypesLift3.ts, 1, 40))
15+
>AS : Symbol(AS, Decl(higherKindedTypesLift3.ts, 1, 5))
16+
>BS : Symbol(BS, Decl(higherKindedTypesLift3.ts, 1, 8))
17+
>CS : Symbol(CS, Decl(higherKindedTypesLift3.ts, 0, 24))
18+
>BS : Symbol(BS, Decl(higherKindedTypesLift3.ts, 1, 8))
19+
}
20+
21+
22+
interface LiftedResult<LC<_LT>> {
23+
>LiftedResult : Symbol(LiftedResult, Decl(higherKindedTypesLift3.ts, 2, 1))
24+
>LC : Symbol(LC, Decl(higherKindedTypesLift3.ts, 5, 23))
25+
>_LT : Symbol(_LT, Decl(higherKindedTypesLift3.ts, 5, 26))
26+
27+
<LA, LB>(lmap: (a: LA) => LB): (a: LC<LA>) => LC<LB>;
28+
>LA : Symbol(LA, Decl(higherKindedTypesLift3.ts, 6, 5))
29+
>LB : Symbol(LB, Decl(higherKindedTypesLift3.ts, 6, 8))
30+
>lmap : Symbol(lmap, Decl(higherKindedTypesLift3.ts, 6, 13))
31+
>a : Symbol(a, Decl(higherKindedTypesLift3.ts, 6, 20))
32+
>LA : Symbol(LA, Decl(higherKindedTypesLift3.ts, 6, 5))
33+
>LB : Symbol(LB, Decl(higherKindedTypesLift3.ts, 6, 8))
34+
>a : Symbol(a, Decl(higherKindedTypesLift3.ts, 6, 36))
35+
>LC : Symbol(LC, Decl(higherKindedTypesLift3.ts, 5, 23))
36+
>LA : Symbol(LA, Decl(higherKindedTypesLift3.ts, 6, 5))
37+
>LC : Symbol(LC, Decl(higherKindedTypesLift3.ts, 5, 23))
38+
>LB : Symbol(LB, Decl(higherKindedTypesLift3.ts, 6, 8))
39+
}
40+
41+
declare function lift<C<_T>>(fToLift: StaticFunctor<C>): LiftedResult<C>
42+
>lift : Symbol(lift, Decl(higherKindedTypesLift3.ts, 7, 1))
43+
>C : Symbol(C, Decl(higherKindedTypesLift3.ts, 9, 22))
44+
>_T : Symbol(_T, Decl(higherKindedTypesLift3.ts, 9, 24))
45+
>fToLift : Symbol(fToLift, Decl(higherKindedTypesLift3.ts, 9, 29))
46+
>StaticFunctor : Symbol(StaticFunctor, Decl(higherKindedTypesLift3.ts, 0, 0))
47+
>C : Symbol(C, Decl(higherKindedTypesLift3.ts, 9, 22))
48+
>LiftedResult : Symbol(LiftedResult, Decl(higherKindedTypesLift3.ts, 2, 1))
49+
>C : Symbol(C, Decl(higherKindedTypesLift3.ts, 9, 22))
50+
51+
52+
declare const myArrayFunctor: StaticFunctor<Array>
53+
>myArrayFunctor : Symbol(myArrayFunctor, Decl(higherKindedTypesLift3.ts, 12, 13))
54+
>StaticFunctor : Symbol(StaticFunctor, Decl(higherKindedTypesLift3.ts, 0, 0))
55+
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
56+
57+
const liftedArray = lift(myArrayFunctor);
58+
>liftedArray : Symbol(liftedArray, Decl(higherKindedTypesLift3.ts, 14, 5))
59+
>lift : Symbol(lift, Decl(higherKindedTypesLift3.ts, 7, 1))
60+
>myArrayFunctor : Symbol(myArrayFunctor, Decl(higherKindedTypesLift3.ts, 12, 13))
61+
62+
declare function stringLength(strarg: string): number
63+
>stringLength : Symbol(stringLength, Decl(higherKindedTypesLift3.ts, 14, 41))
64+
>strarg : Symbol(strarg, Decl(higherKindedTypesLift3.ts, 16, 30))
65+
66+
const liftedStringLength = liftedArray(stringLength);
67+
>liftedStringLength : Symbol(liftedStringLength, Decl(higherKindedTypesLift3.ts, 18, 5))
68+
>liftedArray : Symbol(liftedArray, Decl(higherKindedTypesLift3.ts, 14, 5))
69+
>stringLength : Symbol(stringLength, Decl(higherKindedTypesLift3.ts, 14, 41))
70+
71+
declare const arrayOfStrings: Array<string>;
72+
>arrayOfStrings : Symbol(arrayOfStrings, Decl(higherKindedTypesLift3.ts, 20, 13))
73+
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
74+
75+
const result = liftedStringLength(arrayOfStrings);
76+
>result : Symbol(result, Decl(higherKindedTypesLift3.ts, 22, 5))
77+
>liftedStringLength : Symbol(liftedStringLength, Decl(higherKindedTypesLift3.ts, 18, 5))
78+
>arrayOfStrings : Symbol(arrayOfStrings, Decl(higherKindedTypesLift3.ts, 20, 13))
79+
80+
const expectedType: Array<number> = result;
81+
>expectedType : Symbol(expectedType, Decl(higherKindedTypesLift3.ts, 23, 5))
82+
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
83+
>result : Symbol(result, Decl(higherKindedTypesLift3.ts, 22, 5))
84+
85+
const expectError = liftedStringLength(result)
86+
>expectError : Symbol(expectError, Decl(higherKindedTypesLift3.ts, 25, 5))
87+
>liftedStringLength : Symbol(liftedStringLength, Decl(higherKindedTypesLift3.ts, 18, 5))
88+
>result : Symbol(result, Decl(higherKindedTypesLift3.ts, 22, 5))
89+
90+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
=== tests/cases/compiler/higherKindedTypesLift3.ts ===
2+
interface StaticFunctor<CS<_TS>> {
3+
>StaticFunctor : StaticFunctor<CS>
4+
>CS : CS
5+
>_TS : _TS
6+
7+
<AS, BS>(csas: CS<AS>, fmapstatic: (a: AS) => BS): CS<BS>;
8+
>AS : AS
9+
>BS : BS
10+
>csas : CS
11+
>CS : CS
12+
>AS : AS
13+
>fmapstatic : (a: AS) => BS
14+
>a : AS
15+
>AS : AS
16+
>BS : BS
17+
>CS : CS
18+
>BS : BS
19+
}
20+
21+
22+
interface LiftedResult<LC<_LT>> {
23+
>LiftedResult : LiftedResult<LC>
24+
>LC : LC
25+
>_LT : _LT
26+
27+
<LA, LB>(lmap: (a: LA) => LB): (a: LC<LA>) => LC<LB>;
28+
>LA : LA
29+
>LB : LB
30+
>lmap : (a: LA) => LB
31+
>a : LA
32+
>LA : LA
33+
>LB : LB
34+
>a : LC
35+
>LC : LC
36+
>LA : LA
37+
>LC : LC
38+
>LB : LB
39+
}
40+
41+
declare function lift<C<_T>>(fToLift: StaticFunctor<C>): LiftedResult<C>
42+
>lift : <C>(fToLift: StaticFunctor<C>) => LiftedResult<C>
43+
>C : C
44+
>_T : _T
45+
>fToLift : StaticFunctor<C>
46+
>StaticFunctor : StaticFunctor<CS>
47+
>C : C
48+
>LiftedResult : LiftedResult<LC>
49+
>C : C
50+
51+
52+
declare const myArrayFunctor: StaticFunctor<Array>
53+
>myArrayFunctor : StaticFunctor<T[]>
54+
>StaticFunctor : StaticFunctor<CS>
55+
>Array : T[]
56+
57+
const liftedArray = lift(myArrayFunctor);
58+
>liftedArray : LiftedResult<T[]>
59+
>lift(myArrayFunctor) : LiftedResult<T[]>
60+
>lift : <C>(fToLift: StaticFunctor<C>) => LiftedResult<C>
61+
>myArrayFunctor : StaticFunctor<T[]>
62+
63+
declare function stringLength(strarg: string): number
64+
>stringLength : (strarg: string) => number
65+
>strarg : string
66+
67+
const liftedStringLength = liftedArray(stringLength);
68+
>liftedStringLength : (a: LC) => LC
69+
>liftedArray(stringLength) : (a: LC) => LC
70+
>liftedArray : LiftedResult<T[]>
71+
>stringLength : (strarg: string) => number
72+
73+
declare const arrayOfStrings: Array<string>;
74+
>arrayOfStrings : string[]
75+
>Array : T[]
76+
77+
const result = liftedStringLength(arrayOfStrings);
78+
>result : LC
79+
>liftedStringLength(arrayOfStrings) : LC
80+
>liftedStringLength : (a: LC) => LC
81+
>arrayOfStrings : string[]
82+
83+
const expectedType: Array<number> = result;
84+
>expectedType : number[]
85+
>Array : T[]
86+
>result : LC
87+
88+
const expectError = liftedStringLength(result)
89+
>expectError : LC
90+
>liftedStringLength(result) : LC
91+
>liftedStringLength : (a: LC) => LC
92+
>result : LC
93+
94+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @strict: true
2+
3+
4+
interface StaticFunctor<CS<_TS>> {
5+
<AS, BS>(csas: CS<AS>, fmapstatic: (a: AS) => BS): CS<BS>;
6+
}
7+
8+
9+
interface LiftedResult<LC<_LT>> {
10+
<LA, LB>(lmap: (a: LA) => LB): (a: LC<LA>) => LC<LB>;
11+
}
12+
13+
declare function lift<C<_T>>(fToLift: StaticFunctor<C>): LiftedResult<C>
14+
15+
16+
declare const myArrayFunctor: StaticFunctor<Array>
17+
18+
const liftedArray = lift(myArrayFunctor);
19+
20+
declare function stringLength(strarg: string): number
21+
22+
const liftedStringLength = liftedArray(stringLength);
23+
24+
declare const arrayOfStrings: Array<string>;
25+
26+
const result = liftedStringLength(arrayOfStrings);
27+
const expectedType: Array<number> = result;
28+
29+
const expectError = liftedStringLength(result)
30+

0 commit comments

Comments
 (0)