@@ -203,6 +203,114 @@ public static void Main()
203203 Diagnostic ( ErrorCode . ERR_BadCallerArgumentExpressionParamWithoutDefaultValue , "CallerArgumentExpression" ) . WithLocation ( 29 , 22 ) ) ;
204204 }
205205
206+ [ ConditionalFact ( typeof ( CoreClrOnly ) ) ]
207+ public void TestEndInvoke3 ( )
208+ {
209+ string source = @"
210+ using System.Runtime.CompilerServices;
211+
212+ namespace System.Runtime.InteropServices
213+ {
214+ [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
215+ public sealed class OptionalAttribute : Attribute
216+ {
217+ public OptionalAttribute()
218+ {
219+ }
220+ }
221+
222+ [AttributeUsage(AttributeTargets.Parameter)]
223+ public sealed class DefaultParameterValueAttribute : Attribute
224+ {
225+ public DefaultParameterValueAttribute(object value)
226+ {
227+ Value = value;
228+ }
229+ public object Value { get; }
230+ }
231+ }
232+
233+ class Program
234+ {
235+ const string s1 = nameof(s1);
236+ delegate void D(string s1, [CallerArgumentExpression(s1)] ref string s2 = ""default"");
237+
238+ static void M(string s1, ref string s2)
239+ {
240+ }
241+
242+ public static void Main()
243+ {
244+ D d = M;
245+ string s = string.Empty;
246+ d.EndInvoke(ref s, null);
247+ }
248+ }
249+ " ;
250+
251+ var compilation = CreateCompilation ( source , targetFramework : TargetFramework . NetCoreApp , options : TestOptions . ReleaseExe , parseOptions : TestOptions . RegularPreview ) ;
252+ compilation . VerifyDiagnostics (
253+ // (28,33): error CS9006: The CallerArgumentExpressionAttribute may only be applied to parameters with default values
254+ // delegate void D(string s1, [CallerArgumentExpression(s1)] ref string s2 = "default");
255+ Diagnostic ( ErrorCode . ERR_BadCallerArgumentExpressionParamWithoutDefaultValue , "CallerArgumentExpression" ) . WithLocation ( 28 , 33 ) ,
256+ // (28,63): error CS1741: A ref or out parameter cannot have a default value
257+ // delegate void D(string s1, [CallerArgumentExpression(s1)] ref string s2 = "default");
258+ Diagnostic ( ErrorCode . ERR_RefOutDefaultValue , "ref" ) . WithLocation ( 28 , 63 ) ) ;
259+ }
260+
261+ [ ConditionalFact ( typeof ( CoreClrOnly ) ) ]
262+ public void TestEndInvoke4 ( )
263+ {
264+ string source = @"
265+ using System.Runtime.CompilerServices;
266+ using System.Runtime.InteropServices;
267+
268+ namespace System.Runtime.InteropServices
269+ {
270+ [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
271+ public sealed class OptionalAttribute : Attribute
272+ {
273+ public OptionalAttribute()
274+ {
275+ }
276+ }
277+
278+ [AttributeUsage(AttributeTargets.Parameter)]
279+ public sealed class DefaultParameterValueAttribute : Attribute
280+ {
281+ public DefaultParameterValueAttribute(object value)
282+ {
283+ Value = value;
284+ }
285+ public object Value { get; }
286+ }
287+ }
288+
289+ class Program
290+ {
291+ const string s1 = nameof(s1);
292+ delegate void D(string s1, [CallerArgumentExpression(s1)] [Optional] [DefaultParameterValue(""default"")] ref string s2);
293+
294+ static void M(string s1, ref string s2)
295+ {
296+ }
297+
298+ public static void Main()
299+ {
300+ D d = M;
301+ string s = string.Empty;
302+ d.EndInvoke(ref s, null);
303+ }
304+ }
305+ " ;
306+
307+ var compilation = CreateCompilation ( source , targetFramework : TargetFramework . NetCoreApp , options : TestOptions . ReleaseExe , parseOptions : TestOptions . RegularPreview ) ;
308+ compilation . VerifyDiagnostics (
309+ // (29,33): error CS9006: The CallerArgumentExpressionAttribute may only be applied to parameters with default values
310+ // delegate void D(string s1, [CallerArgumentExpression(s1)] [Optional] [DefaultParameterValue("default")] ref string s2);
311+ Diagnostic ( ErrorCode . ERR_BadCallerArgumentExpressionParamWithoutDefaultValue , "CallerArgumentExpression" ) . WithLocation ( 29 , 33 ) ) ;
312+ }
313+
206314 [ ConditionalFact ( typeof ( CoreClrOnly ) ) ]
207315 public void TestBeginInvoke_ReferringToCallbackParameter ( )
208316 {
0 commit comments