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

IOperation API support for BoundDynamicInvocation #20114

Closed
mavasani opened this issue Jun 8, 2017 · 6 comments
Closed

IOperation API support for BoundDynamicInvocation #20114

mavasani opened this issue Jun 8, 2017 · 6 comments
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Analyzers Bug Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature - IOperation IOperation Urgency-Now
Milestone

Comments

@mavasani
Copy link
Contributor

mavasani commented Jun 8, 2017

This bound node is very similar to BoundCall, except that we have a set of applicable methods instead of a single TargetMethod.

We have couple of choices for the API here:

  1. Reuse IInvocationExpression, and set the TargetMethod to null. In future, when we expose the MethodGroup from IInvocationExpression, the applicable methods can be exposed through this API.
  2. Create a new IDynamicInvocationExpression type:
    public interface IDynamicInvocationExpression : IHasArgumentsExpression
    {
        /// <summary>
        /// Applicable methods.
        /// </summary>
        ImmutableArray<IMethodSymbol> ApplicableMethods { get; }
        /// <summary>
        /// 'This' or 'Me' instance to be supplied to the method, or null if the method is static.
        /// </summary>
        IOperation Instance { get; }
        /// <summary>
        /// True if the invocation uses a virtual mechanism, and false otherwise.
        /// </summary>
        bool IsVirtual { get; }
    }

(1) is similar to the approach we chose for Dynamic collection initializer, but it might be more error prone for analyzer authors as everyone might expect a non-null IInvocationExpression.TargetMethod method for an error free case.

@mavasani mavasani added Area-Analyzers Bug Concept-API This issue involves adding, removing, clarification, or modification of an API. Discussion Feature - IOperation IOperation labels Jun 8, 2017
@mavasani
Copy link
Contributor Author

mavasani commented Jun 8, 2017

@jinujoseph We can discuss this today.

@jinujoseph
Copy link
Contributor

Design Team Decision

We should have at least have "Name" and "Ref Kind" 
Not sure if IhasArgument Expression is going to give all information because the names are part of the information that is passed to the runtime binder. Today IHasArgumentExpression doesn't pass Name at all, so if the information is shared with indexing then we need to have a common interface IDynamicArgument. 

Take a look what's given to runtime binder, and also look at different flavors of dynamic operation. 

@mavasani
Copy link
Contributor Author

See #21711 (comment) for discussion

@CyrusNajmabadi
Copy link
Member

Design decision:

have IDynamicInvocationExpression.
// Use for C# and VB.
It will have a list of expression for the arguments.
There should be two helper methods on this:

// Always null for VB.  Documented as what it does for C#
RefKind? GetRefKind(int argumentIndex);

// Returns null if not a named arg.  Or the name if it was.
string GetArgumentName(int argumentIndex);

(Names can be tweaked)

--

IDynamicMemberAccessExpression
// Used for VB and C#.

--

IDynamicIndexerAccessExpression
// Only ever for C#.

--

IDynamicObjectCreationExpressoin
// Only for C#? what happens in VB if you do "new Foo(somethingDynamic)"

@mavasani
Copy link
Contributor Author

mavasani commented Sep 1, 2017

IDynamicObjectCreationExpressoin
// Only for C#? what happens in VB if you do "new Foo(somethingDynamic)"

Confirmed there is no dynamic/late bound object creation in VB.

Source code:

Option Strict Off

Class Program
    Public Sub New(i As Integer)
    End Sub

    Public Sub New(i As Double)
    End Sub
    Sub M(args As String(), d As Object)
        Dim y = New Program(d)
    End Sub
End Class

Errors:

Error	1	BC30519: Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
    'Public Sub New(i As Integer)': Argument matching parameter 'i' narrows from 'Object' to 'Integer'.
    'Public Sub New(i As Double)': Argument matching parameter 'i' narrows from 'Object' to 'Double'.		10	21	

Operation Tree:

IOperation tree for "New Program(d)"

IInvalidExpression (OperationKind.InvalidExpression, Type: Program, IsInvalid) (Syntax: 'New Program(d)')
  Children(2):
      IOperation:  (OperationKind.None, IsInvalid) (Syntax: 'Program')
      IParameterReferenceExpression: d (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'd')

@tmat tmat removed the Urgency-Soon label Sep 6, 2017
@jinujoseph jinujoseph added Urgency-Now 4 - In Review A fix for the issue is submitted for review. labels Sep 14, 2017
@mavasani
Copy link
Contributor Author

Fixed with #21711

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Analyzers Bug Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature - IOperation IOperation Urgency-Now
Projects
None yet
Development

No branches or pull requests

5 participants