Forbid ConstructType as part of 'no this in constructors'

This commit is contained in:
Nathan Shively-Sanders 2016-04-01 13:06:55 -07:00
parent 9e5fba6036
commit 2a9f39b132
4 changed files with 29 additions and 22 deletions

View file

@ -12416,7 +12416,7 @@ namespace ts {
if (indexOf(func.parameters, node) !== 0) {
error(node, Diagnostics.A_this_parameter_must_be_the_first_parameter);
}
if (func.kind === SyntaxKind.Constructor || func.kind === SyntaxKind.ConstructSignature) {
if (func.kind === SyntaxKind.Constructor || func.kind === SyntaxKind.ConstructSignature || func.kind === SyntaxKind.ConstructorType) {
error(node, Diagnostics.A_constructor_cannot_have_a_this_parameter);
}
if (func.kind === SyntaxKind.SetAccessor) {

View file

@ -77,29 +77,30 @@ tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(154,16): e
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(158,17): error TS2681: A constructor cannot have a 'this' parameter.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(160,11): error TS2682: A setter cannot have a 'this' parameter.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(164,9): error TS2681: A constructor cannot have a 'this' parameter.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(166,30): error TS2680: A 'this' parameter must be the first parameter.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(169,26): error TS1003: Identifier expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(169,30): error TS1005: ',' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(170,20): error TS2370: A rest parameter must be of an array type.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(170,23): error TS1003: Identifier expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(170,27): error TS1005: ',' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,23): error TS1005: ',' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,24): error TS1138: Parameter declaration expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,28): error TS1003: Identifier expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,32): error TS1005: ',' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(173,30): error TS1005: ',' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(173,32): error TS1138: Parameter declaration expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(173,39): error TS1005: ';' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(173,40): error TS1128: Declaration or statement expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(173,42): error TS2304: Cannot find name 'number'.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(173,49): error TS1005: ';' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(176,1): error TS7027: Unreachable code detected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(176,29): error TS2304: Cannot find name 'm'.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(176,32): error TS1005: ';' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(176,35): error TS2304: Cannot find name 'm'.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(166,31): error TS2681: A constructor cannot have a 'this' parameter.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(167,30): error TS2680: A 'this' parameter must be the first parameter.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(170,26): error TS1003: Identifier expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(170,30): error TS1005: ',' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,20): error TS2370: A rest parameter must be of an array type.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,23): error TS1003: Identifier expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(171,27): error TS1005: ',' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,23): error TS1005: ',' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(172,24): error TS1138: Parameter declaration expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(173,28): error TS1003: Identifier expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(173,32): error TS1005: ',' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(174,30): error TS1005: ',' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(174,32): error TS1138: Parameter declaration expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(174,39): error TS1005: ';' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(174,40): error TS1128: Declaration or statement expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(174,42): error TS2304: Cannot find name 'number'.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(174,49): error TS1005: ';' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(177,1): error TS7027: Unreachable code detected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(177,29): error TS2304: Cannot find name 'm'.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(177,32): error TS1005: ';' expected.
tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(177,35): error TS2304: Cannot find name 'm'.
==== tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts (65 errors) ====
==== tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts (66 errors) ====
class C {
n: number;
explicitThis(this: this, m: number): number {
@ -389,6 +390,9 @@ tests/cases/conformance/types/thisType/thisTypeInFunctionsNegative.ts(176,35): e
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2681: A constructor cannot have a 'this' parameter.
}
var thisConstructorType: new (this: number) => number;
~~~~~~~~~~~~
!!! error TS2681: A constructor cannot have a 'this' parameter.
function notFirst(a: number, this: C): number { return this.n; }
~~~~~~~
!!! error TS2680: A 'this' parameter must be the first parameter.

View file

@ -164,6 +164,7 @@ class ThisConstructor {
interface ThisConstructorInterface {
new(this: ThisConstructor, n: number);
}
var thisConstructorType: new (this: number) => number;
function notFirst(a: number, this: C): number { return this.n; }
///// parse errors /////
@ -339,6 +340,7 @@ var ThisConstructor = (function () {
});
return ThisConstructor;
}());
var thisConstructorType;
function notFirst(a, this) { return this.n; }
///// parse errors /////
function modifiers(, C) {

View file

@ -163,6 +163,7 @@ class ThisConstructor {
interface ThisConstructorInterface {
new(this: ThisConstructor, n: number);
}
var thisConstructorType: new (this: number) => number;
function notFirst(a: number, this: C): number { return this.n; }
///// parse errors /////