From 22142d2ccbaa92cbe4b9f066a0bb1ebeca67e870 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 18 Feb 2016 16:25:16 -0800 Subject: [PATCH 01/11] removing some culturally senstive words --- src/compiler/checker.ts | 2 +- src/services/services.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d829795439b..3e555a1ff77 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12248,7 +12248,7 @@ namespace ts { seen = c === node; } }); - // We may be here because of some extra junk between overloads that could not be parsed into a valid node. + // We may be here because of some extra nodes between overloads that could not be parsed into a valid node. // In this case the subsequent node is not really consecutive (.pos !== node.end), and we must ignore it here. if (subsequentNode && subsequentNode.pos === node.end) { if (subsequentNode.kind === node.kind) { diff --git a/src/services/services.ts b/src/services/services.ts index 9302e1ae366..ef7de6dde97 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2829,7 +2829,7 @@ namespace ts { if (oldSourceFile) { // We already had a source file for this file name. Go to the registry to // ensure that we get the right up to date version of it. We need this to - // address the following 'race'. Specifically, say we have the following: + // address the following race-condition. Specifically, say we have the following: // // LS1 // \ From 785e55db8de2b852a50cf87bbe6c467524f9b1f1 Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Sat, 20 Feb 2016 10:25:16 +0800 Subject: [PATCH 02/11] Fixes outDir exclude --- src/compiler/tsc.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index e5b85a7391e..9f68809c389 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -710,16 +710,19 @@ namespace ts { else { const compilerOptions = extend(options, defaultInitCompilerOptions); const configurations: any = { - compilerOptions: serializeCompilerOptions(compilerOptions) + compilerOptions: serializeCompilerOptions(compilerOptions) }; if (fileNames && fileNames.length) { // only set the files property if we have at least one file configurations.files = fileNames; } - else { - configurations.exclude = ["node_modules"]; - } + else { + configurations.exclude = ["node_modules"]; + if (compilerOptions.outDir) { + configurations.exclude.push(compilerOptions.outDir); + } + } sys.writeFile(file, JSON.stringify(configurations, undefined, 4)); reportDiagnostic(createCompilerDiagnostic(Diagnostics.Successfully_created_a_tsconfig_json_file), /* compilerHost */ undefined); From 30294c7fc02ff78103307ae8c2608a84be205466 Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Sat, 20 Feb 2016 11:54:09 +0800 Subject: [PATCH 03/11] Fixes linting issues --- src/server/protocol.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index 3a669753323..b8207570ea2 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -469,7 +469,7 @@ declare namespace ts.server.protocol { placeOpenBraceOnNewLineForControlBlocks?: boolean; /** Index operator */ - [key: string] : string | number | boolean; + [key: string]: string | number | boolean; } /** From 517d7d983fe04a2843fd64a57e289b1c2b013727 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 19 Feb 2016 22:05:17 -0800 Subject: [PATCH 04/11] do not make inferences with the same source\target pair multiple times --- src/compiler/checker.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index dbce5f41ef4..b6e68cb1dc3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6524,6 +6524,7 @@ namespace ts { let targetStack: Type[]; let depth = 0; let inferiority = 0; + const visited: Map = {}; inferFromTypes(source, target); function isInProcess(source: Type, target: Type) { @@ -6653,6 +6654,12 @@ namespace ts { return; } + const key = source.id + "," + target.id; + if (hasProperty(visited, key)) { + return; + } + visited[key] = true; + if (depth === 0) { sourceStack = []; targetStack = []; From 26336cd54b5b9a17c1a719de717354e003216102 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 19 Feb 2016 22:32:05 -0800 Subject: [PATCH 05/11] fix linter issues --- src/server/protocol.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index 3a669753323..c50f211a21f 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -469,7 +469,7 @@ declare namespace ts.server.protocol { placeOpenBraceOnNewLineForControlBlocks?: boolean; /** Index operator */ - [key: string] : string | number | boolean; + [key: string]: string | number | boolean; } /** From b71ec381f941487ae1545eefa506e302d2a43f76 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sat, 20 Feb 2016 00:58:20 -0800 Subject: [PATCH 06/11] Added tests for ASI and element access with 'let'. --- .../es6/variableDeclarations/VariableDeclaration12_es6.ts | 4 ++++ .../es6/variableDeclarations/VariableDeclaration13_es6.ts | 6 ++++++ .../elementAccess/letIdentifierInElementAccess01.ts | 2 ++ 3 files changed, 12 insertions(+) create mode 100644 tests/cases/conformance/es6/variableDeclarations/VariableDeclaration12_es6.ts create mode 100644 tests/cases/conformance/es6/variableDeclarations/VariableDeclaration13_es6.ts create mode 100644 tests/cases/conformance/expressions/elementAccess/letIdentifierInElementAccess01.ts diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration12_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration12_es6.ts new file mode 100644 index 00000000000..f9839cf8502 --- /dev/null +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration12_es6.ts @@ -0,0 +1,4 @@ +// @target:es6 + +let +x \ No newline at end of file diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration13_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration13_es6.ts new file mode 100644 index 00000000000..0f20b02c01c --- /dev/null +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration13_es6.ts @@ -0,0 +1,6 @@ +// @target:es6 + +// An ExpressionStatement cannot start with the two token sequence `let [` because +// that would make it ambiguous with a `let` LexicalDeclaration whose first LexicalBinding was an ArrayBindingPattern. +var let: any; +let[0] = 100; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/elementAccess/letIdentifierInElementAccess01.ts b/tests/cases/conformance/expressions/elementAccess/letIdentifierInElementAccess01.ts new file mode 100644 index 00000000000..f0f71dc6ceb --- /dev/null +++ b/tests/cases/conformance/expressions/elementAccess/letIdentifierInElementAccess01.ts @@ -0,0 +1,2 @@ +var let: any = {}; +(let[0] = 100); \ No newline at end of file From c03aace7ca6ff16b36a641b6d9a8dd2e0c7720c3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sat, 20 Feb 2016 01:02:12 -0800 Subject: [PATCH 07/11] Accepted baselines. --- .../reference/VariableDeclaration12_es6.js | 7 +++++++ .../VariableDeclaration12_es6.symbols | 6 ++++++ .../reference/VariableDeclaration12_es6.types | 6 ++++++ .../VariableDeclaration13_es6.errors.txt | 20 +++++++++++++++++++ .../reference/VariableDeclaration13_es6.js | 13 ++++++++++++ .../letIdentifierInElementAccess01.js | 7 +++++++ .../letIdentifierInElementAccess01.symbols | 7 +++++++ .../letIdentifierInElementAccess01.types | 13 ++++++++++++ 8 files changed, 79 insertions(+) create mode 100644 tests/baselines/reference/VariableDeclaration12_es6.js create mode 100644 tests/baselines/reference/VariableDeclaration12_es6.symbols create mode 100644 tests/baselines/reference/VariableDeclaration12_es6.types create mode 100644 tests/baselines/reference/VariableDeclaration13_es6.errors.txt create mode 100644 tests/baselines/reference/VariableDeclaration13_es6.js create mode 100644 tests/baselines/reference/letIdentifierInElementAccess01.js create mode 100644 tests/baselines/reference/letIdentifierInElementAccess01.symbols create mode 100644 tests/baselines/reference/letIdentifierInElementAccess01.types diff --git a/tests/baselines/reference/VariableDeclaration12_es6.js b/tests/baselines/reference/VariableDeclaration12_es6.js new file mode 100644 index 00000000000..1e7d6d4b363 --- /dev/null +++ b/tests/baselines/reference/VariableDeclaration12_es6.js @@ -0,0 +1,7 @@ +//// [VariableDeclaration12_es6.ts] + +let +x + +//// [VariableDeclaration12_es6.js] +let x; diff --git a/tests/baselines/reference/VariableDeclaration12_es6.symbols b/tests/baselines/reference/VariableDeclaration12_es6.symbols new file mode 100644 index 00000000000..a2f324502dd --- /dev/null +++ b/tests/baselines/reference/VariableDeclaration12_es6.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration12_es6.ts === + +let +x +>x : Symbol(x, Decl(VariableDeclaration12_es6.ts, 1, 3)) + diff --git a/tests/baselines/reference/VariableDeclaration12_es6.types b/tests/baselines/reference/VariableDeclaration12_es6.types new file mode 100644 index 00000000000..14f23f88a7a --- /dev/null +++ b/tests/baselines/reference/VariableDeclaration12_es6.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration12_es6.ts === + +let +x +>x : any + diff --git a/tests/baselines/reference/VariableDeclaration13_es6.errors.txt b/tests/baselines/reference/VariableDeclaration13_es6.errors.txt new file mode 100644 index 00000000000..a022a4ad52b --- /dev/null +++ b/tests/baselines/reference/VariableDeclaration13_es6.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/variableDeclarations/VariableDeclaration13_es6.ts(5,5): error TS1181: Array element destructuring pattern expected. +tests/cases/conformance/es6/variableDeclarations/VariableDeclaration13_es6.ts(5,6): error TS1005: ',' expected. +tests/cases/conformance/es6/variableDeclarations/VariableDeclaration13_es6.ts(5,8): error TS1134: Variable declaration expected. +tests/cases/conformance/es6/variableDeclarations/VariableDeclaration13_es6.ts(5,10): error TS1134: Variable declaration expected. + + +==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration13_es6.ts (4 errors) ==== + + // An ExpressionStatement cannot start with the two token sequence `let [` because + // that would make it ambiguous with a `let` LexicalDeclaration whose first LexicalBinding was an ArrayBindingPattern. + var let: any; + let[0] = 100; + ~ +!!! error TS1181: Array element destructuring pattern expected. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1134: Variable declaration expected. + ~~~ +!!! error TS1134: Variable declaration expected. \ No newline at end of file diff --git a/tests/baselines/reference/VariableDeclaration13_es6.js b/tests/baselines/reference/VariableDeclaration13_es6.js new file mode 100644 index 00000000000..4ec04b18c3a --- /dev/null +++ b/tests/baselines/reference/VariableDeclaration13_es6.js @@ -0,0 +1,13 @@ +//// [VariableDeclaration13_es6.ts] + +// An ExpressionStatement cannot start with the two token sequence `let [` because +// that would make it ambiguous with a `let` LexicalDeclaration whose first LexicalBinding was an ArrayBindingPattern. +var let: any; +let[0] = 100; + +//// [VariableDeclaration13_es6.js] +// An ExpressionStatement cannot start with the two token sequence `let [` because +// that would make it ambiguous with a `let` LexicalDeclaration whose first LexicalBinding was an ArrayBindingPattern. +var let; +let [] = 0; +100; diff --git a/tests/baselines/reference/letIdentifierInElementAccess01.js b/tests/baselines/reference/letIdentifierInElementAccess01.js new file mode 100644 index 00000000000..5e5e857479c --- /dev/null +++ b/tests/baselines/reference/letIdentifierInElementAccess01.js @@ -0,0 +1,7 @@ +//// [letIdentifierInElementAccess01.ts] +var let: any = {}; +(let[0] = 100); + +//// [letIdentifierInElementAccess01.js] +var let = {}; +(let[0] = 100); diff --git a/tests/baselines/reference/letIdentifierInElementAccess01.symbols b/tests/baselines/reference/letIdentifierInElementAccess01.symbols new file mode 100644 index 00000000000..a655b5703b0 --- /dev/null +++ b/tests/baselines/reference/letIdentifierInElementAccess01.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/expressions/elementAccess/letIdentifierInElementAccess01.ts === +var let: any = {}; +>let : Symbol(let, Decl(letIdentifierInElementAccess01.ts, 0, 3)) + +(let[0] = 100); +>let : Symbol(let, Decl(letIdentifierInElementAccess01.ts, 0, 3)) + diff --git a/tests/baselines/reference/letIdentifierInElementAccess01.types b/tests/baselines/reference/letIdentifierInElementAccess01.types new file mode 100644 index 00000000000..187fd7e221c --- /dev/null +++ b/tests/baselines/reference/letIdentifierInElementAccess01.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/expressions/elementAccess/letIdentifierInElementAccess01.ts === +var let: any = {}; +>let : any +>{} : {} + +(let[0] = 100); +>(let[0] = 100) : number +>let[0] = 100 : number +>let[0] : any +>let : any +>0 : number +>100 : number + From 48f728e96fa30c3fe217ee52ad5a3855ff7b3bd8 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 22 Feb 2016 10:28:34 -0800 Subject: [PATCH 08/11] Add abstract properties and accessors Almost all the infrastructure is in place, so I just allowed abstract properties+accessors and added an error when abstract accessors do not have the same abstractness specified. --- src/compiler/checker.ts | 12 +++++++++--- src/compiler/diagnosticMessages.json | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6f643457e2f..72866810a57 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12051,6 +12051,9 @@ namespace ts { if (((node.flags & NodeFlags.AccessibilityModifier) !== (otherAccessor.flags & NodeFlags.AccessibilityModifier))) { error(node.name, Diagnostics.Getter_and_setter_accessors_do_not_agree_in_visibility); } + if (((node.flags & NodeFlags.Abstract) !== (otherAccessor.flags & NodeFlags.Abstract))) { + error(node.name, Diagnostics.Accessors_must_both_be_abstract_or_not_abstract); + } const currentAccessorType = getAnnotatedAccessorType(node); const otherAccessorType = getAnnotatedAccessorType(otherAccessor); @@ -16498,8 +16501,11 @@ namespace ts { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "abstract"); } if (node.kind !== SyntaxKind.ClassDeclaration) { - if (node.kind !== SyntaxKind.MethodDeclaration) { - return grammarErrorOnNode(modifier, Diagnostics.abstract_modifier_can_only_appear_on_a_class_or_method_declaration); + if (node.kind !== SyntaxKind.MethodDeclaration && + node.kind !== SyntaxKind.PropertyDeclaration && + node.kind !== SyntaxKind.GetAccessor && + node.kind !== SyntaxKind.SetAccessor) { + return grammarErrorOnNode(modifier, Diagnostics.abstract_modifier_can_only_appear_on_a_class_method_or_property_declaration); } if (!(node.parent.kind === SyntaxKind.ClassDeclaration && node.parent.flags & NodeFlags.Abstract)) { return grammarErrorOnNode(modifier, Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class); @@ -16993,7 +16999,7 @@ namespace ts { else if (isInAmbientContext(accessor)) { return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context); } - else if (accessor.body === undefined) { + else if (accessor.body === undefined && !(accessor.flags & NodeFlags.Abstract)) { return grammarErrorAtPos(getSourceFileOfNode(accessor), accessor.end - 1, ";".length, Diagnostics._0_expected, "{"); } else if (accessor.typeParameters) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 70c6d8ff167..d5984988876 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -779,7 +779,7 @@ "category": "Error", "code": 1241 }, - "'abstract' modifier can only appear on a class or method declaration.": { + "'abstract' modifier can only appear on a class, method, or property declaration.": { "category": "Error", "code": 1242 }, @@ -1843,6 +1843,10 @@ "category": "Error", "code": 2675 }, + "Accessors must both be abstract or not abstract.": { + "category": "Error", + "code": 2676 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 From 02fc8b1b2dfec3c1792140a0ecf3b6bea864bad4 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 22 Feb 2016 10:31:31 -0800 Subject: [PATCH 09/11] Add abstract property tests and rebaseline. 1. Positive tests. 2. Negative tests. 3. Update error messages. 4. Remove errors from conformance test. --- tests/baselines/reference/abstractProperty.js | 56 +++++++ .../reference/abstractProperty.symbols | 59 +++++++ .../reference/abstractProperty.types | 62 ++++++++ .../abstractPropertyNegative.errors.txt | 106 +++++++++++++ .../reference/abstractPropertyNegative.js | 144 ++++++++++++++++++ .../classAbstractConstructor.errors.txt | 4 +- .../classAbstractDeclarations.d.errors.txt | 4 +- .../classAbstractProperties.errors.txt | 18 +-- .../classAbstractWithInterface.errors.txt | 4 +- tests/cases/compiler/abstractProperty.ts | 22 +++ .../compiler/abstractPropertyNegative.ts | 43 ++++++ 11 files changed, 501 insertions(+), 21 deletions(-) create mode 100644 tests/baselines/reference/abstractProperty.js create mode 100644 tests/baselines/reference/abstractProperty.symbols create mode 100644 tests/baselines/reference/abstractProperty.types create mode 100644 tests/baselines/reference/abstractPropertyNegative.errors.txt create mode 100644 tests/baselines/reference/abstractPropertyNegative.js create mode 100644 tests/cases/compiler/abstractProperty.ts create mode 100644 tests/cases/compiler/abstractPropertyNegative.ts diff --git a/tests/baselines/reference/abstractProperty.js b/tests/baselines/reference/abstractProperty.js new file mode 100644 index 00000000000..9564be862dc --- /dev/null +++ b/tests/baselines/reference/abstractProperty.js @@ -0,0 +1,56 @@ +//// [abstractProperty.ts] +interface A { + prop: string; + raw: string; + m(): void; +} +abstract class B implements A { + abstract prop: string; + abstract raw: string; + abstract readonly ro: string; + abstract get readonlyProp(): string; + abstract set readonlyProp(val: string); + abstract m(): void; +} +class C extends B { + get prop() { return "foo"; } + set prop(v) { } + raw = "edge"; + readonly ro = "readonly please"; + readonlyProp: string; // don't have to give a value, in fact + m() { } +} + +//// [abstractProperty.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var B = (function () { + function B() { + } + Object.defineProperty(B.prototype, "readonlyProp", { + get: function () { }, + set: function (val) { }, + enumerable: true, + configurable: true + }); + return B; +}()); +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + this.raw = "edge"; + this.ro = "readonly please"; + } + Object.defineProperty(C.prototype, "prop", { + get: function () { return "foo"; }, + set: function (v) { }, + enumerable: true, + configurable: true + }); + C.prototype.m = function () { }; + return C; +}(B)); diff --git a/tests/baselines/reference/abstractProperty.symbols b/tests/baselines/reference/abstractProperty.symbols new file mode 100644 index 00000000000..f64df9a5cde --- /dev/null +++ b/tests/baselines/reference/abstractProperty.symbols @@ -0,0 +1,59 @@ +=== tests/cases/compiler/abstractProperty.ts === +interface A { +>A : Symbol(A, Decl(abstractProperty.ts, 0, 0)) + + prop: string; +>prop : Symbol(prop, Decl(abstractProperty.ts, 0, 13)) + + raw: string; +>raw : Symbol(raw, Decl(abstractProperty.ts, 1, 17)) + + m(): void; +>m : Symbol(m, Decl(abstractProperty.ts, 2, 16)) +} +abstract class B implements A { +>B : Symbol(B, Decl(abstractProperty.ts, 4, 1)) +>A : Symbol(A, Decl(abstractProperty.ts, 0, 0)) + + abstract prop: string; +>prop : Symbol(prop, Decl(abstractProperty.ts, 5, 31)) + + abstract raw: string; +>raw : Symbol(raw, Decl(abstractProperty.ts, 6, 26)) + + abstract readonly ro: string; +>ro : Symbol(ro, Decl(abstractProperty.ts, 7, 25)) + + abstract get readonlyProp(): string; +>readonlyProp : Symbol(readonlyProp, Decl(abstractProperty.ts, 8, 33), Decl(abstractProperty.ts, 9, 40)) + + abstract set readonlyProp(val: string); +>readonlyProp : Symbol(readonlyProp, Decl(abstractProperty.ts, 8, 33), Decl(abstractProperty.ts, 9, 40)) +>val : Symbol(val, Decl(abstractProperty.ts, 10, 30)) + + abstract m(): void; +>m : Symbol(m, Decl(abstractProperty.ts, 10, 43)) +} +class C extends B { +>C : Symbol(C, Decl(abstractProperty.ts, 12, 1)) +>B : Symbol(B, Decl(abstractProperty.ts, 4, 1)) + + get prop() { return "foo"; } +>prop : Symbol(prop, Decl(abstractProperty.ts, 13, 19), Decl(abstractProperty.ts, 14, 32)) + + set prop(v) { } +>prop : Symbol(prop, Decl(abstractProperty.ts, 13, 19), Decl(abstractProperty.ts, 14, 32)) +>v : Symbol(v, Decl(abstractProperty.ts, 15, 13)) + + raw = "edge"; +>raw : Symbol(raw, Decl(abstractProperty.ts, 15, 19)) + + readonly ro = "readonly please"; +>ro : Symbol(ro, Decl(abstractProperty.ts, 16, 17)) + + readonlyProp: string; // don't have to give a value, in fact +>readonlyProp : Symbol(readonlyProp, Decl(abstractProperty.ts, 17, 36)) + + m() { } +>m : Symbol(m, Decl(abstractProperty.ts, 18, 25)) +} diff --git a/tests/baselines/reference/abstractProperty.types b/tests/baselines/reference/abstractProperty.types new file mode 100644 index 00000000000..b6aff9356cd --- /dev/null +++ b/tests/baselines/reference/abstractProperty.types @@ -0,0 +1,62 @@ +=== tests/cases/compiler/abstractProperty.ts === +interface A { +>A : A + + prop: string; +>prop : string + + raw: string; +>raw : string + + m(): void; +>m : () => void +} +abstract class B implements A { +>B : B +>A : A + + abstract prop: string; +>prop : string + + abstract raw: string; +>raw : string + + abstract readonly ro: string; +>ro : string + + abstract get readonlyProp(): string; +>readonlyProp : string + + abstract set readonlyProp(val: string); +>readonlyProp : string +>val : string + + abstract m(): void; +>m : () => void +} +class C extends B { +>C : C +>B : B + + get prop() { return "foo"; } +>prop : string +>"foo" : string + + set prop(v) { } +>prop : string +>v : string + + raw = "edge"; +>raw : string +>"edge" : string + + readonly ro = "readonly please"; +>ro : string +>"readonly please" : string + + readonlyProp: string; // don't have to give a value, in fact +>readonlyProp : string + + m() { } +>m : () => void +} diff --git a/tests/baselines/reference/abstractPropertyNegative.errors.txt b/tests/baselines/reference/abstractPropertyNegative.errors.txt new file mode 100644 index 00000000000..8cef7bcb619 --- /dev/null +++ b/tests/baselines/reference/abstractPropertyNegative.errors.txt @@ -0,0 +1,106 @@ +tests/cases/compiler/abstractPropertyNegative.ts(10,18): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/compiler/abstractPropertyNegative.ts(11,18): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'm' from class 'B'. +tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'mismatch' from class 'B'. +tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'prop' from class 'B'. +tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'readonlyProp' from class 'B'. +tests/cases/compiler/abstractPropertyNegative.ts(15,5): error TS1244: Abstract methods can only appear within an abstract class. +tests/cases/compiler/abstractPropertyNegative.ts(16,37): error TS1005: '{' expected. +tests/cases/compiler/abstractPropertyNegative.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/abstractPropertyNegative.ts(24,7): error TS2415: Class 'WrongTypePropertyImpl' incorrectly extends base class 'WrongTypeProperty'. + Types of property 'num' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/abstractPropertyNegative.ts(30,7): error TS2415: Class 'WrongTypeAccessorImpl' incorrectly extends base class 'WrongTypeAccessor'. + Types of property 'num' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/abstractPropertyNegative.ts(33,7): error TS2415: Class 'WrongTypeAccessorImpl2' incorrectly extends base class 'WrongTypeAccessor'. + Types of property 'num' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/abstractPropertyNegative.ts(38,18): error TS2676: Accessors must both be abstract or not abstract. +tests/cases/compiler/abstractPropertyNegative.ts(39,9): error TS2676: Accessors must both be abstract or not abstract. +tests/cases/compiler/abstractPropertyNegative.ts(40,9): error TS2676: Accessors must both be abstract or not abstract. +tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors must both be abstract or not abstract. + + +==== tests/cases/compiler/abstractPropertyNegative.ts (16 errors) ==== + interface A { + prop: string; + m(): string; + } + abstract class B implements A { + abstract prop: string; + public abstract readonly ro: string; + abstract get readonlyProp(): string; + abstract m(): string; + abstract get mismatch(): string; + ~~~~~~~~ +!!! error TS2380: 'get' and 'set' accessor must have the same type. + abstract set mismatch(val: number); // error, not same type + ~~~~~~~~ +!!! error TS2380: 'get' and 'set' accessor must have the same type. + } + class C extends B { + ~ +!!! error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'm' from class 'B'. + ~ +!!! error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'mismatch' from class 'B'. + ~ +!!! error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'prop' from class 'B'. + ~ +!!! error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'readonlyProp' from class 'B'. + readonly ro = "readonly please"; + abstract notAllowed: string; + ~~~~~~~~ +!!! error TS1244: Abstract methods can only appear within an abstract class. + get concreteWithNoBody(): string; + ~ +!!! error TS1005: '{' expected. + } + let c = new C(); + c.ro = "error: lhs of assignment can't be readonly"; + ~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + abstract class WrongTypeProperty { + abstract num: number; + } + class WrongTypePropertyImpl extends WrongTypeProperty { + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2415: Class 'WrongTypePropertyImpl' incorrectly extends base class 'WrongTypeProperty'. +!!! error TS2415: Types of property 'num' are incompatible. +!!! error TS2415: Type 'string' is not assignable to type 'number'. + num = "nope, wrong"; + } + abstract class WrongTypeAccessor { + abstract get num(): number; + } + class WrongTypeAccessorImpl extends WrongTypeAccessor { + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2415: Class 'WrongTypeAccessorImpl' incorrectly extends base class 'WrongTypeAccessor'. +!!! error TS2415: Types of property 'num' are incompatible. +!!! error TS2415: Type 'string' is not assignable to type 'number'. + get num() { return "nope, wrong"; } + } + class WrongTypeAccessorImpl2 extends WrongTypeAccessor { + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2415: Class 'WrongTypeAccessorImpl2' incorrectly extends base class 'WrongTypeAccessor'. +!!! error TS2415: Types of property 'num' are incompatible. +!!! error TS2415: Type 'string' is not assignable to type 'number'. + num = "nope, wrong"; + } + + abstract class AbstractAccessorMismatch { + abstract get p1(): string; + ~~ +!!! error TS2676: Accessors must both be abstract or not abstract. + set p1(val: string) { }; + ~~ +!!! error TS2676: Accessors must both be abstract or not abstract. + get p2(): string { return "should work"; } + ~~ +!!! error TS2676: Accessors must both be abstract or not abstract. + abstract set p2(val: string); + ~~ +!!! error TS2676: Accessors must both be abstract or not abstract. + } + \ No newline at end of file diff --git a/tests/baselines/reference/abstractPropertyNegative.js b/tests/baselines/reference/abstractPropertyNegative.js new file mode 100644 index 00000000000..55c9aea9411 --- /dev/null +++ b/tests/baselines/reference/abstractPropertyNegative.js @@ -0,0 +1,144 @@ +//// [abstractPropertyNegative.ts] +interface A { + prop: string; + m(): string; +} +abstract class B implements A { + abstract prop: string; + public abstract readonly ro: string; + abstract get readonlyProp(): string; + abstract m(): string; + abstract get mismatch(): string; + abstract set mismatch(val: number); // error, not same type +} +class C extends B { + readonly ro = "readonly please"; + abstract notAllowed: string; + get concreteWithNoBody(): string; +} +let c = new C(); +c.ro = "error: lhs of assignment can't be readonly"; + +abstract class WrongTypeProperty { + abstract num: number; +} +class WrongTypePropertyImpl extends WrongTypeProperty { + num = "nope, wrong"; +} +abstract class WrongTypeAccessor { + abstract get num(): number; +} +class WrongTypeAccessorImpl extends WrongTypeAccessor { + get num() { return "nope, wrong"; } +} +class WrongTypeAccessorImpl2 extends WrongTypeAccessor { + num = "nope, wrong"; +} + +abstract class AbstractAccessorMismatch { + abstract get p1(): string; + set p1(val: string) { }; + get p2(): string { return "should work"; } + abstract set p2(val: string); +} + + +//// [abstractPropertyNegative.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var B = (function () { + function B() { + } + Object.defineProperty(B.prototype, "readonlyProp", { + get: function () { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(B.prototype, "mismatch", { + get: function () { }, + set: function (val) { } // error, not same type + , + enumerable: true, + configurable: true + }); + return B; +}()); +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + this.ro = "readonly please"; + } + Object.defineProperty(C.prototype, "concreteWithNoBody", { + get: function () { }, + enumerable: true, + configurable: true + }); + return C; +}(B)); +var c = new C(); +c.ro = "error: lhs of assignment can't be readonly"; +var WrongTypeProperty = (function () { + function WrongTypeProperty() { + } + return WrongTypeProperty; +}()); +var WrongTypePropertyImpl = (function (_super) { + __extends(WrongTypePropertyImpl, _super); + function WrongTypePropertyImpl() { + _super.apply(this, arguments); + this.num = "nope, wrong"; + } + return WrongTypePropertyImpl; +}(WrongTypeProperty)); +var WrongTypeAccessor = (function () { + function WrongTypeAccessor() { + } + Object.defineProperty(WrongTypeAccessor.prototype, "num", { + get: function () { }, + enumerable: true, + configurable: true + }); + return WrongTypeAccessor; +}()); +var WrongTypeAccessorImpl = (function (_super) { + __extends(WrongTypeAccessorImpl, _super); + function WrongTypeAccessorImpl() { + _super.apply(this, arguments); + } + Object.defineProperty(WrongTypeAccessorImpl.prototype, "num", { + get: function () { return "nope, wrong"; }, + enumerable: true, + configurable: true + }); + return WrongTypeAccessorImpl; +}(WrongTypeAccessor)); +var WrongTypeAccessorImpl2 = (function (_super) { + __extends(WrongTypeAccessorImpl2, _super); + function WrongTypeAccessorImpl2() { + _super.apply(this, arguments); + this.num = "nope, wrong"; + } + return WrongTypeAccessorImpl2; +}(WrongTypeAccessor)); +var AbstractAccessorMismatch = (function () { + function AbstractAccessorMismatch() { + } + Object.defineProperty(AbstractAccessorMismatch.prototype, "p1", { + get: function () { }, + set: function (val) { }, + enumerable: true, + configurable: true + }); + ; + Object.defineProperty(AbstractAccessorMismatch.prototype, "p2", { + get: function () { return "should work"; }, + set: function (val) { }, + enumerable: true, + configurable: true + }); + return AbstractAccessorMismatch; +}()); diff --git a/tests/baselines/reference/classAbstractConstructor.errors.txt b/tests/baselines/reference/classAbstractConstructor.errors.txt index fee9f4cefee..c57d52a018f 100644 --- a/tests/baselines/reference/classAbstractConstructor.errors.txt +++ b/tests/baselines/reference/classAbstractConstructor.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractConstructor.ts(2,5): error TS1242: 'abstract' modifier can only appear on a class or method declaration. +tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractConstructor.ts(2,5): error TS1242: 'abstract' modifier can only appear on a class, method, or property declaration. ==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractConstructor.ts (1 errors) ==== abstract class A { abstract constructor() {} ~~~~~~~~ -!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration. +!!! error TS1242: 'abstract' modifier can only appear on a class, method, or property declaration. } \ No newline at end of file diff --git a/tests/baselines/reference/classAbstractDeclarations.d.errors.txt b/tests/baselines/reference/classAbstractDeclarations.d.errors.txt index a1c0e55152c..d71f53118af 100644 --- a/tests/baselines/reference/classAbstractDeclarations.d.errors.txt +++ b/tests/baselines/reference/classAbstractDeclarations.d.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractDeclarations.d.ts(2,5): error TS1242: 'abstract' modifier can only appear on a class or method declaration. +tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractDeclarations.d.ts(2,5): error TS1242: 'abstract' modifier can only appear on a class, method, or property declaration. tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractDeclarations.d.ts(2,28): error TS1183: An implementation cannot be declared in ambient contexts. tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractDeclarations.d.ts(11,15): error TS2515: Non-abstract class 'CC' does not implement inherited abstract member 'foo' from class 'AA'. tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractDeclarations.d.ts(13,15): error TS2515: Non-abstract class 'DD' does not implement inherited abstract member 'foo' from class 'BB'. @@ -9,7 +9,7 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst declare abstract class A { abstract constructor() {} ~~~~~~~~ -!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration. +!!! error TS1242: 'abstract' modifier can only appear on a class, method, or property declaration. ~ !!! error TS1183: An implementation cannot be declared in ambient contexts. } diff --git a/tests/baselines/reference/classAbstractProperties.errors.txt b/tests/baselines/reference/classAbstractProperties.errors.txt index 223a3049825..88c0b587484 100644 --- a/tests/baselines/reference/classAbstractProperties.errors.txt +++ b/tests/baselines/reference/classAbstractProperties.errors.txt @@ -1,29 +1,17 @@ -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(2,5): error TS1242: 'abstract' modifier can only appear on a class or method declaration. -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(3,12): error TS1242: 'abstract' modifier can only appear on a class or method declaration. -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(4,15): error TS1242: 'abstract' modifier can only appear on a class or method declaration. -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(5,13): error TS1242: 'abstract' modifier can only appear on a class or method declaration. -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(7,5): error TS1242: 'abstract' modifier can only appear on a class or method declaration. +tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(5,13): error TS1243: 'private' modifier cannot be used with 'abstract' modifier. tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(12,13): error TS1243: 'private' modifier cannot be used with 'abstract' modifier. -==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts (6 errors) ==== +==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts (2 errors) ==== abstract class A { abstract x : number; - ~~~~~~~~ -!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration. public abstract y : number; - ~~~~~~~~ -!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration. protected abstract z : number; - ~~~~~~~~ -!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration. private abstract w : number; ~~~~~~~~ -!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration. +!!! error TS1243: 'private' modifier cannot be used with 'abstract' modifier. abstract m: () => void; - ~~~~~~~~ -!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration. abstract foo_x() : number; public abstract foo_y() : number; diff --git a/tests/baselines/reference/classAbstractWithInterface.errors.txt b/tests/baselines/reference/classAbstractWithInterface.errors.txt index fa0a3d08957..0fe3b3ba342 100644 --- a/tests/baselines/reference/classAbstractWithInterface.errors.txt +++ b/tests/baselines/reference/classAbstractWithInterface.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractWithInterface.ts(1,1): error TS1242: 'abstract' modifier can only appear on a class or method declaration. +tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractWithInterface.ts(1,1): error TS1242: 'abstract' modifier can only appear on a class, method, or property declaration. ==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractWithInterface.ts (1 errors) ==== abstract interface I {} ~~~~~~~~ -!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration. \ No newline at end of file +!!! error TS1242: 'abstract' modifier can only appear on a class, method, or property declaration. \ No newline at end of file diff --git a/tests/cases/compiler/abstractProperty.ts b/tests/cases/compiler/abstractProperty.ts new file mode 100644 index 00000000000..c0b76057a6b --- /dev/null +++ b/tests/cases/compiler/abstractProperty.ts @@ -0,0 +1,22 @@ +//@target: ES5 +interface A { + prop: string; + raw: string; + m(): void; +} +abstract class B implements A { + abstract prop: string; + abstract raw: string; + abstract readonly ro: string; + abstract get readonlyProp(): string; + abstract set readonlyProp(val: string); + abstract m(): void; +} +class C extends B { + get prop() { return "foo"; } + set prop(v) { } + raw = "edge"; + readonly ro = "readonly please"; + readonlyProp: string; // don't have to give a value, in fact + m() { } +} \ No newline at end of file diff --git a/tests/cases/compiler/abstractPropertyNegative.ts b/tests/cases/compiler/abstractPropertyNegative.ts new file mode 100644 index 00000000000..16c09b10573 --- /dev/null +++ b/tests/cases/compiler/abstractPropertyNegative.ts @@ -0,0 +1,43 @@ +//@target: ES5 +interface A { + prop: string; + m(): string; +} +abstract class B implements A { + abstract prop: string; + public abstract readonly ro: string; + abstract get readonlyProp(): string; + abstract m(): string; + abstract get mismatch(): string; + abstract set mismatch(val: number); // error, not same type +} +class C extends B { + readonly ro = "readonly please"; + abstract notAllowed: string; + get concreteWithNoBody(): string; +} +let c = new C(); +c.ro = "error: lhs of assignment can't be readonly"; + +abstract class WrongTypeProperty { + abstract num: number; +} +class WrongTypePropertyImpl extends WrongTypeProperty { + num = "nope, wrong"; +} +abstract class WrongTypeAccessor { + abstract get num(): number; +} +class WrongTypeAccessorImpl extends WrongTypeAccessor { + get num() { return "nope, wrong"; } +} +class WrongTypeAccessorImpl2 extends WrongTypeAccessor { + num = "nope, wrong"; +} + +abstract class AbstractAccessorMismatch { + abstract get p1(): string; + set p1(val: string) { }; + get p2(): string { return "should work"; } + abstract set p2(val: string); +} From b01a05039988255f0b7cdba22c271729f4cbca63 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 22 Feb 2016 13:55:46 -0800 Subject: [PATCH 10/11] Update error message as requested in PR comments --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- .../abstractPropertyNegative.errors.txt | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 72866810a57..9e5f5caec4d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12052,7 +12052,7 @@ namespace ts { error(node.name, Diagnostics.Getter_and_setter_accessors_do_not_agree_in_visibility); } if (((node.flags & NodeFlags.Abstract) !== (otherAccessor.flags & NodeFlags.Abstract))) { - error(node.name, Diagnostics.Accessors_must_both_be_abstract_or_not_abstract); + error(node.name, Diagnostics.Accessors_must_both_be_abstract_or_non_abstract); } const currentAccessorType = getAnnotatedAccessorType(node); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d5984988876..64e2974e1a1 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1843,7 +1843,7 @@ "category": "Error", "code": 2675 }, - "Accessors must both be abstract or not abstract.": { + "Accessors must both be abstract or non-abstract.": { "category": "Error", "code": 2676 }, diff --git a/tests/baselines/reference/abstractPropertyNegative.errors.txt b/tests/baselines/reference/abstractPropertyNegative.errors.txt index 8cef7bcb619..448fb2255e0 100644 --- a/tests/baselines/reference/abstractPropertyNegative.errors.txt +++ b/tests/baselines/reference/abstractPropertyNegative.errors.txt @@ -16,10 +16,10 @@ tests/cases/compiler/abstractPropertyNegative.ts(30,7): error TS2415: Class 'Wro tests/cases/compiler/abstractPropertyNegative.ts(33,7): error TS2415: Class 'WrongTypeAccessorImpl2' incorrectly extends base class 'WrongTypeAccessor'. Types of property 'num' are incompatible. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/abstractPropertyNegative.ts(38,18): error TS2676: Accessors must both be abstract or not abstract. -tests/cases/compiler/abstractPropertyNegative.ts(39,9): error TS2676: Accessors must both be abstract or not abstract. -tests/cases/compiler/abstractPropertyNegative.ts(40,9): error TS2676: Accessors must both be abstract or not abstract. -tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors must both be abstract or not abstract. +tests/cases/compiler/abstractPropertyNegative.ts(38,18): error TS2676: Accessors must both be abstract or non-abstract. +tests/cases/compiler/abstractPropertyNegative.ts(39,9): error TS2676: Accessors must both be abstract or non-abstract. +tests/cases/compiler/abstractPropertyNegative.ts(40,9): error TS2676: Accessors must both be abstract or non-abstract. +tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors must both be abstract or non-abstract. ==== tests/cases/compiler/abstractPropertyNegative.ts (16 errors) ==== @@ -92,15 +92,15 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors abstract class AbstractAccessorMismatch { abstract get p1(): string; ~~ -!!! error TS2676: Accessors must both be abstract or not abstract. +!!! error TS2676: Accessors must both be abstract or non-abstract. set p1(val: string) { }; ~~ -!!! error TS2676: Accessors must both be abstract or not abstract. +!!! error TS2676: Accessors must both be abstract or non-abstract. get p2(): string { return "should work"; } ~~ -!!! error TS2676: Accessors must both be abstract or not abstract. +!!! error TS2676: Accessors must both be abstract or non-abstract. abstract set p2(val: string); ~~ -!!! error TS2676: Accessors must both be abstract or not abstract. +!!! error TS2676: Accessors must both be abstract or non-abstract. } \ No newline at end of file From ee8986acc855b959aee1d8607f805dee79d69765 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 22 Feb 2016 14:16:00 -0800 Subject: [PATCH 11/11] Error messages consistently use non- prefix In the construction "x must either be y or non-y", we previously used "y or not y", even y is always an adjective. --- src/compiler/checker.ts | 4 ++-- src/compiler/diagnosticMessages.json | 4 ++-- .../classAbstractInstantiations2.errors.txt | 4 ++-- .../reference/classAbstractOverloads.errors.txt | 12 ++++++------ .../reference/functionOverloadErrors.errors.txt | 8 ++++---- .../reference/overloadModifiersMustAgree.errors.txt | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6f643457e2f..153405e930a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12196,7 +12196,7 @@ namespace ts { forEach(overloads, o => { const deviation = getEffectiveDeclarationFlags(o, flagsToCheck) ^ canonicalFlags; if (deviation & NodeFlags.Export) { - error(o.name, Diagnostics.Overload_signatures_must_all_be_exported_or_not_exported); + error(o.name, Diagnostics.Overload_signatures_must_all_be_exported_or_non_exported); } else if (deviation & NodeFlags.Ambient) { error(o.name, Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient); @@ -12205,7 +12205,7 @@ namespace ts { error(o.name || o, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected); } else if (deviation & NodeFlags.Abstract) { - error(o.name, Diagnostics.Overload_signatures_must_all_be_abstract_or_not_abstract); + error(o.name, Diagnostics.Overload_signatures_must_all_be_abstract_or_non_abstract); } }); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 70c6d8ff167..c5a2f56f3b8 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1151,7 +1151,7 @@ "category": "Error", "code": 2382 }, - "Overload signatures must all be exported or not exported.": { + "Overload signatures must all be exported or non-exported.": { "category": "Error", "code": 2383 }, @@ -1635,7 +1635,7 @@ "category": "Error", "code": 2511 }, - "Overload signatures must all be abstract or not abstract.": { + "Overload signatures must all be abstract or non-abstract.": { "category": "Error", "code": 2512 }, diff --git a/tests/baselines/reference/classAbstractInstantiations2.errors.txt b/tests/baselines/reference/classAbstractInstantiations2.errors.txt index 077f87c5050..bf4cd851fb3 100644 --- a/tests/baselines/reference/classAbstractInstantiations2.errors.txt +++ b/tests/baselines/reference/classAbstractInstantiations2.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(21,1): error TS2511: Cannot create an instance of the abstract class 'B'. tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(26,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'bar' from class 'B'. tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(46,5): error TS2391: Function implementation is missing or not immediately following the declaration. -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(46,5): error TS2512: Overload signatures must all be abstract or not abstract. +tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(46,5): error TS2512: Overload signatures must all be abstract or non-abstract. tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(50,5): error TS1244: Abstract methods can only appear within an abstract class. @@ -70,7 +70,7 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst ~~~ !!! error TS2391: Function implementation is missing or not immediately following the declaration. ~~~ -!!! error TS2512: Overload signatures must all be abstract or not abstract. +!!! error TS2512: Overload signatures must all be abstract or non-abstract. } class H { // error -- not declared abstract diff --git a/tests/baselines/reference/classAbstractOverloads.errors.txt b/tests/baselines/reference/classAbstractOverloads.errors.txt index 0a1c96bd30a..155a8451a5d 100644 --- a/tests/baselines/reference/classAbstractOverloads.errors.txt +++ b/tests/baselines/reference/classAbstractOverloads.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(7,5): error TS2512: Overload signatures must all be abstract or not abstract. -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(10,14): error TS2512: Overload signatures must all be abstract or not abstract. -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(12,14): error TS2512: Overload signatures must all be abstract or not abstract. +tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(7,5): error TS2512: Overload signatures must all be abstract or non-abstract. +tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(10,14): error TS2512: Overload signatures must all be abstract or non-abstract. +tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(12,14): error TS2512: Overload signatures must all be abstract or non-abstract. tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(15,5): error TS2391: Function implementation is missing or not immediately following the declaration. tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(20,14): error TS2516: All declarations of an abstract method must be consecutive. @@ -14,16 +14,16 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst abstract bar(); bar(); ~~~ -!!! error TS2512: Overload signatures must all be abstract or not abstract. +!!! error TS2512: Overload signatures must all be abstract or non-abstract. abstract bar(); abstract baz(); ~~~ -!!! error TS2512: Overload signatures must all be abstract or not abstract. +!!! error TS2512: Overload signatures must all be abstract or non-abstract. baz(); abstract baz(); ~~~ -!!! error TS2512: Overload signatures must all be abstract or not abstract. +!!! error TS2512: Overload signatures must all be abstract or non-abstract. baz() {} qux(); diff --git a/tests/baselines/reference/functionOverloadErrors.errors.txt b/tests/baselines/reference/functionOverloadErrors.errors.txt index ae1dfeae4d1..1ec0344ac62 100644 --- a/tests/baselines/reference/functionOverloadErrors.errors.txt +++ b/tests/baselines/reference/functionOverloadErrors.errors.txt @@ -4,8 +4,8 @@ tests/cases/conformance/functions/functionOverloadErrors.ts(50,25): error TS2304 tests/cases/conformance/functions/functionOverloadErrors.ts(51,32): error TS2304: Cannot find name 'window'. tests/cases/conformance/functions/functionOverloadErrors.ts(65,13): error TS2385: Overload signatures must all be public, private or protected. tests/cases/conformance/functions/functionOverloadErrors.ts(68,13): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/functions/functionOverloadErrors.ts(75,21): error TS2383: Overload signatures must all be exported or not exported. -tests/cases/conformance/functions/functionOverloadErrors.ts(79,14): error TS2383: Overload signatures must all be exported or not exported. +tests/cases/conformance/functions/functionOverloadErrors.ts(75,21): error TS2383: Overload signatures must all be exported or non-exported. +tests/cases/conformance/functions/functionOverloadErrors.ts(79,14): error TS2383: Overload signatures must all be exported or non-exported. tests/cases/conformance/functions/functionOverloadErrors.ts(85,18): error TS2384: Overload signatures must all be ambient or non-ambient. tests/cases/conformance/functions/functionOverloadErrors.ts(90,18): error TS2384: Overload signatures must all be ambient or non-ambient. tests/cases/conformance/functions/functionOverloadErrors.ts(94,10): error TS2394: Overload signature is not compatible with function implementation. @@ -103,13 +103,13 @@ tests/cases/conformance/functions/functionOverloadErrors.ts(116,19): error TS237 module M { export function fn1(); ~~~ -!!! error TS2383: Overload signatures must all be exported or not exported. +!!! error TS2383: Overload signatures must all be exported or non-exported. function fn1(n: string); function fn1() { } function fn2(n: string); ~~~ -!!! error TS2383: Overload signatures must all be exported or not exported. +!!! error TS2383: Overload signatures must all be exported or non-exported. export function fn2(); export function fn2() { } } diff --git a/tests/baselines/reference/overloadModifiersMustAgree.errors.txt b/tests/baselines/reference/overloadModifiersMustAgree.errors.txt index 0efdbcdd1f6..8fbc4b4fda5 100644 --- a/tests/baselines/reference/overloadModifiersMustAgree.errors.txt +++ b/tests/baselines/reference/overloadModifiersMustAgree.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/overloadModifiersMustAgree.ts(2,12): error TS2385: Overload signatures must all be public, private or protected. tests/cases/compiler/overloadModifiersMustAgree.ts(6,18): error TS2384: Overload signatures must all be ambient or non-ambient. -tests/cases/compiler/overloadModifiersMustAgree.ts(7,17): error TS2383: Overload signatures must all be exported or not exported. +tests/cases/compiler/overloadModifiersMustAgree.ts(7,17): error TS2383: Overload signatures must all be exported or non-exported. tests/cases/compiler/overloadModifiersMustAgree.ts(12,5): error TS2386: Overload signatures must all be optional or required. @@ -17,7 +17,7 @@ tests/cases/compiler/overloadModifiersMustAgree.ts(12,5): error TS2386: Overload !!! error TS2384: Overload signatures must all be ambient or non-ambient. export function bar(s: string); ~~~ -!!! error TS2383: Overload signatures must all be exported or not exported. +!!! error TS2383: Overload signatures must all be exported or non-exported. function bar(s?: string) { } interface I {