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

GoToDefinition on var in var pattern doesn't navigate to type #51615

Closed
jcouv opened this issue Mar 3, 2021 · 3 comments · Fixed by #51620
Closed

GoToDefinition on var in var pattern doesn't navigate to type #51615

jcouv opened this issue Mar 3, 2021 · 3 comments · Fixed by #51620
Labels
4 - In Review A fix for the issue is submitted for review. Area-IDE Bug
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented Mar 3, 2021

It is possible to use GoToDefinition on var in local declarations, out variables and deconstructions.
But it doesn't work on a var pattern:

string M() { }

void M2()
{
  if (M() is var$$ x && x.Length > 0) // GoToDefinition on `var` should go to definition of `string` type
  {
  }
}

Looking at compiler test SwitchExpression_10, I think that GetDeclaredSymbol and GetTypeInfo work on var patterns, so I suspect this is an IDE problem.

@jcouv jcouv added the Area-IDE label Mar 3, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Mar 3, 2021
@Youssef1313
Copy link
Member

One difference to note is that var in patterns is parsed as VarKeyword. While in local declarations it's parsed as IdentifierToken.

@Youssef1313
Copy link
Member

Youssef1313 commented Mar 3, 2021

I'm not able to debug currently.

But I see the following method is used by SymbolFinder:

public bool IsBindableToken(SyntaxToken token)
{
if (this.IsWord(token) || this.IsLiteral(token) || this.IsOperator(token))
{
switch ((SyntaxKind)token.RawKind)
{
case SyntaxKind.DelegateKeyword:
case SyntaxKind.VoidKeyword:
return false;
}
return true;
}
// In the order by clause a comma might be bound to ThenBy or ThenByDescending
if (token.Kind() == SyntaxKind.CommaToken && token.Parent.IsKind(SyntaxKind.OrderByClause))
{
return true;
}
return false;
}

I suspect that it returns true for var when it's IdentifierToken, but not when it's VarKeyword. (I was incorrect)

This was referenced Mar 3, 2021
@Youssef1313
Copy link
Member

@jcouv I opened #51620 in an attempt to fix this.

@jinujoseph jinujoseph added 4 - In Review A fix for the issue is submitted for review. Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 4, 2021
@jinujoseph jinujoseph added this to the 16.10 milestone Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-IDE Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants