提交 5d36b856 编写于 作者: M Martin Strecker

Removed check for NullLiteralExpression

上级 1e444cfd
......@@ -3913,5 +3913,28 @@ static void Main(dynamic p)
}
}");
}
[WorkItem(18978, "https://github.com/dotnet/roslyn/issues/18978")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryCast)]
public async Task DontRemoveCastCallToMethodWithParamsArgs()
{
await TestMissingInRegularAndScriptAsync(
@"
class Program
{
public static void Main(string[] args)
{
var takesArgs = new[] { ""Hello"", ""World"" };
TakesParams(takesArgs);
TakesParams([|(object)takesArgs|]);
}
private static void TakesParams(params object[] foo)
{
Console.WriteLine(foo.Length);
}
}");
}
}
}
\ No newline at end of file
......@@ -161,43 +161,40 @@ private static bool UserDefinedConversionIsAllowed(ExpressionSyntax expression,
//
// Foo((object)null);
if (cast.Expression.WalkDownParentheses().IsKind(SyntaxKind.NullLiteralExpression))
var argument = cast.WalkUpParentheses().Parent as ArgumentSyntax;
if (argument != null)
{
var argument = cast.WalkUpParentheses().Parent as ArgumentSyntax;
if (argument != null)
// If there are any arguments to the right, we can assume that this is not a
// *single* argument passed to a params parameter.
var argumentList = argument.Parent as BaseArgumentListSyntax;
if (argumentList != null)
{
// If there are any arguments to the right, we can assume that this is not a
// *single* argument passed to a params parameter.
var argumentList = argument.Parent as BaseArgumentListSyntax;
if (argumentList != null)
var argumentIndex = argumentList.Arguments.IndexOf(argument);
if (argumentIndex < argumentList.Arguments.Count - 1)
{
var argumentIndex = argumentList.Arguments.IndexOf(argument);
if (argumentIndex < argumentList.Arguments.Count - 1)
{
return false;
}
return false;
}
}
var parameter = argument.DetermineParameter(semanticModel, cancellationToken: cancellationToken);
if (parameter != null && parameter.IsParams)
{
Debug.Assert(parameter.Type is IArrayTypeSymbol);
var parameter = argument.DetermineParameter(semanticModel, cancellationToken: cancellationToken);
if (parameter != null && parameter.IsParams)
{
Debug.Assert(parameter.Type is IArrayTypeSymbol);
var parameterType = (IArrayTypeSymbol)parameter.Type;
var parameterType = (IArrayTypeSymbol)parameter.Type;
var conversion = semanticModel.Compilation.ClassifyConversion(castType, parameterType);
if (conversion.Exists &&
conversion.IsImplicit)
{
return false;
}
var conversion = semanticModel.Compilation.ClassifyConversion(castType, parameterType);
if (conversion.Exists &&
conversion.IsImplicit)
{
return false;
}
var conversionElementType = semanticModel.Compilation.ClassifyConversion(castType, parameterType.ElementType);
if (conversionElementType.Exists &&
conversionElementType.IsImplicit)
{
return true;
}
var conversionElementType = semanticModel.Compilation.ClassifyConversion(castType, parameterType.ElementType);
if (conversionElementType.Exists &&
conversionElementType.IsImplicit)
{
return true;
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册