Skip to content

Commit

Permalink
Add error elaboration test
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Oct 2, 2017
1 parent bff843a commit c2344e0
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tests/baselines/reference/strictFunctionTypesErrors.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,17 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(84,1): error TS2322: Type 'Fun
tests/cases/compiler/strictFunctionTypesErrors.ts(111,1): error TS2322: Type 'Comparer2<Dog>' is not assignable to type 'Comparer2<Animal>'.
Type 'Animal' is not assignable to type 'Dog'.
Property 'dog' is missing in type 'Animal'.
tests/cases/compiler/strictFunctionTypesErrors.ts(126,1): error TS2322: Type 'Crate<Dog>' is not assignable to type 'Crate<Animal>'.
Types of property 'onSetItem' are incompatible.
Type '(item: Dog) => void' is not assignable to type '(item: Animal) => void'.
Types of parameters 'item' and 'item' are incompatible.
Type 'Animal' is not assignable to type 'Dog'.
tests/cases/compiler/strictFunctionTypesErrors.ts(127,1): error TS2322: Type 'Crate<Animal>' is not assignable to type 'Crate<Dog>'.
Types of property 'item' are incompatible.
Type 'Animal' is not assignable to type 'Dog'.


==== tests/cases/compiler/strictFunctionTypesErrors.ts (29 errors) ====
==== tests/cases/compiler/strictFunctionTypesErrors.ts (31 errors) ====
export {}


Expand Down Expand Up @@ -304,4 +312,29 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(111,1): error TS2322: Type 'Co
!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'.
!!! error TS2322: Property 'dog' is missing in type 'Animal'.
dogComparer2 = animalComparer2; // Ok

// Crate<T> is invariant in --strictFunctionTypes mode

interface Crate<T> {
item: T;
onSetItem: (item: T) => void;
}

declare let animalCrate: Crate<Animal>;
declare let dogCrate: Crate<Dog>;

// Errors below should elaborate the reason for invariance

animalCrate = dogCrate; // Error
~~~~~~~~~~~
!!! error TS2322: Type 'Crate<Dog>' is not assignable to type 'Crate<Animal>'.
!!! error TS2322: Types of property 'onSetItem' are incompatible.
!!! error TS2322: Type '(item: Dog) => void' is not assignable to type '(item: Animal) => void'.
!!! error TS2322: Types of parameters 'item' and 'item' are incompatible.
!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'.
dogCrate = animalCrate; // Error
~~~~~~~~
!!! error TS2322: Type 'Crate<Animal>' is not assignable to type 'Crate<Dog>'.
!!! error TS2322: Types of property 'item' are incompatible.
!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'.

18 changes: 18 additions & 0 deletions tests/baselines/reference/strictFunctionTypesErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ declare let dogComparer2: Comparer2<Dog>;

animalComparer2 = dogComparer2; // Error
dogComparer2 = animalComparer2; // Ok

// Crate<T> is invariant in --strictFunctionTypes mode

interface Crate<T> {
item: T;
onSetItem: (item: T) => void;
}

declare let animalCrate: Crate<Animal>;
declare let dogCrate: Crate<Dog>;

// Errors below should elaborate the reason for invariance

animalCrate = dogCrate; // Error
dogCrate = animalCrate; // Error


//// [strictFunctionTypesErrors.js]
Expand Down Expand Up @@ -168,3 +183,6 @@ animalComparer1 = dogComparer1; // Ok
dogComparer1 = animalComparer1; // Ok
animalComparer2 = dogComparer2; // Error
dogComparer2 = animalComparer2; // Ok
// Errors below should elaborate the reason for invariance
animalCrate = dogCrate; // Error
dogCrate = animalCrate; // Error
36 changes: 36 additions & 0 deletions tests/baselines/reference/strictFunctionTypesErrors.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,39 @@ dogComparer2 = animalComparer2; // Ok
>dogComparer2 : Symbol(dogComparer2, Decl(strictFunctionTypesErrors.ts, 108, 11))
>animalComparer2 : Symbol(animalComparer2, Decl(strictFunctionTypesErrors.ts, 107, 11))

