Skip to content

Conversation

RikkiGibson
Copy link
Member

@RikkiGibson RikkiGibson commented Jan 20, 2022

Closes #58307
Related to #58335

There were many CFG tests that I felt were obviated. I decided to just keep one of them as a "sanity test" to demonstrate that we don't generate nodes for the null-check.

@ghost ghost added the Area-Compilers label Jan 20, 2022
@RikkiGibson RikkiGibson marked this pull request as ready for review January 21, 2022 20:35
@RikkiGibson RikkiGibson requested review from a team as code owners January 21, 2022 20:35
// We never expect multiple declarations for a parameter symbol.
// Partial method parameters are distinct symbols on each method declaration
Contract.ThrowIfTrue(syntaxRefs.Length > 1);
return syntaxRefs.SingleOrDefault() is SyntaxReference syntaxReference
Copy link
Member

Choose a reason for hiding this comment

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

SingleOrDefault will throw when there are multiple references. taht woudl be bad.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did this because I really do expect a parameter to never have multiple syntax references. Is there a different way of handling this scenario you would prefer? For example, just take the first reference if any, check if any of the references have the !! token, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a different way of handling this scenario you would prefer? For example, just take the first reference if any, check if any of the references have the !! token, etc.

Checking if any references have !! seems reasonable to me.

Copy link
Member

@Youssef1313 Youssef1313 Jan 22, 2022

Choose a reason for hiding this comment

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

I think it's important to know if in any case (even in future), we can have multiple syntax locations for a parameter. I'd add a Debug.Assert in the base parameter symbol with a comment explaining that this API is assuming a single syntax reference, or no references at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's important to know if in any case (even in future), we can have multiple syntax locations for a parameter. I'd add a Debug.Assert in the base parameter symbol with a comment explaining that this API is assuming a single syntax reference, or no references at all.

This was my inclination as well. However, I think Debug.Assert will realistically only end up catching the issue if an editor feature test is added which exercises such a new parameter symbol while also using this new API.

Copy link
Member

Choose a reason for hiding this comment

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

@RikkiGibson I mean adding the assert in ParameterSymbol constructor

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I overlooked what you actually said. If we can identify a reasonable central place to assert this assumption, I would be fine with taking it in a separate PR.

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

IDE side LGTM with teh changes requested.

…ic/Services/SemanticFacts/VisualBasicSemanticFacts.vb

Co-authored-by: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
@RikkiGibson
Copy link
Member Author

@chsienki @dotnet/roslyn-compiler for second review.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 4)

@RikkiGibson RikkiGibson enabled auto-merge (squash) January 25, 2022 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parameter null-checking public API

6 participants