Skip to content

Fix Use Auto Property handling of VB's As New syntax#26592

Merged
sharwell merged 4 commits intodotnet:masterfrom
sharwell:auto-property-as-new
May 4, 2018
Merged

Fix Use Auto Property handling of VB's As New syntax#26592
sharwell merged 4 commits intodotnet:masterfrom
sharwell:auto-property-as-new

Conversation

@sharwell
Copy link
Copy Markdown
Contributor

@sharwell sharwell commented May 3, 2018

Fixes #26256

Ask Mode template not completed

Customer scenario

What does the customer do to get into this situation, and why do we think this
is common enough to address for this release. (Granted, sometimes this will be
obvious "Open project, VS crashes" but in general, I need to understand how
common a scenario is)

Bugs this fixes

(either VSO or GitHub links)

Workarounds, if any

Also, why we think they are insufficient for RC vs. RC2, RC3, or RTW

Risk

This is generally a measure our how central the affected code is to adjacent
scenarios and thus how likely your fix is to destabilize a broader area of code

Performance impact

(with a brief justification for that assessment (e.g. "Low perf impact because no extra allocations/no complexity changes" vs. "Low")

Is this a regression from a previous update?

Root cause analysis

How did we miss it? What tests are we adding to guard against it in the future?

How was the bug found?

(E.g. customer reported it vs. ad hoc testing)

Test documentation updated?

If this is a new non-compiler feature or a significant improvement to an existing feature, update https://github.com/dotnet/roslyn/wiki/Manual-Testing once you know which release it is targeting.

@sharwell sharwell requested a review from a team as a code owner May 3, 2018 16:18
@sharwell sharwell added this to the 15.8 milestone May 3, 2018
end class",
"class Class1
readonly property P as Guid
= new Guid(""{00000000-0000-0000-0000-000000000000}"")
Copy link
Copy Markdown
Contributor

@Neme12 Neme12 May 3, 2018

Choose a reason for hiding this comment

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

why do we need to change the syntax? i think this should be:

    readonly property P as new Guid(""{00000000-0000-0000-0000-000000000000}"")

Copy link
Copy Markdown
Contributor Author

@sharwell sharwell May 3, 2018

Choose a reason for hiding this comment

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

➡️ The language-agnostic code generator cannot currently distinguish between these two cases.

Copy link
Copy Markdown
Contributor

@Neme12 Neme12 May 3, 2018

Choose a reason for hiding this comment

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

if the user prefers that, we shouldn't change their code unnecessarily

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This request cannot be implemented without a substantial modification to the code generation infrastructure. As a bug fix for a situation capable of unexpectedly deleting important code, I do not believe the limitation should block progress on this fix.

Copy link
Copy Markdown
Contributor

@Neme12 Neme12 May 3, 2018

Choose a reason for hiding this comment

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

looking at the code above, I see VB specific code above GetFieldInitializer, not a language agnostic generator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

specifically this line:

                statement = statement.WithInitializer(SyntaxFactory.EqualsValue(initializer))

there should be something like WithAsClause

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looking at this another way: prior to this pull request the following code is generated:

readonly property P as Guid

The form used in this pull request is objectively better than the previous implementation in both behavior and style, even if it does not represent the ideal end goal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

➡️ This is now corrected per #26592 (comment)

Dim identifier = TryCast(Await fieldSymbol.DeclaringSyntaxReferences(0).GetSyntaxAsync(cancellationToken).ConfigureAwait(False), ModifiedIdentifierSyntax)
Dim declarator = TryCast(identifier?.Parent, VariableDeclaratorSyntax)
Return declarator?.Initializer?.Value
Dim initializer = declarator?.Initializer?.Value
Copy link
Copy Markdown
Contributor

@Neme12 Neme12 May 3, 2018

Choose a reason for hiding this comment

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

this seems a little unnecessary too - we're getting the expression from the initializer only to then construct a new initializer above - we could just return the initializer itself, together with the as clause as a tuple maybe?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

then a few lines above the code would be changed to

statement = statement.WithInitializer(initializer).WithAsClause(asClause)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

➡️ This change could be implemented as a follow-up improvement, but is outside the scope of the bug fix. The code changes for this pull request were intentionally kept to a minimum and to match d2dc228.

Copy link
Copy Markdown
Contributor

@Neme12 Neme12 May 3, 2018

Choose a reason for hiding this comment

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

well it's sort of a bug fix that introduces another small bug :-/ i think the proper fix should be really easy and probably add even less lines of code than this one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

📝 If I don't make a change here, I'll file a new issue in dotnet/roslyn so this feedback is not lost. The request is certainly reasonable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

➡️ I went ahead and made this change since, unlike the commit referenced above, this code fix does not use the language-agnostic syntax generator for this part.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thank you

@jcouv jcouv added the Area-IDE label May 3, 2018
Dim declarator = TryCast(identifier?.Parent, VariableDeclaratorSyntax)
Return declarator?.Initializer?.Value
Dim initializer = declarator?.Initializer
Dim asNewClause = TryCast(declarator.AsClause, AsNewClauseSyntax)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is the trycast necessary?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah, i see why.might be worth a comment.

@sharwell
Copy link
Copy Markdown
Contributor Author

sharwell commented May 3, 2018

@jinujoseph For approval

@jinujoseph
Copy link
Copy Markdown
Contributor

Approved to merge for 15.8.preview2

@sharwell sharwell merged commit 250804a into dotnet:master May 4, 2018
@sharwell sharwell deleted the auto-property-as-new branch May 4, 2018 12:22
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.

"Use auto property" code fix loses initialized value

6 participants