Skip to content

Fix find all references of inherited constructor #30514

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

Merged
merged 9 commits into from
Mar 22, 2019

Conversation

gabritto
Copy link
Member

Fixes #30216

verify.referenceGroups(aCtr, [
{ definition: "class A", ranges: [aCtr, aNew] },
{ definition: "class B", ranges: [cSuper, bNew]},
{ definition: "class D", ranges: [dNew]}]);
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add tests for finding constructors for all other classes as well. Also tests for constructor invocation locations as well

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to do this but find all references only understands that we are looking for a constructor reference if we call it on a constructor declaration. So if we call find all references on a constructor invocation like new B(), it will return references to the class B. I'm not sure if this is the expected behavior and don't know how to write those tests. Should I open an issue about this? @sandersn @sheetalkamat

Copy link
Member

Choose a reason for hiding this comment

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

You might as well open an issue, although this seems like something that might have an existing issue.

}

function findInheritedConstructorReferences(classDeclaration: ClassLikeDeclaration, state: State): void {
if (hasOwnConstructor(classDeclaration)) return undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Don't you need to look if this class is extending another class and look for its constructor even though this doesn't have constructor?

Copy link
Member

Choose a reason for hiding this comment

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

I think this line quits early in exactly the case that find-all-refs is called on B below:

class A { constructor() { } }
class B extends A { constructor ()  { } }

That's because B does have its own constructor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. The reasoning is that this function will only be called when we are looking for a class' (A) constructor and we find a reference that is like class B extends A. So I think it is enough to check if B doesn't have is own constructor declared.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Looks good, just need the tests @sheetalkamat suggested.

}

function findInheritedConstructorReferences(classDeclaration: ClassLikeDeclaration, state: State): void {
if (hasOwnConstructor(classDeclaration)) return undefined;
Copy link
Member

Choose a reason for hiding this comment

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

I think this line quits early in exactly the case that find-all-refs is called on B below:

class A { constructor() { } }
class B extends A { constructor ()  { } }

That's because B does have its own constructor.

@gabritto gabritto merged commit 0f6f3b7 into master Mar 22, 2019
@gabritto gabritto deleted the fixFindAllRefsInheritedConstructor branch March 22, 2019 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants