Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Treat record positional parameters as properties#48329

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@Youssef1313
Copy link
Member

Fixes#48310

jnm2 reacted with heart emoji
@Youssef1313Youssef1313 requested a review froma team as acode ownerOctober 5, 2020 16:11
@jinujosephjinujoseph added Area-IDE CommunityThe pull request was submitted by a contributor who is not a Microsoft employee. labelsOct 5, 2020
Copy link
Member

@davidwengierdavidwengier left a comment

Choose a reason for hiding this comment

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

May be a nit, but in my opinion it would be nicer to add anIsPrimaryConstructorParameter method to handle this case, and save having to add a parameter to the lambda in this way. It would also make the resulting code self documenting.

@Youssef1313
Copy link
MemberAuthor

@davidwengier I think I'd still need the lambda parameter if I will rely onIsLastTokenOfType. But I might include a new parameter forIsLastTokenOfType that will holdFunc<TSyntaxNode, bool>. This argument will always be_ => true except for the new introduced methodIsPrimaryConstructorParameter. This is the approach that comes to mind if I introduced the method you suggested. Is there a better approach?

@davidwengier
Copy link
Member

davidwengier commentedOct 7, 2020
edited
Loading

@Youssef1313 I haven't thought it through completely, so if you think its not possible, or any better, that's cool, I just pictured something like the tuple handling (seeIsTupleTypeElement), where you can usetoken.GetAncestor<TSyntaxNode>(), and if the node is a parameter of a primary constructor, then go from there.

@Youssef1313
Copy link
MemberAuthor

@davidwengier I made it as a separate method as you suggested and relied on callingtoken.GetAncestor. The only problem with this approach is that GetAncestor is now called twice for the same token. One time inIsLastTokenOfType and the other inIsPrimaryConstructorParameter. I assume the call is cheap and won't impact performance.

privatestaticboolIsPrimaryConstructorParameter(SyntaxTokentoken,SemanticModelsemanticModel,
CancellationTokencancellationToken,outNameDeclarationInforesult)
{
result=IsLastTokenOfType<ParameterSyntax>(
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

By the way, the method name here is very confusing. The name suggests that it returns a bool, but it doesn't.

I would suggest an analyzer to warn for things like this.
Would this be an IDExxxx rule or a CAxxxx rule?

@Youssef1313Youssef1313force-pushed thesuggestion-for-record-param branch from347d428 tob5732e9CompareOctober 7, 2020 14:12
cancellationToken);

returnresult.Type!=null&&
token.GetAncestor<ParameterSyntax>().Parent.IsParentKind(SyntaxKind.RecordDeclaration);
Copy link
Member

Choose a reason for hiding this comment

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

This check should come first, andresult should be default if it fails.

@Youssef1313
Copy link
MemberAuthor

Closing/re-opening for fresh build.

@Youssef1313Youssef1313 deleted the suggestion-for-record-param branchNovember 4, 2020 13:31
@Youssef1313Youssef1313 restored the suggestion-for-record-param branchNovember 4, 2020 13:31
@Youssef1313
Copy link
MemberAuthor

@davidwengier for reviewing after applying review feedback

Copy link
Member

@davidwengierdavidwengier left a comment

Choose a reason for hiding this comment

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

Thanks!

@davidwengierdavidwengier merged commit3655d54 intodotnet:masterDec 14, 2020
@ghostghost added this to theNext milestoneDec 14, 2020
@Youssef1313Youssef1313 deleted the suggestion-for-record-param branchDecember 14, 2020 06:17
333fred added a commit to 333fred/roslyn that referenced this pull requestDec 15, 2020
* upstream/master: (241 commits)  Allow pattern matching `null` against pointer types when the pointer types contain nested type parameters (dotnet#49915)  Remove document extension method and convert usages to use the text buffer extension method.  VB: Strengthen implementation of `PropertySymbol.IsWritable` against NullReferenceException (dotnet#49962)  Add switch to skip nullable analysis (dotnet#49876)  Update dependencies fromhttps://github.com/dotnet/roslyn build 20201211.16 (dotnet#49958)  Treat record positional parameters as properties (dotnet#48329)  [master] Update dependencies from dotnet/roslyn (dotnet#49395)  VB: Ensure array access indexes undergo conversion to integer even when there is a mismatch with array rank. (dotnet#49907)  Disable OOP when running as cloud environment client VS instance  Rename workspace context method (and unify impls) to better represent the condition being checked  Report non-Const locals used in an expression that must have a constant value. (dotnet#49912)  Add support for more ServiceAudience values (dotnet#49914)  Handle ref-containing structs returned by value from function-pointers (dotnet#49883)  Fix error on out param of extern local function (dotnet#49860)  Fix constructor exit warnings for generic NotNull (dotnet#49841)  Loc updates  Prefer more specific path map key (dotnet#49670)  Rename `_availablelocalFunctionOrdinal` to `_availableLocalFunctionOrdinal` (dotnet#49901)  Fix namespace so that external access wrapper type can be accessed from UT.  XamlProjectService fixes (dotnet#49711)  ...
@dibarbetdibarbet modified the milestones:Next,16.9.P3Dec 19, 2020
@Youssef1313Youssef1313 mentioned this pull requestFeb 18, 2021
92 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@davidwengierdavidwengierdavidwengier approved these changes

Assignees

@sharwellsharwell

Labels

Area-IDECommunityThe pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Milestone

16.9.P3

Development

Successfully merging this pull request may close these issues.

Suggested positional parameter name should be pascal-cased

5 participants

@Youssef1313@davidwengier@sharwell@dibarbet@jinujoseph

[8]ページ先頭

©2009-2025 Movatter.jp