Skip to content
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

Fix crash in goto-def on @override #51016

Merged
merged 8 commits into from Oct 3, 2022
Merged

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Sep 30, 2022

getDefinitionFromOverriddenMember previously assumed that getTypeOfSymbolAtLocation returned undefined for a missing type, not errorType. This fixes that.

Fixes #50892

sandersn added 2 commits Sep 30, 2022
When the base type is not defined, getDefinitionFromOverriddenMember
will have its type as errorType, which has no symbol. The error handling
previously only handled the case of no baseType at all -- which I'm not
sure ever actually happens.
1. getTypeAtLocation never returns undefined, only errorType, so check for that.
2. Return directly after missing baseTypeNode instead of continuing to return later.
@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Sep 30, 2022
@sandersn sandersn requested review from gabritto and iisaduan Sep 30, 2022
@sandersn
Copy link
Member Author

sandersn commented Oct 1, 2022

baselines must use getSymbolAtLocation because lots of them change. I'll look at them after the weekend and see if the changes will affect anything but baselines.

@sandersn
Copy link
Member Author

sandersn commented Oct 3, 2022

I reverted the change to getSymbolAtLocation and I'll make that a separate PR, since it's more of an improvement in code readability and possibly in language service functionality.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Oct 3, 2022

@typescript-bot test tsserver top100

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 3, 2022

Heya @DanielRosenwasser, I've started to run the diff-based top-repos suite (tsserver) on this PR at c1babc8. You can monitor the build here.

if (!baseType) return;
if (!baseTypeNode) return;
const expression = skipParentheses(baseTypeNode.expression);
const base = isClassExpression(expression) ? expression.symbol : typeChecker.getSymbolAtLocation(expression);
Copy link
Member

@DanielRosenwasser DanielRosenwasser Oct 3, 2022

Choose a reason for hiding this comment

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

Actually, why are you checking for isClassExpression? Can't you use getDeclaredTypeOfSymbol?

Copy link
Member Author

@sandersn sandersn Oct 3, 2022

Choose a reason for hiding this comment

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

I have to follow Node -> Symbol -> Type, and getSymbolAtLocation doesn't support (parenthesised) class expressions right now, which breaks the Node -> Symbol. Previously, the code used getTypeAtLocation, which does support class expressions. I happen to know that class expressions have a symbol, so I can special-case the Node -> Symbol step for now.

I'm going to follow this PR with one that moves the paren/class-expr check into getTypeAtLocation, but it changes lots of our baselines since, apparently, we use it for type baselines.

@sandersn
Copy link
Member Author

sandersn commented Oct 3, 2022

Half of the top100 failed to run, but the half that did has no new errors. I think that's good enough.

@sandersn sandersn merged commit 299745c into main Oct 3, 2022
13 checks passed
@sandersn sandersn deleted the fix-crash-in-goto-def-override branch Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception while resolving base type from JSDoc for references request
3 participants