// Crate<T> is invariant in --strictFunctionTypes mode

interface Crate<T> {
>Crate : Symbol(Crate, Decl(strictFunctionTypesErrors.ts, 111, 31))
>T : Symbol(T, Decl(strictFunctionTypesErrors.ts, 115, 16))

item: T;
>item : Symbol(Crate.item, Decl(strictFunctionTypesErrors.ts, 115, 20))
>T : Symbol(T, Decl(strictFunctionTypesErrors.ts, 115, 16))

onSetItem: (item: T) => void;
>onSetItem : Symbol(Crate.onSetItem, Decl(strictFunctionTypesErrors.ts, 116, 12))
>item : Symbol(item, Decl(strictFunctionTypesErrors.ts, 117, 16))
>T : Symbol(T, Decl(strictFunctionTypesErrors.ts, 115, 16))
}

declare let animalCrate: Crate<Animal>;
>animalCrate : Symbol(animalCrate, Decl(strictFunctionTypesErrors.ts, 120, 11))
>Crate : Symbol(Crate, Decl(strictFunctionTypesErrors.ts, 111, 31))
>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8))

declare let dogCrate: Crate<Dog>;
>dogCrate : Symbol(dogCrate, Decl(strictFunctionTypesErrors.ts, 121, 11))
>Crate : Symbol(Crate, Decl(strictFunctionTypesErrors.ts, 111, 31))
>Dog : Symbol(Dog, Decl(strictFunctionTypesErrors.ts, 89, 33))

// Errors below should elaborate the reason for invariance

animalCrate = dogCrate; // Error
>animalCrate : Symbol(animalCrate, Decl(strictFunctionTypesErrors.ts, 120, 11))
>dogCrate : Symbol(dogCrate, Decl(strictFunctionTypesErrors.ts, 121, 11))

dogCrate = animalCrate; // Error
>dogCrate : Symbol(dogCrate, Decl(strictFunctionTypesErrors.ts, 121, 11))
>animalCrate : Symbol(animalCrate, Decl(strictFunctionTypesErrors.ts, 120, 11))

38 changes: 38 additions & 0 deletions tests/baselines/reference/strictFunctionTypesErrors.types
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,41 @@ dogComparer2 = animalComparer2; // Ok
>dogComparer2 : Comparer2<Dog>
>animalComparer2 : Comparer2<Animal>

// Crate<T> is invariant in --strictFunctionTypes mode

interface Crate<T> {
>Crate : Crate<T>
>T : T

item: T;
>item : T
>T : T

onSetItem: (item: T) => void;
>onSetItem : (item: T) => void
>item : T
>T : T
}

declare let animalCrate: Crate<Animal>;
>animalCrate : Crate<Animal>
>Crate : Crate<T>
>Animal : Animal

declare let dogCrate: Crate<Dog>;
>dogCrate : Crate<Dog>
>Crate : Crate<T>
>Dog : Dog

// Errors below should elaborate the reason for invariance

animalCrate = dogCrate; // Error
>animalCrate = dogCrate : Crate<Dog>
>animalCrate : Crate<Animal>
>dogCrate : Crate<Dog>

dogCrate = animalCrate; // Error
>dogCrate = animalCrate : Crate<Animal>
>dogCrate : Crate<Dog>
>animalCrate : Crate<Animal>

15 changes: 15 additions & 0 deletions tests/cases/compiler/strictFunctionTypesErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,18 @@ declare let dogComparer2: Comparer2<Dog>;

animalComparer2 = dogComparer2; // Error
dogComparer2 = animalComparer2; // Ok

// Crate<T> is invariant in --strictFunctionTypes mode

interface Crate<T> {
item: T;
onSetItem: (item: T) => void;
}

declare let animalCrate: Crate<Animal>;
declare let dogCrate: Crate<Dog>;

// Errors below should elaborate the reason for invariance

animalCrate = dogCrate; // Error
dogCrate = animalCrate; // Error

0 comments on commit c2344e0

Please sign in to comment.