From ab56cc0c6bfefd259e3f51d24a145e5524b87184 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 15 Oct 2019 14:11:51 -0700 Subject: [PATCH] Remove property-override-method error (#34494) Originally removed incorrectly along with method-override-property error in #24343, then both were restored in #33509. Only method-override-property should be an error, since it doesn't actually work at runtime. --- src/compiler/checker.ts | 10 +++----- src/compiler/diagnosticMessages.json | 4 --- .../checkJsFiles_noErrorLocation.errors.txt | 25 ------------------- ...eMemberPropertyOverridingMethod.errors.txt | 15 ----------- .../propertyOverridesMethod.errors.txt | 13 ---------- .../propertyOverridingPrototype.errors.txt | 16 ------------ 6 files changed, 4 insertions(+), 79 deletions(-) delete mode 100644 tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt delete mode 100644 tests/baselines/reference/inheritanceMemberPropertyOverridingMethod.errors.txt delete mode 100644 tests/baselines/reference/propertyOverridesMethod.errors.txt delete mode 100644 tests/baselines/reference/propertyOverridingPrototype.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3162f2bb76588..b1c206def3ce4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -31692,15 +31692,13 @@ namespace ts { } } else if (isPrototypeProperty(base)) { - if (isPrototypeProperty(derived)) { - // method is overridden with method -- correct case + if (isPrototypeProperty(derived) || derived.flags & SymbolFlags.Property) { + // method is overridden with method or property -- correct case continue; } - else if (derived.flags & SymbolFlags.Accessor) { - errorMessage = Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor; - } else { - errorMessage = Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_property; + Debug.assert(!!(derived.flags & SymbolFlags.Accessor)); + errorMessage = Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor; } } else if (base.flags & SymbolFlags.Accessor) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index dede443895730..100d1a55a0b36 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1561,10 +1561,6 @@ "category": "Error", "code": 2423 }, - "Class '{0}' defines instance member function '{1}', but extended class '{2}' defines it as instance member property.": { - "category": "Error", - "code": 2424 - }, "Class '{0}' defines instance member property '{1}', but extended class '{2}' defines it as instance member function.": { "category": "Error", "code": 2425 diff --git a/tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt b/tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt deleted file mode 100644 index d9104608284a9..0000000000000 --- a/tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt +++ /dev/null @@ -1,25 +0,0 @@ -tests/cases/compiler/a.js(14,10): error TS2424: Class 'A' defines instance member function 'foo', but extended class 'B' defines it as instance member property. - - -==== tests/cases/compiler/a.js (1 errors) ==== - // @ts-check - class A { - constructor() { - - } - foo() { - return 4; - } - } - - class B extends A { - constructor() { - super(); - this.foo = () => 3; - ~~~ -!!! error TS2424: Class 'A' defines instance member function 'foo', but extended class 'B' defines it as instance member property. - } - } - - const i = new B(); - i.foo(); \ No newline at end of file diff --git a/tests/baselines/reference/inheritanceMemberPropertyOverridingMethod.errors.txt b/tests/baselines/reference/inheritanceMemberPropertyOverridingMethod.errors.txt deleted file mode 100644 index 2b56866b22b33..0000000000000 --- a/tests/baselines/reference/inheritanceMemberPropertyOverridingMethod.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/inheritanceMemberPropertyOverridingMethod.ts(8,5): error TS2424: Class 'a' defines instance member function 'x', but extended class 'b' defines it as instance member property. - - -==== tests/cases/compiler/inheritanceMemberPropertyOverridingMethod.ts (1 errors) ==== - class a { - x() { - return "20"; - } - } - - class b extends a { - x: () => string; - ~ -!!! error TS2424: Class 'a' defines instance member function 'x', but extended class 'b' defines it as instance member property. - } \ No newline at end of file diff --git a/tests/baselines/reference/propertyOverridesMethod.errors.txt b/tests/baselines/reference/propertyOverridesMethod.errors.txt deleted file mode 100644 index aaee2d48cf658..0000000000000 --- a/tests/baselines/reference/propertyOverridesMethod.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts(5,5): error TS2424: Class 'A' defines instance member function 'm', but extended class 'B' defines it as instance member property. - - -==== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts (1 errors) ==== - class A { - m() { } - } - class B extends A { - m = () => 1 - ~ -!!! error TS2424: Class 'A' defines instance member function 'm', but extended class 'B' defines it as instance member property. - } - \ No newline at end of file diff --git a/tests/baselines/reference/propertyOverridingPrototype.errors.txt b/tests/baselines/reference/propertyOverridingPrototype.errors.txt deleted file mode 100644 index a585f7999f603..0000000000000 --- a/tests/baselines/reference/propertyOverridingPrototype.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/compiler/propertyOverridingPrototype.ts(7,5): error TS2424: Class 'Base' defines instance member function 'foo', but extended class 'Derived' defines it as instance member property. - - -==== tests/cases/compiler/propertyOverridingPrototype.ts (1 errors) ==== - class Base { - foo() { - } - } - - class Derived extends Base { - foo: () => { }; - ~~~ -!!! error TS2424: Class 'Base' defines instance member function 'foo', but extended class 'Derived' defines it as instance member property. - } - - \ No newline at end of file