PR feedback and another test

This commit is contained in:
Jason Freeman 2015-05-07 14:35:58 -07:00
parent d8ef7b612a
commit bb7f617e72
4 changed files with 114 additions and 1 deletions

View File

@ -3574,7 +3574,8 @@ module ts {
// Since removeSubtypes checks the subtype relation, and the subtype relation on a union
// may attempt to reduce a union, it is possible that removeSubtypes could be called
// recursively on the same set of types.
// recursively on the same set of types. The removeSubtypesStack is used to track which
// sets of types are currently undergoing subtype reduction.
let removeSubtypesStack: string[] = [];
function removeSubtypes(types: Type[]) {
let typeListId = getTypeListId(types);

View File

@ -0,0 +1,45 @@
tests/cases/compiler/unionTypeWithRecursiveSubtypeReduction2.ts(19,1): error TS2322: Type 'Property' is not assignable to type 'Class'.
Types of property 'parent' are incompatible.
Type 'Module | Class' is not assignable to type 'Namespace'.
Type 'Class' is not assignable to type 'Namespace'.
Property 'members' is missing in type 'Class'.
tests/cases/compiler/unionTypeWithRecursiveSubtypeReduction2.ts(20,1): error TS2322: Type 'Class' is not assignable to type 'Property'.
Types of property 'parent' are incompatible.
Type 'Namespace' is not assignable to type 'Module | Class'.
Type 'Namespace' is not assignable to type 'Class'.
Property 'parent' is missing in type 'Namespace'.
==== tests/cases/compiler/unionTypeWithRecursiveSubtypeReduction2.ts (2 errors) ====
class Module {
public members: Class[];
}
class Namespace {
public members: (Class | Property)[];
}
class Class {
public parent: Namespace;
}
class Property {
public parent: Module | Class;
}
var c: Class;
var p: Property;
c = p;
~
!!! error TS2322: Type 'Property' is not assignable to type 'Class'.
!!! error TS2322: Types of property 'parent' are incompatible.
!!! error TS2322: Type 'Module | Class' is not assignable to type 'Namespace'.
!!! error TS2322: Type 'Class' is not assignable to type 'Namespace'.
!!! error TS2322: Property 'members' is missing in type 'Class'.
p = c;
~
!!! error TS2322: Type 'Class' is not assignable to type 'Property'.
!!! error TS2322: Types of property 'parent' are incompatible.
!!! error TS2322: Type 'Namespace' is not assignable to type 'Module | Class'.
!!! error TS2322: Type 'Namespace' is not assignable to type 'Class'.
!!! error TS2322: Property 'parent' is missing in type 'Namespace'.

View File

@ -0,0 +1,47 @@
//// [unionTypeWithRecursiveSubtypeReduction2.ts]
class Module {
public members: Class[];
}
class Namespace {
public members: (Class | Property)[];
}
class Class {
public parent: Namespace;
}
class Property {
public parent: Module | Class;
}
var c: Class;
var p: Property;
c = p;
p = c;
//// [unionTypeWithRecursiveSubtypeReduction2.js]
var Module = (function () {
function Module() {
}
return Module;
})();
var Namespace = (function () {
function Namespace() {
}
return Namespace;
})();
var Class = (function () {
function Class() {
}
return Class;
})();
var Property = (function () {
function Property() {
}
return Property;
})();
var c;
var p;
c = p;
p = c;

View File

@ -0,0 +1,20 @@
class Module {
public members: Class[];
}
class Namespace {
public members: (Class | Property)[];
}
class Class {
public parent: Namespace;
}
class Property {
public parent: Module | Class;
}
var c: Class;
var p: Property;
c = p;
p = c;