Skip to content

allow access protected member in this parameter context - #24645

Merged
Mohamed Hegazy (mhegazy) merged 4 commits into
microsoft:masterfrom
Kingwl:this-type-accessibility
Jun 11, 2018
Merged

Mohamed Hegazy (mhegazy) merged 4 commits into
microsoft:masterfrom
Kingwl:this-type-accessibility

Conversation

@Kingwl

@Kingwl Wenlu Wang (Kingwl) commented Jun 4, 2018 •

Copy link
Copy Markdown
Contributor

this PR take a simple implement

  • lookup ThisParameter when cannot find enclosingClass in protected accessibility check
  • get Constraint if typeof this is generic parameter

Fixes #10302

Comment thread src/compiler/checker.ts Outdated
return false;
let thisParameter: ParameterDeclaration | undefined;
const thisContainer = getThisContainer(node, /* includeArrowFunctions */ false);
if (!thisContainer || !isFunctionLike(thisContainer) || !(thisParameter = getThisParameter(thisContainer)) || !thisParameter.type) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is kind of weird that this works for static properties without this.. i think we should prohibit this. e.g.:

class C { 
    protected static S = 0;
}

C.S;  // Error

function f(this: C) { 
    C.S; // OK
}

@mhegazy

Copy link
Copy Markdown
Contributor

Wesley Wigham (@weswigham) can you please review this change.

Comment thread src/compiler/checker.ts Outdated
// static member access is disallow
let thisParameter: ParameterDeclaration | undefined;
const thisContainer = getThisContainer(node, /* includeArrowFunctions */ false);
if (flags & ModifierFlags.Static || !thisContainer || !isFunctionLike(thisContainer) || !(thisParameter = getThisParameter(thisContainer)) || !thisParameter.type) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. i would move the check for the flag above the request for getThisContainer

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants