Skip to content

Commit

Permalink
show issues: overload selection (microsoft#17471), composition
Browse files Browse the repository at this point in the history
  • Loading branch information
KiaraGrouwstra committed Aug 24, 2017
1 parent 636b4ac commit a76ba38
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/baselines/reference/overloadSelection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//// [overloadSelection.ts]
interface Match {
(o: object): 0;
(o: any): 1;
}
type Wrap = <T = RegExp>(v: T) => Match(T);
type A = Wrap(RegExp);
// falls thru to 1, `object` checked not with generic val `RegExp` but with its constraint (generic `any`)


//// [overloadSelection.js]
// falls thru to 1, `object` checked not with generic val `RegExp` but with its constraint (generic `any`)
26 changes: 26 additions & 0 deletions tests/baselines/reference/overloadSelection.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=== tests/cases/compiler/overloadSelection.ts ===
interface Match {
>Match : Symbol(Match, Decl(overloadSelection.ts, 0, 0))

(o: object): 0;
>o : Symbol(o, Decl(overloadSelection.ts, 1, 3))

(o: any): 1;
>o : Symbol(o, Decl(overloadSelection.ts, 2, 3))
}
type Wrap = <T = RegExp>(v: T) => Match(T);
>Wrap : Symbol(Wrap, Decl(overloadSelection.ts, 3, 1))
>T : Symbol(T, Decl(overloadSelection.ts, 4, 13))
>RegExp : Symbol(RegExp, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>v : Symbol(v, Decl(overloadSelection.ts, 4, 25))
>T : Symbol(T, Decl(overloadSelection.ts, 4, 13))
>Match : Symbol(Match, Decl(overloadSelection.ts, 0, 0))
>T : Symbol(T, Decl(overloadSelection.ts, 4, 13))

type A = Wrap(RegExp);
>A : Symbol(A, Decl(overloadSelection.ts, 4, 43))
>Wrap : Symbol(Wrap, Decl(overloadSelection.ts, 3, 1))
>RegExp : Symbol(RegExp, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))

// falls thru to 1, `object` checked not with generic val `RegExp` but with its constraint (generic `any`)

26 changes: 26 additions & 0 deletions tests/baselines/reference/overloadSelection.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=== tests/cases/compiler/overloadSelection.ts ===
interface Match {
>Match : Match

(o: object): 0;
>o : object

(o: any): 1;
>o : any
}
type Wrap = <T = RegExp>(v: T) => Match(T);
>Wrap : Wrap
>T : T
>RegExp : RegExp
>v : T
>T : T
>Match : Match
>T : T

type A = Wrap(RegExp);
>A : 1
>Wrap : Wrap
>RegExp : RegExp

// falls thru to 1, `object` checked not with generic val `RegExp` but with its constraint (generic `any`)

6 changes: 6 additions & 0 deletions tests/baselines/reference/typeCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ type regexpIsPrimitive3 = genericIsPrimitive3(RegExp)

type map = <Fn extends Function, O extends object>(fn: Fn, obj: O) => { [P in keyof O]: Fn(P) }; // Fn(O[P])
type z = map(<T>(v: T) => [T], { a: 1, b: 2, c: 3 });

// binary function composition, still fails
type Fn1<T extends number> = (v: T[]) => { [k: string]: T };
type Fn2<T> = (v: { [k: string]: T }) => ReadonlyArray<T>;
type Fn3<T> = (v: T) => Fn2(Fn1(T));
type Fn4 = Fn3(1);


//// [typeCall.js]
Expand Down
31 changes: 31 additions & 0 deletions tests/baselines/reference/typeCall.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,34 @@ type z = map(<T>(v: T) => [T], { a: 1, b: 2, c: 3 });
>b : Symbol(b, Decl(typeCall.ts, 56, 38))
>c : Symbol(c, Decl(typeCall.ts, 56, 44))

// binary function composition, still fails
type Fn1<T extends number> = (v: T[]) => { [k: string]: T };
>Fn1 : Symbol(Fn1, Decl(typeCall.ts, 56, 53))
>T : Symbol(T, Decl(typeCall.ts, 59, 9))
>v : Symbol(v, Decl(typeCall.ts, 59, 30))
>T : Symbol(T, Decl(typeCall.ts, 59, 9))
>k : Symbol(k, Decl(typeCall.ts, 59, 44))
>T : Symbol(T, Decl(typeCall.ts, 59, 9))

type Fn2<T> = (v: { [k: string]: T }) => ReadonlyArray<T>;
>Fn2 : Symbol(Fn2, Decl(typeCall.ts, 59, 60))
>T : Symbol(T, Decl(typeCall.ts, 60, 9))
>v : Symbol(v, Decl(typeCall.ts, 60, 15))
>k : Symbol(k, Decl(typeCall.ts, 60, 21))
>T : Symbol(T, Decl(typeCall.ts, 60, 9))
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(typeCall.ts, 60, 9))

