提交 92922112 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #18431 from CyrusNajmabadi/useThrowExplicitConversion

Don't offer 'use throw expression' when there is an explicit cast in source.  It may change semantics.
......@@ -324,6 +324,40 @@ void Foo()
_s = s;
};
}
}");
}
[WorkItem(404142, "https://devdiv.visualstudio.com/DevDiv/_workitems?id=404142")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseThrowExpression)]
public async Task TestNotWithAsCheck()
{
await TestMissingInRegularAndScriptAsync(
@"using System;
class BswParser3
{
private ParserSyntax m_syntax;
public BswParser3(ISyntax syntax)
{
if (syntax == null)
{
[|throw|] new ArgumentNullException(nameof(syntax));
}
m_syntax = syntax as ParserSyntax;
if (m_syntax == null)
throw new ArgumentException();
}
}
internal class ParserSyntax
{
}
public interface ISyntax
{
}");
}
}
......
......@@ -233,8 +233,7 @@ private void AnalyzeOperation(OperationAnalysisContext context, INamedTypeSymbol
localOrParameter = null;
var condition = ifStatement.Condition;
var binaryOperator = condition as IBinaryOperatorExpression;
if (binaryOperator == null)
if (!(condition is IBinaryOperatorExpression binaryOperator))
{
return false;
}
......@@ -262,21 +261,18 @@ private void AnalyzeOperation(OperationAnalysisContext context, INamedTypeSymbol
private bool TryGetLocalOrParameterSymbol(
IOperation operation, out ISymbol localOrParameter)
{
if (operation.Kind == OperationKind.ConversionExpression)
if (operation is IConversionExpression conversion && !conversion.IsExplicit)
{
var conversionExpression = (IConversionExpression)operation;
return TryGetLocalOrParameterSymbol(
conversionExpression.Operand, out localOrParameter);
return TryGetLocalOrParameterSymbol(conversion.Operand, out localOrParameter);
}
if (operation.Kind == OperationKind.LocalReferenceExpression)
else if (operation is ILocalReferenceExpression localReference)
{
localOrParameter = ((ILocalReferenceExpression)operation).Local;
localOrParameter = localReference.Local;
return true;
}
else if (operation.Kind == OperationKind.ParameterReferenceExpression)
else if (operation is IParameterReferenceExpression parameterReference)
{
localOrParameter = ((IParameterReferenceExpression)operation).Parameter;
localOrParameter = parameterReference.Parameter;
return true;
}
......
......@@ -50,4 +50,4 @@ public void TestLinkedFileSet(string startText, List<string> updatedTexts, strin
}
}
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册