-
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
IConversionExpression Rework #20046
Comments
Note: this should probably be represented as |
Design Team Decision: |
@AlekseyTs had some comments on this in #20416 (comment). |
Design Team Decision: |
I think we should also start pulling together a common type that has values we know are always safe to get back to. This could be an object that also allows one to get back to the language specific structs (through extenesion methods at the individual language layers) for features that need exact, rich, language specific data. i.e. we could have: public abstract class CommonConversion {
// common stuff
}
// C# layer
internal class CSharpConversion : CommonConversion {
public readonly Conversion UnderlyingConversion;
}
...
public static Conversion GetCSharpConversion(this CommonConversion conversion)
=> ((CSharpConversion)conversion).UnderlyingConversion; |
@CyrusNajmabadi and I have talked about this offline, and here's what I'm proposing for V1:
New IConversionExpression: /// <summary>
/// Represents a conversion operation.
/// </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 IConversionExpression
{
/// <summary>
/// Value to be converted.
/// </summary>
IOperation Operand { get; }
/// <summary>
/// Gets the underlying conversion. This will be either <see cref="Microsoft.CodeAnalysis.CSharp.Conversion"/>
/// or <see cref="Microsoft.CodeAnalysis.VisualBasic.Conversion"/>.
/// </summary>
/// <typeparam name="TConversion">The specific conversion kind for the language of the code.</typeparam>
/// <returns>The conversion struct. If the wrong conversion type is specified, a <see cref="ArgumentException"/> will be thrown.</returns>
TConversion GetConversion<TConversion>() where TConversion : struct, IConversion;
/// <summary>
/// True if and only if the conversion is indicated explicity by a cast operation in the source code.
/// </summary>
bool IsExplicitInCode { get; }
/// <summary>
/// The language that defined this conversion. Possible values are <see cref="LanguageNames.CSharp"/> and
/// <see cref="LanguageNames.VisualBasic"/>.
/// </summary>
string LanguageName { get; }
} New /// <summary>
/// Represents a conversion that is convertible to a language-specific conversion. This can be either
/// a <see cref="Microsoft.CodeAnalysis.CSharp.Conversion"/> or
/// <see cref="Microsoft.CodeAnalysis.VisualBasic.Conversion"/>.
/// <remarks>
/// This interface is reserved for implementation by its associated APIs. We reserve the right to
/// change it in the future.
/// </remarks>
public interface IConversion
{
/// <summary>
/// Returns true if the conversion exists, as defined by the target language.
/// </summary>
/// <remarks>
/// The existence of a conversion does not necessarily imply that the conversion is valid.
/// For example, an ambiguous user-defined conversion may exist but may not be valid.
/// </remarks>
public bool Exists { get; }
/// <summary>
/// Returns true if the conversion is an identity conversion.
/// </summary>
public bool IsIdentity { get; }
/// <summary>
/// Returns true if the conversion is a numeric conversion.
/// </summary>
public bool IsNumeric { get; }
/// <summary>
/// Returns true if the conversion is a user-defined conversion.
/// </summary>
public bool IsUserDefined { get; }
/// <summary>
/// Returns the method used to perform the conversion for a user-defined conversion if <see cref="IsUserDefined"/> is true.
/// Otherwise, returns null.
/// </summary>
public IMethodSymbol MethodSymbol { get; }
} |
Fixed in #21040. |
Note the ConversionKind.Invalid. This is because the underlying BoundConversion has ConversionKind.InterpolatedString, which is not in our public API. This conversion is part of the C# spec, and should be reflected as a conversion type in the IOperation tree. FYI @mavasani @dotnet/analyzer-ioperation.
The text was updated successfully, but these errors were encountered: