Skip to content

Fixed incorrect suggestion for object initialization simplification#23395

Merged
jinujoseph merged 9 commits intodotnet:masterfrom
zaytsev-victor:Fixed23368
Jun 7, 2018
Merged

Fixed incorrect suggestion for object initialization simplification#23395
jinujoseph merged 9 commits intodotnet:masterfrom
zaytsev-victor:Fixed23368

Conversation

@zaytsev-victor
Copy link
Copy Markdown
Contributor

Customer scenario

User can see suggestion for object initialization simplification even if result won't compile.

Bugs this fixes:
Fixes #23368

Risk
Low

Performance impact
Low

Is this a regression from a previous update?
No

ISymbol member)
{
var implementation = classOrStructType?.FindImplementationForInterfaceMember(member);
switch (implementation)
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.

swithc seems like overkill here. why not just:

return implementation is IPropertySymbol property && ...

}
return implementation is IPropertySymbol property &&
property.ExplicitInterfaceImplementations.Length > 0
&& property.DeclaredAccessibility == Accessibility.Private;
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.

&& on previous line.

@jcouv jcouv added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Mar 31, 2018
@zaytsev-victor
Copy link
Copy Markdown
Contributor Author

@jcouv @sharwell any update on this?

@jinujoseph jinujoseph added this to the 15.8 milestone Apr 18, 2018
@jcouv jcouv added the Area-IDE label Apr 18, 2018
Copy link
Copy Markdown
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks

@jcouv
Copy link
Copy Markdown
Member

jcouv commented Apr 18, 2018

@dotnet/roslyn-ide Can we get a final review on this community PR? Thanks

public void Main()
{
IExample e = [||]new C();
e.Name = string.Empty;
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.

so the order causing one to work and not the other? would it be possible to support both if possible?

class C
Sub Bar()
Dim c As IExample = [||]New Foo
c.LastName = String.Empty
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.

same here.

@heejaechang
Copy link
Copy Markdown
Contributor

retest this please

var implementation = classOrStructType?.FindImplementationForInterfaceMember(member);
return implementation is IPropertySymbol property &&
property.ExplicitInterfaceImplementations.Length > 0 &&
property.DeclaredAccessibility == Accessibility.Private;
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.

note: vb can have public implementations where the member name does not match.

Implements IExample

Private Property Name As String Implements IExample.Name
Public Property LastName As String Implements IExample.LastName
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.

can we have a test where these names don't match. i.e. "Public Property MyLastName Implements IExample.LastName"?

@jinujoseph
Copy link
Copy Markdown
Contributor

@zaytsev-victor could you resolve the conflict and address cyrus feedback pls.

@zaytsev-victor zaytsev-victor requested a review from a team as a code owner May 24, 2018 07:33
class C
Sub Bar()
Dim c As IExample = New Foo With {
.LastName = String.Empty
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.

this is error? can we make it to use MyLastName ?

# Conflicts:
#	src/Features/Core/Portable/UseObjectInitializer/ObjectCreationExpressionAnalyzer.cs
@jinujoseph
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi can you review if your feedback is addressed

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Yup. I will take a look later. For some reason my github rules are not working and i'm not getting notifications about these directly :-/

keyKeyword:=Nothing,
dotToken:=match.MemberAccessExpression.OperatorToken,
name:=DirectCast(match.MemberAccessExpression.Name, IdentifierNameSyntax),
name:=SyntaxFactory.IdentifierName(match.MemberName),
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.

this likely will not work for names that are keywords. You store .ValueText which won't have hte propery escaping here.

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.

@CyrusNajmabadi I've tested it with Class, Property and Date keywords. It works, probably we don't need to escape names in object initializer.

property.ExplicitInterfaceImplementations.Length > 0 &&
property.DeclaredAccessibility == Accessibility.Private;

}
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.

extra newline above this.

@zaytsev-victor
Copy link
Copy Markdown
Contributor Author

retest windows_debug_vs-integration_prtest please

@jinujoseph
Copy link
Copy Markdown
Contributor

approved to merge for 15.8.Preview4

@jinujoseph jinujoseph merged commit d2922fd into dotnet:master Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved to merge Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect suggestion for object initialization simplification

6 participants