mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Addressing feedback and adding regression tests
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
//// [checkInfiniteExpansionTermination.ts]
|
||||
// Regression test for #1002
|
||||
// Before fix this code would cause infinite loop
|
||||
|
||||
interface IObservable<T> {
|
||||
n: IObservable<T[]>; // Needed, must be T[]
|
||||
}
|
||||
|
||||
// Needed
|
||||
interface ISubject<T> extends IObservable<T> { }
|
||||
|
||||
interface Foo { x }
|
||||
interface Bar { y }
|
||||
|
||||
var values: IObservable<Foo>;
|
||||
var values2: ISubject<Bar>;
|
||||
values = values2;
|
||||
|
||||
|
||||
//// [checkInfiniteExpansionTermination.js]
|
||||
// Regression test for #1002
|
||||
// Before fix this code would cause infinite loop
|
||||
var values;
|
||||
var values2;
|
||||
values = values2;
|
||||
@@ -0,0 +1,44 @@
|
||||
=== tests/cases/compiler/checkInfiniteExpansionTermination.ts ===
|
||||
// Regression test for #1002
|
||||
// Before fix this code would cause infinite loop
|
||||
|
||||
interface IObservable<T> {
|
||||
>IObservable : IObservable<T>
|
||||
>T : T
|
||||
|
||||
n: IObservable<T[]>; // Needed, must be T[]
|
||||
>n : IObservable<T[]>
|
||||
>IObservable : IObservable<T>
|
||||
>T : T
|
||||
}
|
||||
|
||||
// Needed
|
||||
interface ISubject<T> extends IObservable<T> { }
|
||||
>ISubject : ISubject<T>
|
||||
>T : T
|
||||
>IObservable : IObservable<T>
|
||||
>T : T
|
||||
|
||||
interface Foo { x }
|
||||
>Foo : Foo
|
||||
>x : any
|
||||
|
||||
interface Bar { y }
|
||||
>Bar : Bar
|
||||
>y : any
|
||||
|
||||
var values: IObservable<Foo>;
|
||||
>values : IObservable<Foo>
|
||||
>IObservable : IObservable<T>
|
||||
>Foo : Foo
|
||||
|
||||
var values2: ISubject<Bar>;
|
||||
>values2 : ISubject<Bar>
|
||||
>ISubject : ISubject<T>
|
||||
>Bar : Bar
|
||||
|
||||
values = values2;
|
||||
>values = values2 : ISubject<Bar>
|
||||
>values : IObservable<Foo>
|
||||
>values2 : ISubject<Bar>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//// [checkInfiniteExpansionTermination2.ts]
|
||||
// Regression test for #1002
|
||||
// Before fix this code would cause infinite loop
|
||||
|
||||
interface IObservable<T> {
|
||||
n: IObservable<T[]>;
|
||||
}
|
||||
interface ISubject<T> extends IObservable<T> { }
|
||||
|
||||
declare function combineLatest<TOther>(x: IObservable<TOther>[]): void;
|
||||
declare function combineLatest(): void;
|
||||
|
||||
function fn<T>() {
|
||||
var values: ISubject<any>[] = [];
|
||||
// Hang when using <T>, but not <any>
|
||||
combineLatest<T>(values);
|
||||
}
|
||||
|
||||
|
||||
//// [checkInfiniteExpansionTermination2.js]
|
||||
// Regression test for #1002
|
||||
// Before fix this code would cause infinite loop
|
||||
function fn() {
|
||||
var values = [];
|
||||
// Hang when using <T>, but not <any>
|
||||
combineLatest(values);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
=== tests/cases/compiler/checkInfiniteExpansionTermination2.ts ===
|
||||
// Regression test for #1002
|
||||
// Before fix this code would cause infinite loop
|
||||
|
||||
interface IObservable<T> {
|
||||
>IObservable : IObservable<T>
|
||||
>T : T
|
||||
|
||||
n: IObservable<T[]>;
|
||||
>n : IObservable<T[]>
|
||||
>IObservable : IObservable<T>
|
||||
>T : T
|
||||
}
|
||||
interface ISubject<T> extends IObservable<T> { }
|
||||
>ISubject : ISubject<T>
|
||||
>T : T
|
||||
>IObservable : IObservable<T>
|
||||
>T : T
|
||||
|
||||
declare function combineLatest<TOther>(x: IObservable<TOther>[]): void;
|
||||
>combineLatest : { <TOther>(x: IObservable<TOther>[]): void; (): void; }
|
||||
>TOther : TOther
|
||||
>x : IObservable<TOther>[]
|
||||
>IObservable : IObservable<T>
|
||||
>TOther : TOther
|
||||
|
||||
declare function combineLatest(): void;
|
||||
>combineLatest : { <TOther>(x: IObservable<TOther>[]): void; (): void; }
|
||||
|
||||
function fn<T>() {
|
||||
>fn : <T>() => void
|
||||
>T : T
|
||||
|
||||
var values: ISubject<any>[] = [];
|
||||
>values : ISubject<any>[]
|
||||
>ISubject : ISubject<T>
|
||||
>[] : undefined[]
|
||||
|
||||
// Hang when using <T>, but not <any>
|
||||
combineLatest<T>(values);
|
||||
>combineLatest<T>(values) : void
|
||||
>combineLatest : { <TOther>(x: IObservable<TOther>[]): void; (): void; }
|
||||
>T : T
|
||||
>values : ISubject<any>[]
|
||||
}
|
||||
|
||||
45
tests/baselines/reference/typeComparisonCaching.errors.txt
Normal file
45
tests/baselines/reference/typeComparisonCaching.errors.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
tests/cases/compiler/typeComparisonCaching.ts(26,1): error TS2323: Type 'B' is not assignable to type 'A'.
|
||||
Types of property 's' are incompatible.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/compiler/typeComparisonCaching.ts(27,1): error TS2323: Type 'D' is not assignable to type 'C'.
|
||||
Types of property 'q' are incompatible.
|
||||
Type 'B' is not assignable to type 'A'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/typeComparisonCaching.ts (2 errors) ====
|
||||
// Check that we only cache results of type comparisons that are free of assumptions
|
||||
|
||||
interface A {
|
||||
p: C;
|
||||
s: string;
|
||||
}
|
||||
|
||||
interface B {
|
||||
p: D;
|
||||
s: number;
|
||||
}
|
||||
|
||||
interface C {
|
||||
q: A;
|
||||
}
|
||||
|
||||
interface D {
|
||||
q: B;
|
||||
}
|
||||
|
||||
var a: A;
|
||||
var b: B;
|
||||
var c: C;
|
||||
var d: D;
|
||||
|
||||
a = b;
|
||||
~
|
||||
!!! error TS2323: Type 'B' is not assignable to type 'A'.
|
||||
!!! error TS2323: Types of property 's' are incompatible.
|
||||
!!! error TS2323: Type 'number' is not assignable to type 'string'.
|
||||
c = d; // Should not be allowed
|
||||
~
|
||||
!!! error TS2323: Type 'D' is not assignable to type 'C'.
|
||||
!!! error TS2323: Types of property 'q' are incompatible.
|
||||
!!! error TS2323: Type 'B' is not assignable to type 'A'.
|
||||
|
||||
38
tests/baselines/reference/typeComparisonCaching.js
Normal file
38
tests/baselines/reference/typeComparisonCaching.js
Normal file
@@ -0,0 +1,38 @@
|
||||
//// [typeComparisonCaching.ts]
|
||||
// Check that we only cache results of type comparisons that are free of assumptions
|
||||
|
||||
interface A {
|
||||
p: C;
|
||||
s: string;
|
||||
}
|
||||
|
||||
interface B {
|
||||
p: D;
|
||||
s: number;
|
||||
}
|
||||
|
||||
interface C {
|
||||
q: A;
|
||||
}
|
||||
|
||||
interface D {
|
||||
q: B;
|
||||
}
|
||||
|
||||
var a: A;
|
||||
var b: B;
|
||||
var c: C;
|
||||
var d: D;
|
||||
|
||||
a = b;
|
||||
c = d; // Should not be allowed
|
||||
|
||||
|
||||
//// [typeComparisonCaching.js]
|
||||
// Check that we only cache results of type comparisons that are free of assumptions
|
||||
var a;
|
||||
var b;
|
||||
var c;
|
||||
var d;
|
||||
a = b;
|
||||
c = d; // Should not be allowed
|
||||
16
tests/cases/compiler/checkInfiniteExpansionTermination.ts
Normal file
16
tests/cases/compiler/checkInfiniteExpansionTermination.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
// Regression test for #1002
|
||||
// Before fix this code would cause infinite loop
|
||||
|
||||
interface IObservable<T> {
|
||||
n: IObservable<T[]>; // Needed, must be T[]
|
||||
}
|
||||
|
||||
// Needed
|
||||
interface ISubject<T> extends IObservable<T> { }
|
||||
|
||||
interface Foo { x }
|
||||
interface Bar { y }
|
||||
|
||||
var values: IObservable<Foo>;
|
||||
var values2: ISubject<Bar>;
|
||||
values = values2;
|
||||
16
tests/cases/compiler/checkInfiniteExpansionTermination2.ts
Normal file
16
tests/cases/compiler/checkInfiniteExpansionTermination2.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
// Regression test for #1002
|
||||
// Before fix this code would cause infinite loop
|
||||
|
||||
interface IObservable<T> {
|
||||
n: IObservable<T[]>;
|
||||
}
|
||||
interface ISubject<T> extends IObservable<T> { }
|
||||
|
||||
declare function combineLatest<TOther>(x: IObservable<TOther>[]): void;
|
||||
declare function combineLatest(): void;
|
||||
|
||||
function fn<T>() {
|
||||
var values: ISubject<any>[] = [];
|
||||
// Hang when using <T>, but not <any>
|
||||
combineLatest<T>(values);
|
||||
}
|
||||
27
tests/cases/compiler/typeComparisonCaching.ts
Normal file
27
tests/cases/compiler/typeComparisonCaching.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
// Check that we only cache results of type comparisons that are free of assumptions
|
||||
|
||||
interface A {
|
||||
p: C;
|
||||
s: string;
|
||||
}
|
||||
|
||||
interface B {
|
||||
p: D;
|
||||
s: number;
|
||||
}
|
||||
|
||||
interface C {
|
||||
q: A;
|
||||
}
|
||||
|
||||
interface D {
|
||||
q: B;
|
||||
}
|
||||
|
||||
var a: A;
|
||||
var b: B;
|
||||
var c: C;
|
||||
var d: D;
|
||||
|
||||
a = b;
|
||||
c = d; // Should not be allowed
|
||||
Reference in New Issue
Block a user