-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Disallow property/accessor overrides #33401
Closed
+1,697
−15
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f76e01f
Disallow property/accessor overrides
sandersn c26785e
Merge branch 'master' into disallow-property-accessor-override
sandersn c4f334a
Updates from design review + fix ancient bug
sandersn 526ceb7
Merge branch 'master' into disallow-property-accessor-override
sandersn 58e1746
Ignore this-property assignments
sandersn 832d51f
Fix base-in-interface check
sandersn 6ec445f
Fix check
sandersn c283574
Fix new errors in services
sandersn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/baselines/reference/accessorsOverrideProperty.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts(5,9): error TS2611: Class 'A' defines instance member property 'p', but extended class 'B' defines it as instance member accessor. | ||
tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts(12,9): error TS2611: Class 'C' defines instance member property 'p', but extended class 'D' defines it as instance member accessor. | ||
|
||
|
||
==== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts (2 errors) ==== | ||
class A { | ||
p = 'yep' | ||
} | ||
class B extends A { | ||
get p() { return 'oh no' } // error | ||
~ | ||
!!! error TS2611: Class 'A' defines instance member property 'p', but extended class 'B' defines it as instance member accessor. | ||
} | ||
class C { | ||
p = 101 | ||
} | ||
class D extends C { | ||
_secret = 11 | ||
get p() { return this._secret } // error | ||
~ | ||
!!! error TS2611: Class 'C' defines instance member property 'p', but extended class 'D' defines it as instance member accessor. | ||
set p(value) { this._secret = value } // error | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//// [accessorsOverrideProperty.ts] | ||
class A { | ||
p = 'yep' | ||
} | ||
class B extends A { | ||
get p() { return 'oh no' } // error | ||
} | ||
class C { | ||
p = 101 | ||
} | ||
class D extends C { | ||
_secret = 11 | ||
get p() { return this._secret } // error | ||
set p(value) { this._secret = value } // error | ||
} | ||
|
||
|
||
//// [accessorsOverrideProperty.js] | ||
class A { | ||
constructor() { | ||
this.p = 'yep'; | ||
} | ||
} | ||
class B extends A { | ||
get p() { return 'oh no'; } // error | ||
} | ||
class C { | ||
constructor() { | ||
this.p = 101; | ||
} | ||
} | ||
class D extends C { | ||
constructor() { | ||
super(...arguments); | ||
this._secret = 11; | ||
} | ||
get p() { return this._secret; } // error | ||
set p(value) { this._secret = value; } // error | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/baselines/reference/accessorsOverrideProperty.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts === | ||
class A { | ||
>A : Symbol(A, Decl(accessorsOverrideProperty.ts, 0, 0)) | ||
|
||
p = 'yep' | ||
>p : Symbol(A.p, Decl(accessorsOverrideProperty.ts, 0, 9)) | ||
} | ||
class B extends A { | ||
>B : Symbol(B, Decl(accessorsOverrideProperty.ts, 2, 1)) | ||
>A : Symbol(A, Decl(accessorsOverrideProperty.ts, 0, 0)) | ||
|
||
get p() { return 'oh no' } // error | ||
>p : Symbol(B.p, Decl(accessorsOverrideProperty.ts, 3, 19)) | ||
} | ||
class C { | ||
>C : Symbol(C, Decl(accessorsOverrideProperty.ts, 5, 1)) | ||
|
||
p = 101 | ||
>p : Symbol(C.p, Decl(accessorsOverrideProperty.ts, 6, 9)) | ||
} | ||
class D extends C { | ||
>D : Symbol(D, Decl(accessorsOverrideProperty.ts, 8, 1)) | ||
>C : Symbol(C, Decl(accessorsOverrideProperty.ts, 5, 1)) | ||
|
||
_secret = 11 | ||
>_secret : Symbol(D._secret, Decl(accessorsOverrideProperty.ts, 9, 19)) | ||
|
||
get p() { return this._secret } // error | ||
>p : Symbol(D.p, Decl(accessorsOverrideProperty.ts, 10, 17), Decl(accessorsOverrideProperty.ts, 11, 35)) | ||
>this._secret : Symbol(D._secret, Decl(accessorsOverrideProperty.ts, 9, 19)) | ||
>this : Symbol(D, Decl(accessorsOverrideProperty.ts, 8, 1)) | ||
>_secret : Symbol(D._secret, Decl(accessorsOverrideProperty.ts, 9, 19)) | ||
|
||
set p(value) { this._secret = value } // error | ||
>p : Symbol(D.p, Decl(accessorsOverrideProperty.ts, 10, 17), Decl(accessorsOverrideProperty.ts, 11, 35)) | ||
>value : Symbol(value, Decl(accessorsOverrideProperty.ts, 12, 10)) | ||
>this._secret : Symbol(D._secret, Decl(accessorsOverrideProperty.ts, 9, 19)) | ||
>this : Symbol(D, Decl(accessorsOverrideProperty.ts, 8, 1)) | ||
>_secret : Symbol(D._secret, Decl(accessorsOverrideProperty.ts, 9, 19)) | ||
>value : Symbol(value, Decl(accessorsOverrideProperty.ts, 12, 10)) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts === | ||
class A { | ||
>A : A | ||
|
||
p = 'yep' | ||
>p : string | ||
>'yep' : "yep" | ||
} | ||
class B extends A { | ||
>B : B | ||
>A : A | ||
|
||
get p() { return 'oh no' } // error | ||
>p : string | ||
>'oh no' : "oh no" | ||
} | ||
class C { | ||
>C : C | ||
|
||
p = 101 | ||
>p : number | ||
>101 : 101 | ||
} | ||
class D extends C { | ||
>D : D | ||
>C : C | ||
|
||
_secret = 11 | ||
>_secret : number | ||
>11 : 11 | ||
|
||
get p() { return this._secret } // error | ||
>p : number | ||
>this._secret : number | ||
>this : this | ||
>_secret : number | ||
|
||
set p(value) { this._secret = value } // error | ||
>p : number | ||
>value : number | ||
>this._secret = value : number | ||
>this._secret : number | ||
>this : this | ||
>_secret : number | ||
>value : number | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/accessorsOverrideProperty2.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts(6,7): error TS2611: Class 'Base' defines instance member property 'x', but extended class 'Derived' defines it as instance member accessor. | ||
|
||
|
||
==== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts (1 errors) ==== | ||
class Base { | ||
x = 1; | ||
} | ||
|
||
class Derived extends Base { | ||
get x() { return 2; } // should be an error | ||
~ | ||
!!! error TS2611: Class 'Base' defines instance member property 'x', but extended class 'Derived' defines it as instance member accessor. | ||
set x(value) { console.log(`x was set to ${value}`); } | ||
} | ||
|
||
const obj = new Derived(); // nothing printed | ||
console.log(obj.x); // 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//// [accessorsOverrideProperty2.ts] | ||
class Base { | ||
x = 1; | ||
} | ||
|
||
class Derived extends Base { | ||
get x() { return 2; } // should be an error | ||
set x(value) { console.log(`x was set to ${value}`); } | ||
} | ||
|
||
const obj = new Derived(); // nothing printed | ||
console.log(obj.x); // 1 | ||
|
||
|
||
//// [accessorsOverrideProperty2.js] | ||
class Base { | ||
constructor() { | ||
this.x = 1; | ||
} | ||
} | ||
class Derived extends Base { | ||
get x() { return 2; } // should be an error | ||
set x(value) { console.log(`x was set to ${value}`); } | ||
} | ||
const obj = new Derived(); // nothing printed | ||
console.log(obj.x); // 1 |
36 changes: 36 additions & 0 deletions
36
tests/baselines/reference/accessorsOverrideProperty2.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts === | ||
class Base { | ||
>Base : Symbol(Base, Decl(accessorsOverrideProperty2.ts, 0, 0)) | ||
|
||
x = 1; | ||
>x : Symbol(Base.x, Decl(accessorsOverrideProperty2.ts, 0, 12)) | ||
} | ||
|
||
class Derived extends Base { | ||
>Derived : Symbol(Derived, Decl(accessorsOverrideProperty2.ts, 2, 1)) | ||
>Base : Symbol(Base, Decl(accessorsOverrideProperty2.ts, 0, 0)) | ||
|
||
get x() { return 2; } // should be an error | ||
>x : Symbol(Derived.x, Decl(accessorsOverrideProperty2.ts, 4, 28), Decl(accessorsOverrideProperty2.ts, 5, 23)) | ||
|
||
set x(value) { console.log(`x was set to ${value}`); } | ||
>x : Symbol(Derived.x, Decl(accessorsOverrideProperty2.ts, 4, 28), Decl(accessorsOverrideProperty2.ts, 5, 23)) | ||
>value : Symbol(value, Decl(accessorsOverrideProperty2.ts, 6, 8)) | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>value : Symbol(value, Decl(accessorsOverrideProperty2.ts, 6, 8)) | ||
} | ||
|
||
const obj = new Derived(); // nothing printed | ||
>obj : Symbol(obj, Decl(accessorsOverrideProperty2.ts, 9, 5)) | ||
>Derived : Symbol(Derived, Decl(accessorsOverrideProperty2.ts, 2, 1)) | ||
|
||
console.log(obj.x); // 1 | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>obj.x : Symbol(Derived.x, Decl(accessorsOverrideProperty2.ts, 4, 28), Decl(accessorsOverrideProperty2.ts, 5, 23)) | ||
>obj : Symbol(obj, Decl(accessorsOverrideProperty2.ts, 9, 5)) | ||
>x : Symbol(Derived.x, Decl(accessorsOverrideProperty2.ts, 4, 28), Decl(accessorsOverrideProperty2.ts, 5, 23)) | ||
|
42 changes: 42 additions & 0 deletions
42
tests/baselines/reference/accessorsOverrideProperty2.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts === | ||
class Base { | ||
>Base : Base | ||
|
||
x = 1; | ||
>x : number | ||
>1 : 1 | ||
} | ||
|
||
class Derived extends Base { | ||
>Derived : Derived | ||
>Base : Base | ||
|
||
get x() { return 2; } // should be an error | ||
>x : number | ||
>2 : 2 | ||
|
||
set x(value) { console.log(`x was set to ${value}`); } | ||
>x : number | ||
>value : number | ||
>console.log(`x was set to ${value}`) : void | ||
>console.log : (message?: any, ...optionalParams: any[]) => void | ||
>console : Console | ||
>log : (message?: any, ...optionalParams: any[]) => void | ||
>`x was set to ${value}` : string | ||
>value : number | ||
} | ||
|
||
const obj = new Derived(); // nothing printed | ||
>obj : Derived | ||
>new Derived() : Derived | ||
>Derived : typeof Derived | ||
|
||
console.log(obj.x); // 1 | ||
>console.log(obj.x) : void | ||
>console.log : (message?: any, ...optionalParams: any[]) => void | ||
>console : Console | ||
>log : (message?: any, ...optionalParams: any[]) => void | ||
>obj.x : number | ||
>obj : Derived | ||
>x : number | ||
|
15 changes: 15 additions & 0 deletions
15
tests/baselines/reference/accessorsOverrideProperty3.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts(6,9): error TS2611: Class 'Animal' defines instance member property 'sound', but extended class 'Lion' defines it as instance member accessor. | ||
|
||
|
||
==== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts (1 errors) ==== | ||
declare class Animal { | ||
sound: string | ||
} | ||
class Lion extends Animal { | ||
_sound = 'grrr' | ||
get sound() { return this._sound } // error here | ||
~~~~~ | ||
!!! error TS2611: Class 'Animal' defines instance member property 'sound', but extended class 'Lion' defines it as instance member accessor. | ||
set sound(val) { this._sound = val } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//// [accessorsOverrideProperty3.ts] | ||
declare class Animal { | ||
sound: string | ||
} | ||
class Lion extends Animal { | ||
_sound = 'grrr' | ||
get sound() { return this._sound } // error here | ||
set sound(val) { this._sound = val } | ||
} | ||
|
||
|
||
//// [accessorsOverrideProperty3.js] | ||
class Lion extends Animal { | ||
constructor() { | ||
super(...arguments); | ||
this._sound = 'grrr'; | ||
} | ||
get sound() { return this._sound; } // error here | ||
set sound(val) { this._sound = val; } | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change makes it obvious that this line is always false and its contents are dead code. I'll remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errr, instead I tried reviving it. We'll see how much code has unknowingly been missing this error.