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

Missing Field/Property reference expression nodes in object creation initializer node #19276

Closed
mavasani opened this issue May 4, 2017 · 1 comment
Assignees
Milestone

Comments

@mavasani
Copy link
Contributor

mavasani commented May 4, 2017

internal class Class
{
    public int Property { get; set; }
    public int Field;

    public void M()
    {
        var c = new Class() { Field = 0, Property = 0 };
    }
}
IOperation tree for "new Class() { Field = 0, Property = 0 }"

IObjectCreationExpression (Constructor: Class..ctor()) (OperationKind.ObjectCreationExpression, Type: Class) (Syntax: 'new Class() ... perty = 0 }')
  Initializers(2): IAssignmentExpression (OperationKind.AssignmentExpression, Type: System.Int32) (Syntax: 'Field = 0')
      Left: IOperation:  (OperationKind.None) (Syntax: 'Field')
      Right: ILiteralExpression (Text: 0) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: '0')
    IAssignmentExpression (OperationKind.AssignmentExpression, Type: System.Int32) (Syntax: 'Property = 0')
      Left: IOperation:  (OperationKind.None) (Syntax: 'Property')
      Right: ILiteralExpression (Text: 0) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: '0')

Expected:

  1. Left: IOperation: (OperationKind.None) (Syntax: 'Field') must be an IFieldReferenceExpression and
  2. Left: IOperation: (OperationKind.None) (Syntax: 'Property') must be an IPropertyReferenceExpression

Similar code in VB does contain the field and property reference expressions on Left:

Friend Class [Class]
    Public Field As Integer
    Public Property Prop As Integer

    Public Sub M()
        Dim c = New [Class]() With {.Field = 0, .Prop = 0}
    End Sub
End Class
IOperation tree for "New [Class]() With {.Field = 0, .Prop = 0}"

IObjectCreationExpression (Constructor: Sub [Class]..ctor()) (OperationKind.ObjectCreationExpression, Type: [Class]) (Syntax: 'New [Class] ...  .Prop = 0}')
  Initializers(2): IAssignmentExpression (OperationKind.AssignmentExpression, Type: System.Int32) (Syntax: '.Field = 0')
      Left: IFieldReferenceExpression: [Class].Field As System.Int32 (OperationKind.FieldReferenceExpression, Type: System.Int32) (Syntax: 'Field')
          Instance Receiver: IOperation:  (OperationKind.None) (Syntax: 'New [Class] ...  .Prop = 0}')
      Right: ILiteralExpression (Text: 0) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: '0')
    IAssignmentExpression (OperationKind.AssignmentExpression, Type: System.Void) (Syntax: '.Prop = 0')
      Left: IIndexedPropertyReferenceExpression: Property [Class].Prop As System.Int32 (OperationKind.PropertyReferenceExpression, Type: System.Int32) (Syntax: 'Prop')
          Instance Receiver: IOperation:  (OperationKind.None) (Syntax: 'New [Class] ...  .Prop = 0}')
      Right: ILiteralExpression (Text: 0) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: '0')
mavasani added a commit to mavasani/roslyn that referenced this issue May 4, 2017
There are couple of changes here:
1. API change: `ImmutableArray<ISymbolInitializer> MemberInitializers` is changed to `ImmutableArray<IOperation> Initializers`.
2. Implementation changes:
   1. Instead of returning the member initializers as synthesized ISymbolInitializer nodes, we now return member intializers as IAssignmentExpression nodes. This ensures completeness of IOperation tree.
   2. Now we also return the collection intializer expressions within an object creation expression.

Fixes dotnet#18115

There are 2 bugs still affecting this area:
1. dotnet#18781: IOperation API shape for collection initializer expressions
2. dotnet#19276: Missing Field/Property reference expression nodes in object creation initializer node
@jinujoseph jinujoseph added this to the 15.5 milestone Jun 27, 2017
@mavasani
Copy link
Contributor Author

Fixed with #20689

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants