Need to add a couple of errors and squash one

Will update after checking out other branch for a minute
This commit is contained in:
Nathan Shively-Sanders 2019-09-16 10:56:30 -07:00
parent ac96739777
commit 70a15bdeeb
6 changed files with 95 additions and 19 deletions

View file

@ -29477,7 +29477,6 @@ namespace ts {
// type declaration, derived and base resolve to the same symbol even in the case of generic classes.
if (derived === base) {
// derived class inherits base without override/redeclaration
const derivedClassDecl = getClassLikeDeclarationOfSymbol(type.symbol)!;
// It is an error to inherit an abstract member without implementing it or being declared abstract.
@ -29522,6 +29521,7 @@ namespace ts {
if (derived.flags & SymbolFlags.Property
&& !(derived.flags & SymbolFlags.Transient)
&& !(baseDeclarationFlags & ModifierFlags.Abstract)
&& !(derivedDeclarationFlags & ModifierFlags.Ambient)
&& !derived.declarations.some(d => d.flags & NodeFlags.Ambient)
&& derived.declarations.some(d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer)) {
const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_provide_an_initializer_with_this_override;
@ -29529,6 +29529,11 @@ namespace ts {
}
continue;
}
if (derivedDeclarationFlags & ModifiersFlags.Ambient) {
const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_provide_an_initializer_with_this_override;
error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type));
continue;
}
let errorMessage: DiagnosticMessage;
if (isPrototypeProperty(base)) {
@ -32518,7 +32523,7 @@ namespace ts {
else if (flags & ModifierFlags.Async) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
}
else if (isClassLike(node.parent)) {
else if (isClassLike(node.parent) && !isPropertyDeclaration(node)) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare");
}
else if (node.kind === SyntaxKind.Parameter) {
@ -33627,7 +33632,7 @@ namespace ts {
}
}
if (node.flags & NodeFlags.Ambient) {
if (node.flags & NodeFlags.Ambient || getModifierFlags(node) & ModifierFlags.Ambient) {
checkAmbientInitializer(node);
}

View file

@ -1,5 +1,5 @@
tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(5,5): error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override.
tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(11,5): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override.
tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(14,5): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override.
==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (2 errors) ====
@ -7,16 +7,22 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP
property = 'x';
}
class B extends A {
property; // should be an error
property; // error
~~~~~~~~
!!! error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override.
}
class BD extends A {
declare property; // still has implicit any
}
class C {
p: string;
}
class D extends C {
p: 'hi'; // should also be an error?
p: 'hi'; // error
~
!!! error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override.
}
class DD extends C {
declare p: 'bye'; // ok
}

View file

@ -3,13 +3,19 @@ class A {
property = 'x';
}
class B extends A {
property; // should be an error
property; // error
}
class BD extends A {
declare property; // still has implicit any
}
class C {
p: string;
}
class D extends C {
p: 'hi'; // should also be an error?
p: 'hi'; // error
}
class DD extends C {
declare p: 'bye'; // ok
}
@ -40,6 +46,13 @@ var B = /** @class */ (function (_super) {
}
return B;
}(A));
var BD = /** @class */ (function (_super) {
__extends(BD, _super);
function BD() {
return _super !== null && _super.apply(this, arguments) || this;
}
return BD;
}(A));
var C = /** @class */ (function () {
function C() {
}
@ -52,3 +65,10 @@ var D = /** @class */ (function (_super) {
}
return D;
}(C));
var DD = /** @class */ (function (_super) {
__extends(DD, _super);
function DD() {
return _super !== null && _super.apply(this, arguments) || this;
}
return DD;
}(C));

View file

@ -9,20 +9,34 @@ class B extends A {
>B : Symbol(B, Decl(derivedUninitializedPropertyDeclaration.ts, 2, 1))
>A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0))
property; // should be an error
property; // error
>property : Symbol(B.property, Decl(derivedUninitializedPropertyDeclaration.ts, 3, 19))
}
class BD extends A {
>BD : Symbol(BD, Decl(derivedUninitializedPropertyDeclaration.ts, 5, 1))
>A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0))
declare property; // still has implicit any
>property : Symbol(BD.property, Decl(derivedUninitializedPropertyDeclaration.ts, 6, 20))
}
class C {
>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 5, 1))
>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1))
p: string;
>p : Symbol(C.p, Decl(derivedUninitializedPropertyDeclaration.ts, 6, 9))
>p : Symbol(C.p, Decl(derivedUninitializedPropertyDeclaration.ts, 9, 9))
}
class D extends C {
>D : Symbol(D, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1))
>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 5, 1))
>D : Symbol(D, Decl(derivedUninitializedPropertyDeclaration.ts, 11, 1))
>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1))
p: 'hi'; // should also be an error?
>p : Symbol(D.p, Decl(derivedUninitializedPropertyDeclaration.ts, 9, 19))
p: 'hi'; // error
>p : Symbol(D.p, Decl(derivedUninitializedPropertyDeclaration.ts, 12, 19))
}
class DD extends C {
>DD : Symbol(DD, Decl(derivedUninitializedPropertyDeclaration.ts, 14, 1))
>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1))
declare p: 'bye'; // ok
>p : Symbol(DD.p, Decl(derivedUninitializedPropertyDeclaration.ts, 15, 20))
}

View file

@ -10,7 +10,14 @@ class B extends A {
>B : B
>A : A
property; // should be an error
property; // error
>property : any
}
class BD extends A {
>BD : BD
>A : A
declare property; // still has implicit any
>property : any
}
class C {
@ -23,7 +30,14 @@ class D extends C {
>D : D
>C : C
p: 'hi'; // should also be an error?
p: 'hi'; // error
>p : "hi"
}
class DD extends C {
>DD : DD
>C : C
declare p: 'bye'; // ok
>p : "bye"
}

View file

@ -1,12 +1,29 @@
// @strict: true
class A {
property = 'x';
m() { return 1 }
}
class B extends A {
property; // should be an error
property; // error
}
class BD extends A {
declare property; // still has implicit any, but is implicitly initialised
}
class BDBang extends A {
declare property!; // still has implicit any, doesn't need !, but has it anyway
}
class BOther extends A {
declare m() { return 2 } // not allowed on methods
declare nonce; // only allowed when exists in base
declare property = 'y' // initialiser not allowed with declare
}
class C {
p: string;
}
class D extends C {
p: 'hi'; // should also be an error?
p: 'hi'; // error
}
class DD extends C {
declare p: 'bye'; // ok
}