未验证 提交 d16a6fd5 编写于 作者: R Rikki Gibson 提交者: GitHub

Null-check conversion group nested in identity conversion (#41886)

上级 3e9fa6e3
......@@ -5770,8 +5770,8 @@ private static BoundConversion GetConversionIfApplicable(BoundExpression convers
// and that any warnings caught by this recursive call of VisitConversion won't be redundant.
if (useLegacyWarnings && conversionOperand is BoundConversion operandConversion && !operandConversion.ConversionKind.IsUserDefinedConversion())
{
var explicitType = operandConversion.ConversionGroupOpt.ExplicitType;
if (explicitType.Equals(targetTypeWithNullability, TypeCompareKind.ConsiderEverything))
var explicitType = operandConversion.ConversionGroupOpt?.ExplicitType;
if (explicitType?.Equals(targetTypeWithNullability, TypeCompareKind.ConsiderEverything) == true)
{
TrackAnalyzedNullabilityThroughConversionGroup(
calculateResultType(targetTypeWithNullability, fromExplicitCast, operandType.State, isSuppressed, targetType),
......
......@@ -51485,6 +51485,24 @@ static void Main(object? x)
comp.VerifyDiagnostics();
}
[Fact, WorkItem(41763, "https://github.com/dotnet/roslyn/issues/41763")]
public void Conversions_EnumToUnderlyingType_SemanticModel()
{
var source = @"
enum E
{
A = 1,
B = (int)A
}";
var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue());
var tree = comp.SyntaxTrees.Single();
var model = comp.GetSemanticModel(tree);
comp.VerifyDiagnostics();
var node = tree.GetRoot().DescendantNodes().OfType<EnumMemberDeclarationSyntax>().ElementAt(1);
model.GetSymbolInfo(node.EqualsValue.Value);
}
[Fact]
public void IdentityConversion_LocalDeclaration()
{
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册