Skip to content

Commit 13734e7

Browse files
Fix for issue #6154 - overriding methods with properties in the derived class (#24343)
* Fix to issue 6154 - Overriding a method with a property in the derived class should not cause a compiler error * new baselines * fixed deleted baselines
1 parent 9b9ec63 commit 13734e7

12 files changed

+101
-93
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24489,7 +24489,7 @@ namespace ts {
2448924489
continue;
2449024490
}
2449124491

24492-
if (isPrototypeProperty(base) && isPrototypeProperty(derived) || base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) {
24492+
if (isPrototypeProperty(base) || base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) {
2449324493
// method is overridden with method or property/accessor is overridden with property/accessor - correct case
2449424494
continue;
2449524495
}

tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt

-25
This file was deleted.

tests/baselines/reference/inheritanceMemberAccessorOverridingMethod.errors.txt

-36
This file was deleted.

tests/baselines/reference/inheritanceMemberAccessorOverridingMethod.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class a {
77

88
class b extends a {
99
get x() {
10-
return "20";
10+
return () => "20";
1111
}
12-
set x(aValue: string) {
13-
12+
set x(aValue) {
13+
1414
}
1515
}
1616

@@ -40,7 +40,7 @@ var b = /** @class */ (function (_super) {
4040
}
4141
Object.defineProperty(b.prototype, "x", {
4242
get: function () {
43-
return "20";
43+
return function () { return "20"; };
4444
},
4545
set: function (aValue) {
4646
},

tests/baselines/reference/inheritanceMemberAccessorOverridingMethod.symbols

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class b extends a {
1616
get x() {
1717
>x : Symbol(b.x, Decl(inheritanceMemberAccessorOverridingMethod.ts, 6, 19), Decl(inheritanceMemberAccessorOverridingMethod.ts, 9, 5))
1818

19-
return "20";
19+
return () => "20";
2020
}
21-
set x(aValue: string) {
21+
set x(aValue) {
2222
>x : Symbol(b.x, Decl(inheritanceMemberAccessorOverridingMethod.ts, 6, 19), Decl(inheritanceMemberAccessorOverridingMethod.ts, 9, 5))
2323
>aValue : Symbol(aValue, Decl(inheritanceMemberAccessorOverridingMethod.ts, 10, 10))
24-
24+
2525
}
2626
}

tests/baselines/reference/inheritanceMemberAccessorOverridingMethod.types

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ class b extends a {
1515
>a : a
1616

1717
get x() {
18-
>x : string
18+
>x : () => string
1919

20-
return "20";
20+
return () => "20";
21+
>() => "20" : () => string
2122
>"20" : "20"
2223
}
23-
set x(aValue: string) {
24-
>x : string
25-
>aValue : string
26-
24+
set x(aValue) {
25+
>x : () => string
26+
>aValue : () => string
27+
2728
}
2829
}

tests/baselines/reference/inheritanceMemberPropertyOverridingMethod.errors.txt

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [propertyOverridingPrototype.ts]
2+
class Base {
3+
foo() {
4+
}
5+
}
6+
7+
class Derived extends Base {
8+
foo: () => { };
9+
}
10+
11+
12+
13+
//// [propertyOverridingPrototype.js]
14+
var __extends = (this && this.__extends) || (function () {
15+
var extendStatics = Object.setPrototypeOf ||
16+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
17+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
18+
return function (d, b) {
19+
extendStatics(d, b);
20+
function __() { this.constructor = d; }
21+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
22+
};
23+
})();
24+
var Base = /** @class */ (function () {
25+
function Base() {
26+
}
27+
Base.prototype.foo = function () {
28+
};
29+
return Base;
30+
}());
31+
var Derived = /** @class */ (function (_super) {
32+
__extends(Derived, _super);
33+
function Derived() {
34+
return _super !== null && _super.apply(this, arguments) || this;
35+
}
36+
return Derived;
37+
}(Base));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/propertyOverridingPrototype.ts ===
2+
class Base {
3+
>Base : Symbol(Base, Decl(propertyOverridingPrototype.ts, 0, 0))
4+
5+
foo() {
6+
>foo : Symbol(Base.foo, Decl(propertyOverridingPrototype.ts, 0, 12))
7+
}
8+
}
9+
10+
class Derived extends Base {
11+
>Derived : Symbol(Derived, Decl(propertyOverridingPrototype.ts, 3, 1))
12+
>Base : Symbol(Base, Decl(propertyOverridingPrototype.ts, 0, 0))
13+
14+
foo: () => { };
15+
>foo : Symbol(Derived.foo, Decl(propertyOverridingPrototype.ts, 5, 28))
16+
}
17+
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/propertyOverridingPrototype.ts ===
2+
class Base {
3+
>Base : Base
4+
5+
foo() {
6+
>foo : () => void
7+
}
8+
}
9+
10+
class Derived extends Base {
11+
>Derived : Derived
12+
>Base : Base
13+
14+
foo: () => { };
15+
>foo : () => {}
16+
}
17+
18+
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @target: es5
12
class a {
23
x() {
34
return "20";
@@ -6,9 +7,9 @@ class a {
67

78
class b extends a {
89
get x() {
9-
return "20";
10+
return () => "20";
1011
}
11-
set x(aValue: string) {
12-
12+
set x(aValue) {
13+
1314
}
1415
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Base {
2+
foo() {
3+
}
4+
}
5+
6+
class Derived extends Base {
7+
foo: () => { };
8+
}
9+

0 commit comments

Comments
 (0)