type Fn3<T> = (v: T) => Fn2(Fn1(T));
>Fn3 : Symbol(Fn3, Decl(typeCall.ts, 60, 58))
>T : Symbol(T, Decl(typeCall.ts, 61, 9))
>v : Symbol(v, Decl(typeCall.ts, 61, 15))
>T : Symbol(T, Decl(typeCall.ts, 61, 9))
>Fn2 : Symbol(Fn2, Decl(typeCall.ts, 59, 60))
>Fn1 : Symbol(Fn1, Decl(typeCall.ts, 56, 53))
>T : Symbol(T, Decl(typeCall.ts, 61, 9))

type Fn4 = Fn3(1);
>Fn4 : Symbol(Fn4, Decl(typeCall.ts, 61, 36))
>Fn3 : Symbol(Fn3, Decl(typeCall.ts, 60, 58))

33 changes: 32 additions & 1 deletion tests/baselines/reference/typeCall.types
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ type stringIsPrimitive = IsPrimitive(string); // '1', ok
>IsPrimitive : IsPrimitive

type regexpIsPrimitive = IsPrimitive(RegExp); // '0', ok
>regexpIsPrimitive : "0"
>regexpIsPrimitive : "1"
>IsPrimitive : IsPrimitive
>RegExp : RegExp

Expand Down Expand Up @@ -183,3 +183,34 @@ type z = map(<T>(v: T) => [T], { a: 1, b: 2, c: 3 });
>b : 2
>c : 3

// binary function composition, still fails
type Fn1<T extends number> = (v: T[]) => { [k: string]: T };
>Fn1 : Fn1<T>
>T : T
>v : T[]
>T : T
>k : string
>T : T

type Fn2<T> = (v: { [k: string]: T }) => ReadonlyArray<T>;
>Fn2 : Fn2<T>
>T : T
>v : { [k: string]: T; }
>k : string
>T : T
>ReadonlyArray : ReadonlyArray<T>
>T : T

type Fn3<T> = (v: T) => Fn2(Fn1(T));
>Fn3 : Fn3<T>
>T : T
>v : T
>T : T
>Fn2 : Fn2<T>
>Fn1 : Fn1<T>
>T : T

type Fn4 = Fn3(1);
>Fn4 : any
>Fn3 : Fn3<T>

9 changes: 9 additions & 0 deletions tests/cases/compiler/overloadSelection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @allowSyntheticDefaultImports: true

interface Match {
(o: object): 0;
(o: any): 1;
}
type Wrap = <T = RegExp>(v: T) => Match(T);
type A = Wrap(RegExp);
// falls thru to 1, `object` checked not with generic val `RegExp` but with its constraint (generic `any`)
6 changes: 6 additions & 0 deletions tests/cases/compiler/typeCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ type regexpIsPrimitive3 = genericIsPrimitive3(RegExp)

type map = <Fn extends Function, O extends object>(fn: Fn, obj: O) => { [P in keyof O]: Fn(P) }; // Fn(O[P])
type z = map(<T>(v: T) => [T], { a: 1, b: 2, c: 3 });

// binary function composition, still fails
type Fn1<T extends number> = (v: T[]) => { [k: string]: T };
type Fn2<T> = (v: { [k: string]: T }) => ReadonlyArray<T>;
type Fn3<T> = (v: T) => Fn2(Fn1(T));
type Fn4 = Fn3(1);

0 comments on commit a76ba38

Please sign in to comment.