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

public enum DeclarationKind must have an InitAccessor member #48136

Closed
Youssef1313 opened this issue Sep 28, 2020 · 19 comments · Fixed by #52803
Closed

public enum DeclarationKind must have an InitAccessor member #48136

Youssef1313 opened this issue Sep 28, 2020 · 19 comments · Fixed by #52803
Labels
Area-IDE Concept-Continuous Improvement Need More Info The issue needs more information to proceed.
Milestone

Comments

@Youssef1313
Copy link
Member

https://docs.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.editing.declarationkind?view=roslyn-dotnet

The current enum members include GetAccessor, SetAccessor, but not InitAccessor.

@sharwell
Copy link
Member

Why not just use SetAccessor?

@Youssef1313
Copy link
Member Author

@sharwell Did you mean that SyntaxGenerator.GetDeclarationKind(SyntaxNode) method should return "DeclarationKind.SetAccessor" for both set and init declarations?
I think they need to be treated differently as they're 3 different accessors.

@Youssef1313
Copy link
Member Author

Also, SyntaxGenerator currently have GetSetAccessorStatements, and GetGetAccessorStatements. A new method GetInitAccessorStatements should be considered.

@sharwell
Copy link
Member

Isn't an init accessor just a set accessor with use-site restrictions?

@Youssef1313
Copy link
Member Author

@sharwell Yes, it's even compiled to set_PropName, but I think that's from a semantics.
The enumeration is involved in usage with SyntaxGenerator, so I think if they are separated, that will give consumers more flexibility to do what they want.

@CyrusNajmabadi
Copy link
Member

Isn't an init accessor just a set accessor with use-site restrictions?

Yes. And my understanding is that that's how the compiler is exposing this info.

@Youssef1313
Copy link
Member Author

I'm okay if you agree that both should fall into DeclarationKind.SetAccessor. I'll open a PR

@sharwell
Copy link
Member

I could end up going either way. I can see advantages and disadvantages to both approaches.

@Youssef1313
Copy link
Member Author

Does this method need to account for init as well?

public override IReadOnlyList<SyntaxNode> GetSetAccessorStatements(SyntaxNode declaration)
{
var accessor = GetAccessor(declaration, SyntaxKind.SetAccessorDeclaration);
return accessor?.Body?.Statements ?? s_EmptyList;
}

I think it currently doesn't. I can put that in #48137 as well

@CyrusNajmabadi
Copy link
Member

i think it's challenign to answer some of these without having clear cases of where consumers use this so we can judge what their expectations would be .

@Youssef1313
Copy link
Member Author

@CyrusNajmabadi Is this discussable in a design meeting? or the issue needs to get some comments from consumers to decide?

@CyrusNajmabadi
Copy link
Member

We would likely need comments from consumers here.

@jinujoseph jinujoseph added Concept-Continuous Improvement Need More Info The issue needs more information to proceed. labels Oct 15, 2020
@jinujoseph jinujoseph added this to the Backlog milestone Oct 15, 2020
@Youssef1313
Copy link
Member Author

DeclarationKind enum now contains "RecordClass" member, which is kind of syntactic sugar of a "class" with extra synthesized members.

Given that, I think it makes sense to do that with "init" vs "set" since it's a similar case.

@sharwell @CyrusNajmabadi What are your thoughts?

@Youssef1313
Copy link
Member Author

Also note that GetDeclarationKind will currently return None for init accessors. So if InitAccessor is going to be rejected as a member of the enum, then GetDeclarationKind should be adjusted to return SetAccessor instead of None:

case SyntaxKind.GetAccessorDeclaration:
return DeclarationKind.GetAccessor;
case SyntaxKind.SetAccessorDeclaration:
return DeclarationKind.SetAccessor;
case SyntaxKind.AddAccessorDeclaration:
return DeclarationKind.AddAccessor;
case SyntaxKind.RemoveAccessorDeclaration:
return DeclarationKind.RemoveAccessor;
}
return DeclarationKind.None;

@sharwell
Copy link
Member

sharwell commented Apr 20, 2021

DeclarationKind enum now contains "RecordClass" member

This seems unfortunate. Do we know when it was added?

Edit: It looks like it shipped in 16.9. I'm not sure we need to make the rest of DeclarationKind more complex just because RecordClass wasn't implemented as a duplicate of Class.

@Youssef1313
Copy link
Member Author

Hmmm, from the discussion in #10094, it seems that you're indeed correct. "RecordClass" shouldn't have been added at all. But removing it is a breaking change :/

Now the question is:

  • Should we take a breaking change to keep things consistent?
  • Should GetDeclarationKind return DeclarationKind.None or DeclarationKind.SetAccessor for init declarations?

@sharwell
Copy link
Member

It might not be to late to mark RecordClass Obsolete with the message "This value is not used".

@Youssef1313
Copy link
Member Author

@sharwell Should I open a PR or wait until other team members agree?

@sharwell
Copy link
Member

You could open a draft PR to frame the discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Concept-Continuous Improvement Need More Info The issue needs more information to proceed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants