From 0abb4c907ef494c5c29d351b6e7844a9ee9491c1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 28 Feb 2016 19:44:18 -0800 Subject: [PATCH 1/6] Added tests. --- ...TypeInBasePropertyAndDerivedContainerOfBase01.ts | 13 +++++++++++++ .../recurringTypeParamForContainerOfBase01.ts | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts create mode 100644 tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts diff --git a/tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts b/tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts new file mode 100644 index 0000000000000..6597f32adc901 --- /dev/null +++ b/tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts @@ -0,0 +1,13 @@ +// @declaration: true + +interface BoxOfFoo { + item: T +} + +interface Foo { + self: this; +} + +interface Bar extends Foo { + other: BoxOfFoo; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts b/tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts new file mode 100644 index 0000000000000..e8484d30f9512 --- /dev/null +++ b/tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts @@ -0,0 +1,13 @@ +// @declaration: true + +interface BoxOfFoo> { + item: T +} + +interface Foo> { + self: T; +} + +interface Bar> extends Foo { + other: BoxOfFoo; +} \ No newline at end of file From daf15963a35d02e16a371e92e3b1b5f2b0f84bd9 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 28 Feb 2016 19:57:44 -0800 Subject: [PATCH 2/6] Accepted baselines. --- .../recurringTypeParamForContainerOfBase01.js | 27 ++++++++++++++ ...rringTypeParamForContainerOfBase01.symbols | 37 +++++++++++++++++++ ...curringTypeParamForContainerOfBase01.types | 37 +++++++++++++++++++ ...ertyAndDerivedContainerOfBase01.errors.txt | 24 ++++++++++++ ...BasePropertyAndDerivedContainerOfBase01.js | 27 ++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 tests/baselines/reference/recurringTypeParamForContainerOfBase01.js create mode 100644 tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols create mode 100644 tests/baselines/reference/recurringTypeParamForContainerOfBase01.types create mode 100644 tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt create mode 100644 tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.js diff --git a/tests/baselines/reference/recurringTypeParamForContainerOfBase01.js b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.js new file mode 100644 index 0000000000000..b3ef0cba312f2 --- /dev/null +++ b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.js @@ -0,0 +1,27 @@ +//// [recurringTypeParamForContainerOfBase01.ts] + +interface BoxOfFoo> { + item: T +} + +interface Foo> { + self: T; +} + +interface Bar> extends Foo { + other: BoxOfFoo; +} + +//// [recurringTypeParamForContainerOfBase01.js] + + +//// [recurringTypeParamForContainerOfBase01.d.ts] +interface BoxOfFoo> { + item: T; +} +interface Foo> { + self: T; +} +interface Bar> extends Foo { + other: BoxOfFoo; +} diff --git a/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols new file mode 100644 index 0000000000000..f0a5eafeae26c --- /dev/null +++ b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts === + +interface BoxOfFoo> { +>BoxOfFoo : Symbol(BoxOfFoo, Decl(recurringTypeParamForContainerOfBase01.ts, 0, 0)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19)) +>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19)) + + item: T +>item : Symbol(item, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 38)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19)) +} + +interface Foo> { +>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14)) +>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14)) + + self: T; +>self : Symbol(self, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 33)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14)) +} + +interface Bar> extends Foo { +>Bar : Symbol(Bar, Decl(recurringTypeParamForContainerOfBase01.ts, 7, 1)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14)) +>Bar : Symbol(Bar, Decl(recurringTypeParamForContainerOfBase01.ts, 7, 1)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14)) +>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14)) + + other: BoxOfFoo; +>other : Symbol(other, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 48)) +>BoxOfFoo : Symbol(BoxOfFoo, Decl(recurringTypeParamForContainerOfBase01.ts, 0, 0)) +>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14)) +} diff --git a/tests/baselines/reference/recurringTypeParamForContainerOfBase01.types b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.types new file mode 100644 index 0000000000000..38b23263f01d4 --- /dev/null +++ b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts === + +interface BoxOfFoo> { +>BoxOfFoo : BoxOfFoo +>T : T +>Foo : Foo +>T : T + + item: T +>item : T +>T : T +} + +interface Foo> { +>Foo : Foo +>T : T +>Foo : Foo +>T : T + + self: T; +>self : T +>T : T +} + +interface Bar> extends Foo { +>Bar : Bar +>T : T +>Bar : Bar +>T : T +>Foo : Foo +>T : T + + other: BoxOfFoo; +>other : BoxOfFoo +>BoxOfFoo : BoxOfFoo +>T : T +} diff --git a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt new file mode 100644 index 0000000000000..cde44b8a13ac8 --- /dev/null +++ b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts(11,21): error TS2344: Type 'this' does not satisfy the constraint 'Foo'. + Type 'Bar' is not assignable to type 'Foo'. + Types of property 'self' are incompatible. + Type 'Bar' is not assignable to type 'this'. + + +==== tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts (1 errors) ==== + + interface BoxOfFoo { + item: T + } + + interface Foo { + self: this; + } + + interface Bar extends Foo { + other: BoxOfFoo; + ~~~~ +!!! error TS2344: Type 'this' does not satisfy the constraint 'Foo'. +!!! error TS2344: Type 'Bar' is not assignable to type 'Foo'. +!!! error TS2344: Types of property 'self' are incompatible. +!!! error TS2344: Type 'Bar' is not assignable to type 'this'. + } \ No newline at end of file diff --git a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.js b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.js new file mode 100644 index 0000000000000..51cc5a24bb649 --- /dev/null +++ b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.js @@ -0,0 +1,27 @@ +//// [thisTypeInBasePropertyAndDerivedContainerOfBase01.ts] + +interface BoxOfFoo { + item: T +} + +interface Foo { + self: this; +} + +interface Bar extends Foo { + other: BoxOfFoo; +} + +//// [thisTypeInBasePropertyAndDerivedContainerOfBase01.js] + + +//// [thisTypeInBasePropertyAndDerivedContainerOfBase01.d.ts] +interface BoxOfFoo { + item: T; +} +interface Foo { + self: this; +} +interface Bar extends Foo { + other: BoxOfFoo; +} From cdd10b09b19797647cffe0996bd3dc846a14b6aa Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 28 Feb 2016 20:08:55 -0800 Subject: [PATCH 3/6] Instantiate type parameters with themselves as their 'this' type when relating. --- src/compiler/checker.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c2a14e5b9a04a..b5526e204cabf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5595,9 +5595,14 @@ namespace ts { if (source.flags & TypeFlags.TypeParameter) { let constraint = getConstraintOfTypeParameter(source); + if (!constraint || constraint.flags & TypeFlags.Any) { constraint = emptyObjectType; } + + // The constraint may need to be further instantiated with its 'this' type. + constraint = getTypeWithThisArgument(constraint); + // Report constraint errors only if the constraint is not the empty object type const reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { From 268b2d44fa508b9e8ccfc1b2b71d1b25967cf52e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 28 Feb 2016 20:22:46 -0800 Subject: [PATCH 4/6] Accepted baselines. --- tests/baselines/reference/fuzzy.errors.txt | 2 -- ...ertyAndDerivedContainerOfBase01.errors.txt | 24 ----------------- ...ropertyAndDerivedContainerOfBase01.symbols | 27 +++++++++++++++++++ ...ePropertyAndDerivedContainerOfBase01.types | 27 +++++++++++++++++++ 4 files changed, 54 insertions(+), 26 deletions(-) delete mode 100644 tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt create mode 100644 tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols create mode 100644 tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.types diff --git a/tests/baselines/reference/fuzzy.errors.txt b/tests/baselines/reference/fuzzy.errors.txt index 0aa8207ff9879..72ac4c816f9f7 100644 --- a/tests/baselines/reference/fuzzy.errors.txt +++ b/tests/baselines/reference/fuzzy.errors.txt @@ -4,7 +4,6 @@ tests/cases/compiler/fuzzy.ts(21,20): error TS2322: Type '{ anything: number; on Types of property 'oneI' are incompatible. Type 'this' is not assignable to type 'I'. Type 'C' is not assignable to type 'I'. - Property 'alsoWorks' is missing in type 'C'. tests/cases/compiler/fuzzy.ts(25,20): error TS2352: Neither type '{ oneI: this; }' nor type 'R' is assignable to the other. Property 'anything' is missing in type '{ oneI: this; }'. @@ -39,7 +38,6 @@ tests/cases/compiler/fuzzy.ts(25,20): error TS2352: Neither type '{ oneI: this; !!! error TS2322: Types of property 'oneI' are incompatible. !!! error TS2322: Type 'this' is not assignable to type 'I'. !!! error TS2322: Type 'C' is not assignable to type 'I'. -!!! error TS2322: Property 'alsoWorks' is missing in type 'C'. } worksToo():R { diff --git a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt deleted file mode 100644 index cde44b8a13ac8..0000000000000 --- a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts(11,21): error TS2344: Type 'this' does not satisfy the constraint 'Foo'. - Type 'Bar' is not assignable to type 'Foo'. - Types of property 'self' are incompatible. - Type 'Bar' is not assignable to type 'this'. - - -==== tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts (1 errors) ==== - - interface BoxOfFoo { - item: T - } - - interface Foo { - self: this; - } - - interface Bar extends Foo { - other: BoxOfFoo; - ~~~~ -!!! error TS2344: Type 'this' does not satisfy the constraint 'Foo'. -!!! error TS2344: Type 'Bar' is not assignable to type 'Foo'. -!!! error TS2344: Types of property 'self' are incompatible. -!!! error TS2344: Type 'Bar' is not assignable to type 'this'. - } \ No newline at end of file diff --git a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols new file mode 100644 index 0000000000000..379e4d3c8a49e --- /dev/null +++ b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols @@ -0,0 +1,27 @@ +=== tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts === + +interface BoxOfFoo { +>BoxOfFoo : Symbol(BoxOfFoo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 0, 0)) +>T : Symbol(T, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 19)) +>Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1)) + + item: T +>item : Symbol(item, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 35)) +>T : Symbol(T, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 19)) +} + +interface Foo { +>Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1)) + + self: this; +>self : Symbol(self, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 5, 15)) +} + +interface Bar extends Foo { +>Bar : Symbol(Bar, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 7, 1)) +>Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1)) + + other: BoxOfFoo; +>other : Symbol(other, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 9, 27)) +>BoxOfFoo : Symbol(BoxOfFoo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 0, 0)) +} diff --git a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.types b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.types new file mode 100644 index 0000000000000..9f6b83df05748 --- /dev/null +++ b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.types @@ -0,0 +1,27 @@ +=== tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts === + +interface BoxOfFoo { +>BoxOfFoo : BoxOfFoo +>T : T +>Foo : Foo + + item: T +>item : T +>T : T +} + +interface Foo { +>Foo : Foo + + self: this; +>self : this +} + +interface Bar extends Foo { +>Bar : Bar +>Foo : Foo + + other: BoxOfFoo; +>other : BoxOfFoo +>BoxOfFoo : BoxOfFoo +} From ee4baef51fba69ed6fcd9ea89cd44d3f77f21a46 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 1 May 2016 21:08:53 -0700 Subject: [PATCH 5/6] Applied suggested change. --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ef53b6e7d6136..f182ce899ce46 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5912,7 +5912,7 @@ namespace ts { } // The constraint may need to be further instantiated with its 'this' type. - constraint = getTypeWithThisArgument(constraint); + constraint = getTypeWithThisArgument(constraint, source); // Report constraint errors only if the constraint is not the empty object type const reportConstraintErrors = reportErrors && constraint !== emptyObjectType; From b75605e55e7425f1f763b56bcefa64f1b8c2a1f6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 1 May 2016 21:53:27 -0700 Subject: [PATCH 6/6] Accepted baselines. --- .../recurringTypeParamForContainerOfBase01.symbols | 6 +++--- ...hisTypeInBasePropertyAndDerivedContainerOfBase01.symbols | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols index f0a5eafeae26c..48ea1ffa0cf5c 100644 --- a/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols +++ b/tests/baselines/reference/recurringTypeParamForContainerOfBase01.symbols @@ -7,7 +7,7 @@ interface BoxOfFoo> { >T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19)) item: T ->item : Symbol(item, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 38)) +>item : Symbol(BoxOfFoo.item, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 38)) >T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19)) } @@ -18,7 +18,7 @@ interface Foo> { >T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14)) self: T; ->self : Symbol(self, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 33)) +>self : Symbol(Foo.self, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 33)) >T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14)) } @@ -31,7 +31,7 @@ interface Bar> extends Foo { >T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14)) other: BoxOfFoo; ->other : Symbol(other, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 48)) +>other : Symbol(Bar.other, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 48)) >BoxOfFoo : Symbol(BoxOfFoo, Decl(recurringTypeParamForContainerOfBase01.ts, 0, 0)) >T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14)) } diff --git a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols index 379e4d3c8a49e..566bf3aa0935e 100644 --- a/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols +++ b/tests/baselines/reference/thisTypeInBasePropertyAndDerivedContainerOfBase01.symbols @@ -6,7 +6,7 @@ interface BoxOfFoo { >Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1)) item: T ->item : Symbol(item, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 35)) +>item : Symbol(BoxOfFoo.item, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 35)) >T : Symbol(T, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 19)) } @@ -14,7 +14,7 @@ interface Foo { >Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1)) self: this; ->self : Symbol(self, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 5, 15)) +>self : Symbol(Foo.self, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 5, 15)) } interface Bar extends Foo { @@ -22,6 +22,6 @@ interface Bar extends Foo { >Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1)) other: BoxOfFoo; ->other : Symbol(other, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 9, 27)) +>other : Symbol(Bar.other, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 9, 27)) >BoxOfFoo : Symbol(BoxOfFoo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 0, 0)) }