@@ -64,6 +64,30 @@ private int GetActualArgumentCount()
6464 return FirstOptionalArgumentIndex ;
6565 }
6666
67+ public string [ ] GetArgumentNames ( int skipCount = 0 )
68+ {
69+ string [ ] argumentNames = ArgumentNames ;
70+ if ( AddNamesToPrimitiveValues && IsPrimitiveValue . Any ( ) && ! IsExpandedForm
71+ && ! ParameterNames . Any ( string . IsNullOrEmpty ) )
72+ {
73+ Debug . Assert ( skipCount == 0 ) ;
74+ if ( argumentNames == null )
75+ {
76+ argumentNames = new string [ Arguments . Length ] ;
77+ }
78+
79+ for ( int i = 0 ; i < Arguments . Length ; i ++ )
80+ {
81+ if ( IsPrimitiveValue [ i ] && argumentNames [ i ] == null )
82+ {
83+ argumentNames [ i ] = ParameterNames [ i ] ;
84+ }
85+ }
86+ }
87+
88+ return argumentNames ;
89+ }
90+
6791 public IList < ResolveResult > GetArgumentResolveResults ( int skipCount = 0 )
6892 {
6993 var expectedParameters = ExpectedParameters ;
@@ -95,33 +119,17 @@ public IList<ResolveResult> GetArgumentResolveResultsDirect(int skipCount = 0)
95119
96120 public IEnumerable < Expression > GetArgumentExpressions ( int skipCount = 0 )
97121 {
98- if ( AddNamesToPrimitiveValues && IsPrimitiveValue . Any ( ) && ! IsExpandedForm
99- && ! ParameterNames . Any ( p => string . IsNullOrEmpty ( p ) ) )
100- {
101- Debug . Assert ( skipCount == 0 ) ;
102- if ( ArgumentNames == null )
103- {
104- ArgumentNames = new string [ Arguments . Length ] ;
105- }
106-
107- for ( int i = 0 ; i < Arguments . Length ; i ++ )
108- {
109- if ( IsPrimitiveValue [ i ] && ArgumentNames [ i ] == null )
110- {
111- ArgumentNames [ i ] = ParameterNames [ i ] ;
112- }
113- }
114- }
122+ var argumentNames = GetArgumentNames ( skipCount ) ;
115123 int argumentCount = GetActualArgumentCount ( ) ;
116124 var useImplicitlyTypedOut = UseImplicitlyTypedOut ;
117- if ( ArgumentNames == null )
125+ if ( argumentNames == null )
118126 {
119127 return Arguments . Skip ( skipCount ) . Take ( argumentCount ) . Select ( arg => AddAnnotations ( arg . Expression ) ) ;
120128 }
121129 else
122130 {
123131 Debug . Assert ( skipCount == 0 ) ;
124- return Arguments . Take ( argumentCount ) . Zip ( ArgumentNames . Take ( argumentCount ) ,
132+ return Arguments . Take ( argumentCount ) . Zip ( argumentNames . Take ( argumentCount ) ,
125133 ( arg , name ) => {
126134 if ( name == null )
127135 return AddAnnotations ( arg . Expression ) ;
@@ -531,6 +539,10 @@ public ExpressionWithResolveResult Build(OpCode callOpCode, IMethod method,
531539 Expression targetExpr ;
532540 string methodName = method . Name ;
533541 AstNodeCollection < AstType > typeArgumentList ;
542+ if ( ( transform & CallTransformation . NoNamedArgsForPrettiness ) != 0 )
543+ {
544+ argumentList . AddNamesToPrimitiveValues = false ;
545+ }
534546 if ( ( transform & CallTransformation . NoOptionalArgumentAllowed ) != 0 )
535547 {
536548 argumentList . FirstOptionalArgumentIndex = - 1 ;
@@ -674,7 +686,7 @@ public ExpressionWithResolveResult BuildCollectionInitializerExpression(OpCode c
674686 argumentList . UseImplicitlyTypedOut = false ;
675687 var transform = GetRequiredTransformationsForCall ( expectedTargetDetails , method , ref unused ,
676688 ref argumentList , CallTransformation . None , out _ ) ;
677- Debug . Assert ( transform == CallTransformation . None || transform == CallTransformation . NoOptionalArgumentAllowed ) ;
689+ Debug . Assert ( ( transform & ~ ( CallTransformation . NoOptionalArgumentAllowed | CallTransformation . NoNamedArgsForPrettiness ) ) == 0 ) ;
678690
679691 // Calls with only one argument do not need an array initializer expression to wrap them.
680692 // Any special cases are handled by the caller (i.e., ExpressionBuilder.TranslateObjectAndCollectionInitializer)
@@ -1121,7 +1133,8 @@ enum CallTransformation
11211133 /// Add calls to AsRefReadOnly for in parameters that did not have an explicit DirectionExpression yet.
11221134 /// </summary>
11231135 EnforceExplicitIn = 8 ,
1124- All = 0xf ,
1136+ NoNamedArgsForPrettiness = 0x10 ,
1137+ All = 0x1f ,
11251138 }
11261139
11271140 private CallTransformation GetRequiredTransformationsForCall ( ExpectedTargetDetails expectedTargetDetails , IMethod method ,
@@ -1198,7 +1211,7 @@ private CallTransformation GetRequiredTransformationsForCall(ExpectedTargetDetai
11981211 bool skipTargetCast = method . Accessibility <= Accessibility . Protected && expressionBuilder . IsBaseTypeOfCurrentType ( method . DeclaringTypeDefinition ) ;
11991212 OverloadResolutionErrors errors ;
12001213 while ( ( errors = IsUnambiguousCall ( expectedTargetDetails , method , targetResolveResult , typeArguments ,
1201- argumentList . GetArgumentResolveResults ( ) . ToArray ( ) , argumentList . ArgumentNames , argumentList . FirstOptionalArgumentIndex , out foundMethod ,
1214+ argumentList . GetArgumentResolveResults ( ) . ToArray ( ) , argumentList . GetArgumentNames ( ) , argumentList . FirstOptionalArgumentIndex , out foundMethod ,
12021215 out var bestCandidateIsExpandedForm ) ) != OverloadResolutionErrors . None || bestCandidateIsExpandedForm != argumentList . IsExpandedForm )
12031216 {
12041217 switch ( errors )
@@ -1228,7 +1241,11 @@ private CallTransformation GetRequiredTransformationsForCall(ExpectedTargetDetai
12281241 default :
12291242 // TODO : implement some more intelligent algorithm that decides which of these fixes (cast args, add target, cast target, add type args)
12301243 // is best in this case. Additionally we should not cast all arguments at once, but step-by-step try to add only a minimal number of casts.
1231- if ( argumentList . FirstOptionalArgumentIndex >= 0 )
1244+ if ( argumentList . AddNamesToPrimitiveValues )
1245+ {
1246+ argumentList . AddNamesToPrimitiveValues = false ;
1247+ }
1248+ else if ( argumentList . FirstOptionalArgumentIndex >= 0 )
12321249 {
12331250 argumentList . FirstOptionalArgumentIndex = - 1 ;
12341251 }
@@ -1293,6 +1310,8 @@ private CallTransformation GetRequiredTransformationsForCall(ExpectedTargetDetai
12931310 transform |= CallTransformation . RequireTypeArguments ;
12941311 if ( argumentList . FirstOptionalArgumentIndex < 0 )
12951312 transform |= CallTransformation . NoOptionalArgumentAllowed ;
1313+ if ( ! argumentList . AddNamesToPrimitiveValues )
1314+ transform |= CallTransformation . NoNamedArgsForPrettiness ;
12961315 return transform ;
12971316 }
12981317
@@ -1438,7 +1457,7 @@ private ExpressionWithResolveResult HandleImplicitConversion(IMethod method, Tra
14381457 var conversions = CSharpConversions . Get ( expressionBuilder . compilation ) ;
14391458 IType targetType = method . ReturnType ;
14401459 var conv = conversions . ImplicitConversion ( argument . Type , targetType ) ;
1441- if ( ! ( conv . IsUserDefined && conv . IsValid && conv . Method . Equals ( method ) ) )
1460+ if ( ! ( conv . IsUserDefined && conv . IsValid && conv . Method . Equals ( method , NormalizeTypeVisitor . TypeErasure ) ) )
14421461 {
14431462 // implicit conversion to targetType isn't directly possible, so first insert a cast to the argument type
14441463 argument = argument . ConvertTo ( method . Parameters [ 0 ] . Type , expressionBuilder ) ;
@@ -1766,9 +1785,14 @@ ExpressionWithResolveResult HandleConstructorCall(ExpectedTargetDetails expected
17661785 {
17671786 while ( IsUnambiguousCall ( expectedTargetDetails , method , null , Empty < IType > . Array ,
17681787 argumentList . GetArgumentResolveResults ( ) . ToArray ( ) ,
1769- argumentList . ArgumentNames , argumentList . FirstOptionalArgumentIndex , out _ ,
1788+ argumentList . GetArgumentNames ( ) , argumentList . FirstOptionalArgumentIndex , out _ ,
17701789 out var bestCandidateIsExpandedForm ) != OverloadResolutionErrors . None || bestCandidateIsExpandedForm != argumentList . IsExpandedForm )
17711790 {
1791+ if ( argumentList . AddNamesToPrimitiveValues )
1792+ {
1793+ argumentList . AddNamesToPrimitiveValues = false ;
1794+ continue ;
1795+ }
17721796 if ( argumentList . FirstOptionalArgumentIndex >= 0 )
17731797 {
17741798 argumentList . FirstOptionalArgumentIndex = - 1 ;
0 commit comments