Skip to content

Commit

Permalink
Fix for issue #6154 - overriding methods with properties in the deriv…
Browse files Browse the repository at this point in the history
…ed 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
  • Loading branch information
elizabethdinella authored May 24, 2018
1 parent 9b9ec63 commit 13734e7
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24489,7 +24489,7 @@ namespace ts {
continue;
}

if (isPrototypeProperty(base) && isPrototypeProperty(derived) || base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) {
if (isPrototypeProperty(base) || base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) {
// method is overridden with method or property/accessor is overridden with property/accessor - correct case
continue;
}
Expand Down
25 changes: 0 additions & 25 deletions tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class a {

class b extends a {
get x() {
return "20";
return () => "20";
}
set x(aValue: string) {

set x(aValue) {
}
}

Expand Down Expand Up @@ -40,7 +40,7 @@ var b = /** @class */ (function (_super) {
}
Object.defineProperty(b.prototype, "x", {
get: function () {
return "20";
return function () { return "20"; };
},
set: function (aValue) {
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class b extends a {
get x() {
>x : Symbol(b.x, Decl(inheritanceMemberAccessorOverridingMethod.ts, 6, 19), Decl(inheritanceMemberAccessorOverridingMethod.ts, 9, 5))

return "20";
return () => "20";
}
set x(aValue: string) {
set x(aValue) {
>x : Symbol(b.x, Decl(inheritanceMemberAccessorOverridingMethod.ts, 6, 19), Decl(inheritanceMemberAccessorOverridingMethod.ts, 9, 5))
>aValue : Symbol(aValue, Decl(inheritanceMemberAccessorOverridingMethod.ts, 10, 10))

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ class b extends a {
>a : a

get x() {
>x : string
>x : () => string

return "20";
return () => "20";
>() => "20" : () => string
>"20" : "20"
}
set x(aValue: string) {
>x : string
>aValue : string

set x(aValue) {
>x : () => string
>aValue : () => string
}
}

This file was deleted.

37 changes: 37 additions & 0 deletions tests/baselines/reference/propertyOverridingPrototype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//// [propertyOverridingPrototype.ts]
class Base {
foo() {
}
}

class Derived extends Base {
foo: () => { };
}



//// [propertyOverridingPrototype.js]
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var Base = /** @class */ (function () {
function Base() {
}
Base.prototype.foo = function () {
};
return Base;
}());
var Derived = /** @class */ (function (_super) {
__extends(Derived, _super);
function Derived() {
return _super !== null && _super.apply(this, arguments) || this;
}
return Derived;
}(Base));
18 changes: 18 additions & 0 deletions tests/baselines/reference/propertyOverridingPrototype.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
=== tests/cases/compiler/propertyOverridingPrototype.ts ===
class Base {
>Base : Symbol(Base, Decl(propertyOverridingPrototype.ts, 0, 0))

foo() {
>foo : Symbol(Base.foo, Decl(propertyOverridingPrototype.ts, 0, 12))
}
}

class Derived extends Base {
>Derived : Symbol(Derived, Decl(propertyOverridingPrototype.ts, 3, 1))
>Base : Symbol(Base, Decl(propertyOverridingPrototype.ts, 0, 0))

foo: () => { };
>foo : Symbol(Derived.foo, Decl(propertyOverridingPrototype.ts, 5, 28))
}


18 changes: 18 additions & 0 deletions tests/baselines/reference/propertyOverridingPrototype.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
=== tests/cases/compiler/propertyOverridingPrototype.ts ===
class Base {
>Base : Base

foo() {
>foo : () => void
}
}

class Derived extends Base {
>Derived : Derived
>Base : Base

foo: () => { };
>foo : () => {}
}


Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @target: es5
class a {
x() {
return "20";
Expand All @@ -6,9 +7,9 @@ class a {

class b extends a {
get x() {
return "20";
return () => "20";
}
set x(aValue: string) {

set x(aValue) {
}
}
9 changes: 9 additions & 0 deletions tests/cases/compiler/propertyOverridingPrototype.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Base {
foo() {
}
}

class Derived extends Base {
foo: () => { };
}

0 comments on commit 13734e7

Please sign in to comment.