-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Wire up 'writing' parameter through protected derived class detection #43455
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
tests/cases/compiler/publicGetterProtectedSetterFromThisParameter.ts(33,7): error TS2446: Property 'q' is protected and only accessible through an instance of class 'A'. This is an instance of class 'B'. | ||
tests/cases/compiler/publicGetterProtectedSetterFromThisParameter.ts(34,7): error TS2446: Property 'u' is protected and only accessible through an instance of class 'A'. This is an instance of class 'B'. | ||
|
||
|
||
==== tests/cases/compiler/publicGetterProtectedSetterFromThisParameter.ts (2 errors) ==== | ||
class A { | ||
get x() { return 0; } | ||
protected set x(v: number) { } | ||
|
||
public get y() { return 0; } | ||
protected set y(v: number) { } | ||
} | ||
|
||
class B { | ||
get q() { return 0; } | ||
protected set q(v: number) { } | ||
|
||
protected get u() { return 0; } | ||
protected set u(v: number) { } | ||
|
||
foo(this: A, a: A, b: B) { | ||
// Should have no errors in this block | ||
this.x = 0; | ||
this.y = 0; | ||
a.x = 0; | ||
a.y = 0; | ||
b.q = 0; | ||
b.u = 0; | ||
} | ||
} | ||
|
||
function bar(this: A, a: A, b: B) { | ||
this.x = 0; | ||
this.y = 0; | ||
a.x = 0; | ||
a.y = 0; | ||
// These should error | ||
b.q = 0; | ||
~ | ||
!!! error TS2446: Property 'q' is protected and only accessible through an instance of class 'A'. This is an instance of class 'B'. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'll file a new issue |
||
b.u = 0; | ||
~ | ||
!!! error TS2446: Property 'u' is protected and only accessible through an instance of class 'A'. This is an instance of class 'B'. | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//// [publicGetterProtectedSetterFromThisParameter.ts] | ||
class A { | ||
get x() { return 0; } | ||
protected set x(v: number) { } | ||
|
||
public get y() { return 0; } | ||
protected set y(v: number) { } | ||
} | ||
|
||
class B { | ||
get q() { return 0; } | ||
protected set q(v: number) { } | ||
|
||
protected get u() { return 0; } | ||
protected set u(v: number) { } | ||
|
||
foo(this: A, a: A, b: B) { | ||
// Should have no errors in this block | ||
this.x = 0; | ||
this.y = 0; | ||
a.x = 0; | ||
a.y = 0; | ||
b.q = 0; | ||
b.u = 0; | ||
} | ||
} | ||
|
||
function bar(this: A, a: A, b: B) { | ||
this.x = 0; | ||
this.y = 0; | ||
a.x = 0; | ||
a.y = 0; | ||
// These should error | ||
b.q = 0; | ||
b.u = 0; | ||
} | ||
|
||
|
||
//// [publicGetterProtectedSetterFromThisParameter.js] | ||
var A = /** @class */ (function () { | ||
function A() { | ||
} | ||
Object.defineProperty(A.prototype, "x", { | ||
get: function () { return 0; }, | ||
set: function (v) { }, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(A.prototype, "y", { | ||
get: function () { return 0; }, | ||
set: function (v) { }, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return A; | ||
}()); | ||
var B = /** @class */ (function () { | ||
function B() { | ||
} | ||
Object.defineProperty(B.prototype, "q", { | ||
get: function () { return 0; }, | ||
set: function (v) { }, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(B.prototype, "u", { | ||
get: function () { return 0; }, | ||
set: function (v) { }, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
B.prototype.foo = function (a, b) { | ||
// Should have no errors in this block | ||
this.x = 0; | ||
this.y = 0; | ||
a.x = 0; | ||
a.y = 0; | ||
b.q = 0; | ||
b.u = 0; | ||
}; | ||
return B; | ||
}()); | ||
function bar(a, b) { | ||
this.x = 0; | ||
this.y = 0; | ||
a.x = 0; | ||
a.y = 0; | ||
// These should error | ||
b.q = 0; | ||
b.u = 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
=== tests/cases/compiler/publicGetterProtectedSetterFromThisParameter.ts === | ||
class A { | ||
>A : Symbol(A, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 0)) | ||
|
||
get x() { return 0; } | ||
>x : Symbol(A.x, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 1, 23)) | ||
|
||
protected set x(v: number) { } | ||
>x : Symbol(A.x, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 1, 23)) | ||
>v : Symbol(v, Decl(publicGetterProtectedSetterFromThisParameter.ts, 2, 18)) | ||
|
||
public get y() { return 0; } | ||
>y : Symbol(A.y, Decl(publicGetterProtectedSetterFromThisParameter.ts, 2, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 4, 30)) | ||
|
||
protected set y(v: number) { } | ||
>y : Symbol(A.y, Decl(publicGetterProtectedSetterFromThisParameter.ts, 2, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 4, 30)) | ||
>v : Symbol(v, Decl(publicGetterProtectedSetterFromThisParameter.ts, 5, 18)) | ||
} | ||
|
||
class B { | ||
>B : Symbol(B, Decl(publicGetterProtectedSetterFromThisParameter.ts, 6, 1)) | ||
|
||
get q() { return 0; } | ||
>q : Symbol(B.q, Decl(publicGetterProtectedSetterFromThisParameter.ts, 8, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 9, 23)) | ||
|
||
protected set q(v: number) { } | ||
>q : Symbol(B.q, Decl(publicGetterProtectedSetterFromThisParameter.ts, 8, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 9, 23)) | ||
>v : Symbol(v, Decl(publicGetterProtectedSetterFromThisParameter.ts, 10, 18)) | ||
|
||
protected get u() { return 0; } | ||
>u : Symbol(B.u, Decl(publicGetterProtectedSetterFromThisParameter.ts, 10, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 12, 33)) | ||
|
||
protected set u(v: number) { } | ||
>u : Symbol(B.u, Decl(publicGetterProtectedSetterFromThisParameter.ts, 10, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 12, 33)) | ||
>v : Symbol(v, Decl(publicGetterProtectedSetterFromThisParameter.ts, 13, 18)) | ||
|
||
foo(this: A, a: A, b: B) { | ||
>foo : Symbol(B.foo, Decl(publicGetterProtectedSetterFromThisParameter.ts, 13, 32)) | ||
>this : Symbol(this, Decl(publicGetterProtectedSetterFromThisParameter.ts, 15, 6)) | ||
>A : Symbol(A, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 0)) | ||
>a : Symbol(a, Decl(publicGetterProtectedSetterFromThisParameter.ts, 15, 14)) | ||
>A : Symbol(A, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 0)) | ||
>b : Symbol(b, Decl(publicGetterProtectedSetterFromThisParameter.ts, 15, 20)) | ||
>B : Symbol(B, Decl(publicGetterProtectedSetterFromThisParameter.ts, 6, 1)) | ||
|
||
// Should have no errors in this block | ||
this.x = 0; | ||
>this.x : Symbol(A.x, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 1, 23)) | ||
>this : Symbol(this, Decl(publicGetterProtectedSetterFromThisParameter.ts, 15, 6)) | ||
>x : Symbol(A.x, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 1, 23)) | ||
|
||
this.y = 0; | ||
>this.y : Symbol(A.y, Decl(publicGetterProtectedSetterFromThisParameter.ts, 2, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 4, 30)) | ||
>this : Symbol(this, Decl(publicGetterProtectedSetterFromThisParameter.ts, 15, 6)) | ||
>y : Symbol(A.y, Decl(publicGetterProtectedSetterFromThisParameter.ts, 2, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 4, 30)) | ||
|
||
a.x = 0; | ||
>a.x : Symbol(A.x, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 1, 23)) | ||
>a : Symbol(a, Decl(publicGetterProtectedSetterFromThisParameter.ts, 15, 14)) | ||
>x : Symbol(A.x, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 1, 23)) | ||
|
||
a.y = 0; | ||
>a.y : Symbol(A.y, Decl(publicGetterProtectedSetterFromThisParameter.ts, 2, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 4, 30)) | ||
>a : Symbol(a, Decl(publicGetterProtectedSetterFromThisParameter.ts, 15, 14)) | ||
>y : Symbol(A.y, Decl(publicGetterProtectedSetterFromThisParameter.ts, 2, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 4, 30)) | ||
|
||
b.q = 0; | ||
>b.q : Symbol(B.q, Decl(publicGetterProtectedSetterFromThisParameter.ts, 8, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 9, 23)) | ||
>b : Symbol(b, Decl(publicGetterProtectedSetterFromThisParameter.ts, 15, 20)) | ||
>q : Symbol(B.q, Decl(publicGetterProtectedSetterFromThisParameter.ts, 8, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 9, 23)) | ||
|
||
b.u = 0; | ||
>b.u : Symbol(B.u, Decl(publicGetterProtectedSetterFromThisParameter.ts, 10, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 12, 33)) | ||
>b : Symbol(b, Decl(publicGetterProtectedSetterFromThisParameter.ts, 15, 20)) | ||
>u : Symbol(B.u, Decl(publicGetterProtectedSetterFromThisParameter.ts, 10, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 12, 33)) | ||
} | ||
} | ||
|
||
function bar(this: A, a: A, b: B) { | ||
>bar : Symbol(bar, Decl(publicGetterProtectedSetterFromThisParameter.ts, 24, 1)) | ||
>this : Symbol(this, Decl(publicGetterProtectedSetterFromThisParameter.ts, 26, 13)) | ||
>A : Symbol(A, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 0)) | ||
>a : Symbol(a, Decl(publicGetterProtectedSetterFromThisParameter.ts, 26, 21)) | ||
>A : Symbol(A, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 0)) | ||
>b : Symbol(b, Decl(publicGetterProtectedSetterFromThisParameter.ts, 26, 27)) | ||
>B : Symbol(B, Decl(publicGetterProtectedSetterFromThisParameter.ts, 6, 1)) | ||
|
||
this.x = 0; | ||
>this.x : Symbol(A.x, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 1, 23)) | ||
>this : Symbol(this, Decl(publicGetterProtectedSetterFromThisParameter.ts, 26, 13)) | ||
>x : Symbol(A.x, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 1, 23)) | ||
|
||
this.y = 0; | ||
>this.y : Symbol(A.y, Decl(publicGetterProtectedSetterFromThisParameter.ts, 2, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 4, 30)) | ||
>this : Symbol(this, Decl(publicGetterProtectedSetterFromThisParameter.ts, 26, 13)) | ||
>y : Symbol(A.y, Decl(publicGetterProtectedSetterFromThisParameter.ts, 2, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 4, 30)) | ||
|
||
a.x = 0; | ||
>a.x : Symbol(A.x, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 1, 23)) | ||
>a : Symbol(a, Decl(publicGetterProtectedSetterFromThisParameter.ts, 26, 21)) | ||
>x : Symbol(A.x, Decl(publicGetterProtectedSetterFromThisParameter.ts, 0, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 1, 23)) | ||
|
||
a.y = 0; | ||
>a.y : Symbol(A.y, Decl(publicGetterProtectedSetterFromThisParameter.ts, 2, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 4, 30)) | ||
>a : Symbol(a, Decl(publicGetterProtectedSetterFromThisParameter.ts, 26, 21)) | ||
>y : Symbol(A.y, Decl(publicGetterProtectedSetterFromThisParameter.ts, 2, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 4, 30)) | ||
|
||
// These should error | ||
b.q = 0; | ||
>b.q : Symbol(B.q, Decl(publicGetterProtectedSetterFromThisParameter.ts, 8, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 9, 23)) | ||
>b : Symbol(b, Decl(publicGetterProtectedSetterFromThisParameter.ts, 26, 27)) | ||
>q : Symbol(B.q, Decl(publicGetterProtectedSetterFromThisParameter.ts, 8, 9), Decl(publicGetterProtectedSetterFromThisParameter.ts, 9, 23)) | ||
|
||
b.u = 0; | ||
>b.u : Symbol(B.u, Decl(publicGetterProtectedSetterFromThisParameter.ts, 10, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 12, 33)) | ||
>b : Symbol(b, Decl(publicGetterProtectedSetterFromThisParameter.ts, 26, 27)) | ||
>u : Symbol(B.u, Decl(publicGetterProtectedSetterFromThisParameter.ts, 10, 32), Decl(publicGetterProtectedSetterFromThisParameter.ts, 12, 33)) | ||
} | ||
|
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.
highly recommend switching from
foo/bar/baz
todonkey/diddy/cranky
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.
bananas