From 29f6036176f1b85875f2e6704935c678a66feeb6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 26 Sep 2015 14:31:03 -0700 Subject: [PATCH] Fixing comment and error message per CR feedback --- src/compiler/checker.ts | 7 +- src/compiler/diagnosticMessages.json | 2 +- .../thisInInvalidContexts.errors.txt | 4 +- ...InInvalidContextsExternalModule.errors.txt | 4 +- .../reference/thisTypeErrors.errors.txt | 116 +++++++++--------- 5 files changed, 67 insertions(+), 66 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ea704ed3382..b18c39c47db 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3041,8 +3041,9 @@ namespace ts { return true; } - // A type is considered independent if it is a built-in type keyword, an array with an element type that is - // considered independent, or a type reference that is considered independent. + // A type is considered independent if it the any, string, number, boolean, symbol, or void keyword, a string + // literal type, an array with an element type that is considered independent, or a type reference that is + // considered independent. function isIndependentType(node: TypeNode): boolean { switch (node.kind) { case SyntaxKind.AnyKeyword: @@ -4368,7 +4369,7 @@ namespace ts { return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)).thisType; } } - error(node, Diagnostics.this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface); + error(node, Diagnostics.A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface); return unknownType; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6c5cd3cf8b8..202f28e313e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1652,7 +1652,7 @@ "category": "Error", "code": 2525 }, - "'this' type is available only in a non-static member of a class or interface.": { + "A 'this' type is available only in a non-static member of a class or interface.": { "category": "Error", "code": 2526 }, diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index 29c090b5d90..76b90ed7c20 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(38,25): error TS2507: Type 'any' is not a constructor function type. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(44,9): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): error TS2332: 'this' cannot be referenced in current location. @@ -51,7 +51,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): function genericFunc(x: T) { } genericFunc(undefined); // Should be an error ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. class ErrClass3 extends this { ~~~~ diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index 20507c21213..2aa474d4cdc 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(38,25): error TS2507: Type 'any' is not a constructor function type. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(44,9): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(45,9): error TS2332: 'this' cannot be referenced in current location. @@ -52,7 +52,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod function genericFunc(x: T) { } genericFunc(undefined); // Should be an error ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. class ErrClass3 extends this { ~~~~ diff --git a/tests/baselines/reference/thisTypeErrors.errors.txt b/tests/baselines/reference/thisTypeErrors.errors.txt index b21c96968a3..17b7e0d39b9 100644 --- a/tests/baselines/reference/thisTypeErrors.errors.txt +++ b/tests/baselines/reference/thisTypeErrors.errors.txt @@ -1,109 +1,109 @@ -tests/cases/conformance/types/thisType/thisTypeErrors.ts(1,9): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(2,14): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(3,9): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(5,16): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(5,23): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(6,12): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(11,13): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(12,14): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(13,18): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(14,23): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(15,15): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(15,22): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(19,13): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(20,14): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(21,18): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(22,23): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(23,15): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(23,22): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(27,15): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(28,17): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(29,19): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(29,26): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(35,19): error TS2526: 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(1,9): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(2,14): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(3,9): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(5,16): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(5,23): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(6,12): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(11,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(12,14): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(13,18): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(14,23): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(15,15): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(15,22): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(19,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(20,14): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(21,18): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(22,23): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(23,15): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(23,22): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(27,15): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(28,17): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(29,19): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(29,26): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(35,19): error TS2526: A 'this' type is available only in a non-static member of a class or interface. tests/cases/conformance/types/thisType/thisTypeErrors.ts(36,20): error TS2331: 'this' cannot be referenced in a module or namespace body. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(41,14): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(41,21): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(46,23): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(46,30): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,18): error TS2526: 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,25): error TS2526: 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(41,14): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(41,21): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(46,23): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(46,30): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,18): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,25): error TS2526: A 'this' type is available only in a non-static member of a class or interface. ==== tests/cases/conformance/types/thisType/thisTypeErrors.ts (30 errors) ==== var x1: this; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. var x2: { a: this }; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. var x3: this[]; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. function f1(x: this): this { ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. var y: this; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. return this; } interface I1 { a: { x: this }; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. b: { (): this }; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. c: { new (): this }; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. d: { [x: string]: this }; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. e: { f(x: this): this }; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. } class C1 { a: { x: this }; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. b: { (): this }; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. c: { new (): this }; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. d: { [x: string]: this }; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. e: { f(x: this): this }; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. } class C2 { static x: this; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. static y = undefined; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. static foo(x: this): this { ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. return undefined; } } @@ -111,7 +111,7 @@ tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,25): error TS2526: ' namespace N1 { export var x: this; ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. export var y = this; ~~~~ !!! error TS2331: 'this' cannot be referenced in a module or namespace body. @@ -121,26 +121,26 @@ tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,25): error TS2526: ' x1 = { g(x: this): this { ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. return undefined; } } f() { function g(x: this): this { ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. return undefined; } let x2 = { h(x: this): this { ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. ~~~~ -!!! error TS2526: 'this' type is available only in a non-static member of a class or interface. +!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. return undefined; } }