GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow visibility on constructors by AbubakerB · Pull Request #4174 · microsoft/TypeScript

Conversation

@AbubakerB

@AbubakerB Abubaker Bashir (AbubakerB) commented Aug 6, 2015

Copy link
Copy Markdown
Contributor

Fixes #2341.

Changes:
1 - Allows private, protected and public accessibilities on constructors.
2 - Disallows classes with private constructors from being extended.
3 - Now throws an error on constructor overloads with different access modifiers (than the constructors implementation).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Abubaker Bashir (AbubakerB) added 3 commits August 6, 2015 00:48
@AbubakerB
Fixes issue #2341
708f423
@AbubakerB
Add tests for issue #2341
9dfa9c7
@AbubakerB
Accept baselines
6d01766
@msftclas

Microsoft Contribution License Agreements (msftclas) commented Aug 6, 2015

Copy link
Copy Markdown

Hi Abubaker Bashir (@AbubakerB), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!
We will now validate the agreement and then real humans will evaluate your PR.

TTYL, MSBOT;

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-signed label Aug 6, 2015
@RyanCavanaugh

Ryan Cavanaugh (RyanCavanaugh) commented Aug 6, 2015

Copy link
Copy Markdown
Member

For this to work properly, the visibility needs to be part of the construct signature rather than being a declaration-based check that happens during signature resolution. Otherwise it's going to be too difficult to enforce assignability constraints based on constructor visibility.

A relevant testcase to add would be:

class Foo {
  private constructor() { }
}
class Bar {
  protected constructor() { }
}
let x: new() => any;
x = Foo; // Should be an error
x = Bar; // Should be an error
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Abubaker Bashir (AbubakerB) added 5 commits August 12, 2015 00:13
@AbubakerB
Add check on construct signature and relevant test cases.
7105a41
@AbubakerB
Refactor constructor call visibility check
51bf395
@AbubakerB
Clean ups!
c87c3c5
@AbubakerB
null check and only check signature visibility on Construct Kind.
f66e66d
@AbubakerB
Accept baselines
5421ac8
@AbubakerB

Abubaker Bashir (AbubakerB) commented Aug 12, 2015

Copy link
Copy Markdown
Contributor Author

Ryan Cavanaugh (@RyanCavanaugh) SignaturesRelatedTo now checks visibility of constructor.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AbubakerB

Abubaker Bashir (AbubakerB) commented Sep 10, 2015

Copy link
Copy Markdown
Contributor Author

Should i close this off? or is this in the pipeline?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DanielRosenwasser
DanielRosenwasser reviewed Sep 13, 2015
View reviewed changes
Comment thread src/compiler/checker.ts Outdated

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Sep 13, 2015

Copy link
Copy Markdown
Member

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.

Can you wrap these return statements with curlies and place them on their own line?

if (!constructor || !node.expression) {
    return;
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@AbubakerB Abubaker Bashir (AbubakerB) Sep 14, 2015

Copy link
Copy Markdown
Contributor Author

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.

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Sep 13, 2015

Copy link
Copy Markdown
Member

The declaration emitter will need to be amended - add // @declaration: true to the top of every affected test file.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Sep 13, 2015

Copy link
Copy Markdown
Member

The following test cases would be useful too:

class Base {
    protected constructor() {
    }
}

class Derived extends Base {
    private constructor() {
        super();
    }
}
class Base {
    protected constructor() {
    }
}

class Derived extends Base {
    protected constructor() {
        super();
    }
}

var baseCtor = Base;
baseCtor = Derived;
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Sep 13, 2015

Copy link
Copy Markdown
Member

Abubaker Bashir (@AbubakerB) sorry this fell off of our radar, we've been hard at work on TypeScript 1.6.

Anders Hejlsberg (@ahejlsberg) Mohamed Hegazy (@mhegazy) Vladimir Matveev (@vladima) any thoughts?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Abubaker Bashir (AbubakerB) added 4 commits September 14, 2015 22:34
@AbubakerB
Addressed CR feedback
ffec744
@AbubakerB
Changed error message for mismatching ctor signature
0e8ecbd
@AbubakerB
Addressed test PR feedback.
3732fcd
@AbubakerB
Accepted new baselines
f2d3b29
@AbubakerB

Abubaker Bashir (AbubakerB) commented Sep 14, 2015

Copy link
Copy Markdown
Contributor Author

Daniel Rosenwasser (@DanielRosenwasser) I see, that's fine :)

  1. I've added // @declaration: true to the three test files.
  2. Added test cases under classConstructorAccessibility2.ts. Although, I have one question... Can a X ctor signature be assigned to a non-X ctor signature? (where X is public/protected/private).
  3. Renamed the diagnostic message for error code 2656 to be more clear.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DanielRosenwasser
DanielRosenwasser reviewed Sep 15, 2015
View reviewed changes
Comment thread tests/baselines/reference/classConstructorAccessibility.errors.txt Outdated

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Sep 15, 2015

Copy link
Copy Markdown
Member

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.

Shouldn't this be new (x: number): D?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@AbubakerB Abubaker Bashir (AbubakerB) Sep 15, 2015

Copy link
Copy Markdown
Contributor Author

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.

What would be the best way of adding the new before the signature output?
I can't seem to find any method that writes 'new' + signature.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Abubaker Bashir (AbubakerB) added 2 commits September 15, 2015 21:51
@AbubakerB
Addressed PR feedback - Amended diagnostic messages
35fceb9
@AbubakerB
Accept baselines
f6d8a0c
@RyanCavanaugh

Ryan Cavanaugh (RyanCavanaugh) commented Jan 25, 2016

Copy link
Copy Markdown
Member

Abubaker Bashir (@AbubakerB) can you get this up-to-date and resubmit in a new PR? Very sorry we left this hanging for so long.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@AbubakerB @msftclas @RyanCavanaugh @DanielRosenwasser
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.