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

[API proposal]: GetDeclaredSymbol for lambdas #63051

Open
Youssef1313 opened this issue Jul 29, 2022 · 2 comments
Open

[API proposal]: GetDeclaredSymbol for lambdas #63051

Youssef1313 opened this issue Jul 29, 2022 · 2 comments
Assignees
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation Area-Compilers Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request
Milestone

Comments

@Youssef1313
Copy link
Member

Youssef1313 commented Jul 29, 2022

Background and Motivation

The node kinds SyntaxKind.AnonymousMethodExpression, SyntaxKind.ParenthesizedLambdaExpression, and SyntaxKind.SimpleLambdaExpression declares lambda symbols, but not supported by GetDeclaredSymbol

Proposed API

namespace Microsoft.CodeAnalysis.CSharp
{
     internal class CSharpSemanticModel
     {
+        public abstract ISymbol GetDeclaredSymbol(AnonymousFunctionExpressionSyntax anonymousFunctionSyntax, CancellationToken cancellationToken = default(CancellationToken));
     }

namespace Microsoft.CodeAnalysis
{
     public static class CSharpExtensions
     {
+        public static ISymbol? GetDeclaredSymbol(this SemanticModel? semanticModel, AnonymousFunctionExpressionSyntax anonymousFunctionSyntax, CancellationToken cancellationToken = default(CancellationToken))
     }
}

There will be parallel changes to VB.

Usage Examples

Alternative Designs

Risks

@Youssef1313 Youssef1313 added Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request labels Jul 29, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 29, 2022
@333fred 333fred added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 29, 2022
@333fred 333fred added this to the 17.4 milestone Jul 29, 2022
@CyrusNajmabadi
Copy link
Member

I would support this. But it's worht a discussion. These guys are very funky in that they really can declare entirely fresh symbols (Esp. now with the work for lambda defaults and whatnot), but you have to do GetSymbolInfo on them. The latter does makes sense as these are also expressions though.

Generally speaking though, this divergence has always been odd on the IDE side. We generally have had to constantly special case these guys, rather than uniformly going through GetDeclaredSymbol. It has felt weird that virtually all other type/member symbols that come from something in source use a one mechanism, but these use another.

I'm curious what compiler thinks though. That said, i'm guessing IDE is more the primary consumer of these APIs, so maybe we defer more to that need?

@333fred
Copy link
Member

333fred commented Aug 18, 2022

API Review

  • Should we just have GetSymbolInfo be the API you use here?
  • We need to investigate the behavior of GetSymbolInfo/GetDeclaredSymbol for:
    • Local functions
    • Anonymous types
    • Tuples
    • Other GetDeclaredSymbol examples that are not suffixed with "DeclarationSyntax"
  • Do any of them return info from both of these APIs?

@333fred 333fred added api-needs-work API needs work before it is approved, it is NOT ready for implementation and removed api-ready-for-review API is ready for review, it is NOT ready for implementation labels Aug 18, 2022
@jaredpar jaredpar modified the milestones: 17.4, 17.5 Oct 7, 2022
@jaredpar jaredpar modified the milestones: 17.5, 17.6 Jan 5, 2023
@jaredpar jaredpar modified the milestones: 17.6, C# 12.0 Feb 15, 2023
@jaredpar jaredpar modified the milestones: C# 12.0, Backlog Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation Area-Compilers Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request
Projects
None yet
Development

No branches or pull requests

4 participants