-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
IBoundDelegateCreationExpression API #20095
Comments
Fyi @dotnet/analyzer-ioperation |
Need IsCached (but maybe v2 if really hard to provide) |
@CyrusNajmabadi @AlekseyTs @dotnet/analyzer-ioperation, another set of expressions to consider: Action a = delegate() { }; Currently, this ends up being represented as an ILambda, with the appropriate IConversion from lambda to |
This is another syntax for a lambda, there should be no difference with a regular lambda, I think. |
API proposal: /// <summary>
/// Represents a delegate creation expression. This is created whenever a new delegate is created.
/// </summary>
/// <remarks>
/// This interface is reserved for implementation by its associated APIs. We reserve the right to
/// change it in the future.
/// </remarks>
public interface IDelegateCreationExpression : IHasArgumentsExpression
{
/// <summary>
/// Symbol of the method being referenced by this delegate, if any.
/// </summary>
IMethodSymbol Method { get; }
} In C#, the argument will directly be the argument of the BoundDelegateCreationExpression. In VB, we will synthesize an IMethodBindingExpression from the BoundDelegateCreationExpression, and use that as the argument for the IDelegateCreationExpression. For lambdas, we will synthesize IDelegateCreationExpressions when encountering specific IConversionExpressions. In C#, this will be any with ConversionKind.MethodGroup. In VB, I'm still determining what this list will look like, but at an initial look it appears that it will be all conversions with ConversionKind.Lambda set. |
Design Team Decision It probably doesn't make sense to expose the constructor for the delegate and it doesn't make sense to expose it as arguments. We are contracting the delegate either from the method or from the conversion. We should probably have one node IOperationTarget Target is either conversion on top of the Lamda or it represents the method binding. |
Address #8913 as part of this work |
Small point for design discussion today: Given this code: using System;
class P
{
void M1()
{
Action m = (Action)M2;
}
void M2()
{
}
} I'm going to create the following IOperation tree:
The question is how to indicate that this was an explicit cast. I talked with @AlekseyTs, and he proposed using the IsImplicit flag on the IDelegateCreationExpression for this. I like it, but for the sake of discussion, the other option is to put an IConversionExpression above the IDelegateCreationExpression. |
Another small question: given the following code
The underlying BoundNodes have a BoundDelegateCreation with a BoundConversion underneath. Should we detect this case and ensure there is only one IDelegateCreationExpression in the resulting tree, or show that there are in fact two creations here? |
I believe the two nodes are using different target methods, so we should keep both. |
Design decision: // Method reference, wrapped with explicit delegate creation. // Method reference, wrapped with implicit delegate creation |
Given the following C# code:
We currently get the following IOperation tree:
This is inconsistent with the SemanticModel. For GetTypeInfo on the M1 IdentifierSyntaxNode, we have a Type of
null
and a ConvertedType ofProgram.DType
. Note that the underlying BoundNode structure is actually aBoundLocalDeclaration
, with an initializer ofBoundConversion
. We actually detectConversionKind.MethodGroup
and turn them intoIMethodBindingExpression
s. We should synthesize this expression under a conversion expression, and the type of theIMethodBindingExpression
should be null.Further complicating this is the VB equivalent. The following is the equivalent VB code:
This has an IOperation tree of:
The OperationKind.None is because BoundMethodCreationExpression support in VB is not currently implemented, see #19917. The complication is that the SemanticModel API does not return the same results.
AddressOf M1
has a Type ofProgram.DType
, and a ConvertedType ofProgram.DType
. Consistency here would, I think, imply that we shouldn't have anIConversionExpression
, as we never seem to have them for identity conversions. However, this would be inconsistent with the C# API, which I think is more important here. We need to discuss how to resolve these at the IOp meeting.The text was updated successfully, but these errors were encountered: