Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #6154 - overriding methods with properties in the derived class #24343

Merged
merged 3 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24430,7 +24430,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: () => { };
}