diff --git a/src/Compilers/CSharp/Portable/BoundTree/Expression.cs b/src/Compilers/CSharp/Portable/BoundTree/Expression.cs index 59738533272460c4bed4f9e60bf6637805184307..7283f4640b5ab498a9b13d1f3dd7c9a0d5339d4e 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/Expression.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/Expression.cs @@ -119,16 +119,11 @@ internal static IArgument CreateArgumentOperation(ArgumentKind kind, IParameterS //TODO: https://github.com/dotnet/roslyn/issues/18722 // Right now, for erroneous code, we exposes all expression in place of arguments as IArgument with Parameter set to null, // so user needs to check IsInvalid first before using anything we returned. Need to implement a new interface for invalid invocation instead. - if (n.HasErrors || optionalParametersMethod == null) + if (n.HasErrors || (object)optionalParametersMethod == null) { // optionalParametersMethod can be null if we are writing to a readonly indexer or reading from an writeonly indexer, // in which case HasErrors property would be true, but we still want to treat this as invalid invocation. - ArrayBuilder argumentsWithErrors = ArrayBuilder.GetInstance(boundArguments.Length); - for (int a = 0; a < boundArguments.Length; ++a) - { - argumentsWithErrors.Add(CreateArgumentOperation(ArgumentKind.Explicit, null, boundArguments[a])); - } - return argumentsWithErrors.ToImmutableAndFree(); + return boundArguments.SelectAsArray(arg => CreateArgumentOperation(ArgumentKind.Explicit, null, arg)); } return LocalRewriter.MakeArgumentsInEvaluationOrder( diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs index 955f5c060451736edee7fee50a1954245c85df9e..65f80c694c8a8d8bf1098d8d6196aee3c25eefad 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs @@ -391,7 +391,7 @@ private static bool IsSafeForReordering(BoundExpression expression, RefKind kind ArrayBuilder temporariesBuilder = ArrayBuilder.GetInstance(); rewrittenArguments = _factory.MakeTempsForDiscardArguments(rewrittenArguments, temporariesBuilder); - if (CanSkipRewriting(ref rewrittenArguments, methodOrIndexer, expanded, argsToParamsOpt, invokedAsExtensionMethod, out var isComReceiver)) + if (CanSkipRewriting(rewrittenArguments, methodOrIndexer, expanded, argsToParamsOpt, invokedAsExtensionMethod, out var isComReceiver)) { temps = temporariesBuilder.ToImmutableAndFree(); return rewrittenArguments; @@ -519,9 +519,7 @@ private static bool IsSafeForReordering(BoundExpression expression, RefKind kind ArrayBuilder argumentsInEvaluationBuilder = ArrayBuilder.GetInstance(parameters.Length); - bool canSkipRewriting = CanSkipRewriting(ref arguments, methodOrIndexer, expanded, argsToParamsOpt, invokedAsExtensionMethod, out var isComReceiver); - - if (canSkipRewriting) + if (CanSkipRewriting(arguments, methodOrIndexer, expanded, argsToParamsOpt, invokedAsExtensionMethod, out var isComReceiver)) { // In this case, the invocation is not in expanded form and there's no named argument provided. // So we just return list of arguments as is. @@ -529,7 +527,7 @@ private static bool IsSafeForReordering(BoundExpression expression, RefKind kind { argumentsInEvaluationBuilder.Add(BoundCall.CreateArgumentOperation(ArgumentKind.Explicit, parameters[i], arguments[i])); } - return argumentsInEvaluationBuilder.ToImmutableAndFree(); ; + return argumentsInEvaluationBuilder.ToImmutableAndFree(); } ArrayBuilder missingParametersBuilder = ArrayBuilder.GetInstance(parameters.Length); @@ -551,7 +549,7 @@ private static bool IsSafeForReordering(BoundExpression expression, RefKind kind // temporariesBuilder will be null when factory is null. private static bool CanSkipRewriting( - ref ImmutableArray rewrittenArguments, + ImmutableArray rewrittenArguments, Symbol methodOrIndexer, bool expanded, ImmutableArray argsToParamsOpt, @@ -701,10 +699,7 @@ private static ImmutableArray GetRefKindsOrNull(ArrayBuilder r // Set loop variable so the value for next iteration will be the index of the first non param-array argument after param-array argument(s). a = firstNonParamArrayArgumentIndex - 1; - var paramArrayType = parameters[p].Type; - var arrayArgs = paramArray.ToImmutableAndFree(); - - argument = CreateParamArrayArgument(syntax, paramArrayType, arrayArgs, null, binder); + argument = CreateParamArrayArgument(syntax, parameter.Type, paramArray.ToImmutableAndFree(), null, binder); } argumentsBuilder.Add(BoundCall.CreateArgumentOperation(kind, parameter, argument)); diff --git a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IArgument.cs b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IArgument.cs index fb74de5f8bad3d8cb47f6386322cb7af9be501ea..f806d06f450b72d1b98f05b215f8c88eac659d3b 100644 --- a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IArgument.cs +++ b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IArgument.cs @@ -850,7 +850,7 @@ class P } [Fact] - public void CallerInfoAttributesInvokedInFieldInitilizer() + public void CallerInfoAttributesInvokedInFieldInitializer() { string source = @" using System.Runtime.CompilerServices; diff --git a/src/Compilers/Test/Utilities/CSharp/SemanticModelTestBase.cs b/src/Compilers/Test/Utilities/CSharp/SemanticModelTestBase.cs index c3739daccc9460aa2898f1f2b11c10cb00deca27..80abf4a6c392d4ba345cc839de91b9a5cffdf184 100644 --- a/src/Compilers/Test/Utilities/CSharp/SemanticModelTestBase.cs +++ b/src/Compilers/Test/Utilities/CSharp/SemanticModelTestBase.cs @@ -302,7 +302,7 @@ protected void VerifyOperationTreeAndDiagnosticsForTest(CSharpCompi CSharpParseOptions parseOptions = null, MetadataReference[] additionalReferences = null, Action AdditionalOperationTreeVerifier = null) - where TSyntaxNode : SyntaxNode + where TSyntaxNode : SyntaxNode { var ilReference = CreateMetadataReferenceFromIlSource(ilSource); VerifyOperationTreeAndDiagnosticsForTest(testSrc, expectedOperationTree, expectedDiagnostics, compilationOptions, parseOptions, new[] { ilReference }, AdditionalOperationTreeVerifier);