From: Stephen Toub Date: Tue, 27 Jul 2021 10:40:25 +0000 (-0400) Subject: Update compiler version to enable CallerArgumentExpression (#56349) X-Git-Tag: accepted/tizen/unified/20220110.054933~896 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b9e3c72ead567bbf02367aaddd4ecc9d4e172c8a;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Update compiler version to enable CallerArgumentExpression (#56349) --- diff --git a/eng/Versions.props b/eng/Versions.props index aaa7ff9..2739d99 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -17,8 +17,8 @@ release true - - 4.0.0-3.21367.2 + + 4.0.0-3.21376.12 true false false diff --git a/src/libraries/System.Net.WebClient/src/System/Net/WebClient.cs b/src/libraries/System.Net.WebClient/src/System/Net/WebClient.cs index 553bf48..d23488f 100644 --- a/src/libraries/System.Net.WebClient/src/System/Net/WebClient.cs +++ b/src/libraries/System.Net.WebClient/src/System/Net/WebClient.cs @@ -143,7 +143,7 @@ namespace System.Net get { return _encoding; } set { - ArgumentNullException.ThrowIfNull(value, nameof(value)); + ArgumentNullException.ThrowIfNull(value); _encoding = value; } } @@ -280,7 +280,7 @@ namespace System.Net public byte[] DownloadData(Uri address) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); + ArgumentNullException.ThrowIfNull(address); StartOperation(); try @@ -320,8 +320,8 @@ namespace System.Net public void DownloadFile(Uri address, string fileName) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); - ArgumentNullException.ThrowIfNull(fileName, nameof(fileName)); + ArgumentNullException.ThrowIfNull(address); + ArgumentNullException.ThrowIfNull(fileName); WebRequest? request = null; FileStream? fs = null; @@ -359,7 +359,7 @@ namespace System.Net public Stream OpenRead(Uri address) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); + ArgumentNullException.ThrowIfNull(address); WebRequest? request = null; StartOperation(); @@ -392,7 +392,7 @@ namespace System.Net public Stream OpenWrite(Uri address, string? method) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); + ArgumentNullException.ThrowIfNull(address); if (method == null) { method = MapToDefaultMethod(address); @@ -432,8 +432,8 @@ namespace System.Net public byte[] UploadData(Uri address, string? method, byte[] data) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); - ArgumentNullException.ThrowIfNull(data, nameof(data)); + ArgumentNullException.ThrowIfNull(address); + ArgumentNullException.ThrowIfNull(data); if (method == null) { method = MapToDefaultMethod(address); @@ -553,8 +553,8 @@ namespace System.Net public byte[] UploadFile(Uri address, string? method, string fileName) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); - ArgumentNullException.ThrowIfNull(fileName, nameof(fileName)); + ArgumentNullException.ThrowIfNull(address); + ArgumentNullException.ThrowIfNull(fileName); if (method == null) { method = MapToDefaultMethod(address); @@ -626,8 +626,8 @@ namespace System.Net public byte[] UploadValues(Uri address, string? method, NameValueCollection data) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); - ArgumentNullException.ThrowIfNull(data, nameof(data)); + ArgumentNullException.ThrowIfNull(address); + ArgumentNullException.ThrowIfNull(data); if (method == null) { method = MapToDefaultMethod(address); @@ -665,8 +665,8 @@ namespace System.Net public string UploadString(Uri address, string? method, string data) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); - ArgumentNullException.ThrowIfNull(data, nameof(data)); + ArgumentNullException.ThrowIfNull(address); + ArgumentNullException.ThrowIfNull(data); if (method == null) { method = MapToDefaultMethod(address); @@ -691,7 +691,7 @@ namespace System.Net public string DownloadString(Uri address) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); + ArgumentNullException.ThrowIfNull(address); StartOperation(); try @@ -781,7 +781,7 @@ namespace System.Net private Uri GetUri(string address) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); + ArgumentNullException.ThrowIfNull(address); Uri? uri; if (_baseAddress != null) @@ -801,7 +801,7 @@ namespace System.Net private Uri GetUri(Uri address) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); + ArgumentNullException.ThrowIfNull(address); Uri? uri = address; @@ -1297,7 +1297,7 @@ namespace System.Net public void OpenReadAsync(Uri address, object? userToken) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); + ArgumentNullException.ThrowIfNull(address); AsyncOperation asyncOp = StartAsyncOperation(userToken); try @@ -1335,7 +1335,7 @@ namespace System.Net public void OpenWriteAsync(Uri address, string? method, object? userToken) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); + ArgumentNullException.ThrowIfNull(address); if (method == null) { method = MapToDefaultMethod(address); @@ -1396,7 +1396,7 @@ namespace System.Net public void DownloadStringAsync(Uri address, object? userToken) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); + ArgumentNullException.ThrowIfNull(address); AsyncOperation asyncOp = StartAsyncOperation(userToken); try @@ -1422,7 +1422,7 @@ namespace System.Net public void DownloadDataAsync(Uri address, object? userToken) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); + ArgumentNullException.ThrowIfNull(address); AsyncOperation asyncOp = StartAsyncOperation(userToken); try @@ -1448,8 +1448,8 @@ namespace System.Net public void DownloadFileAsync(Uri address, string fileName, object? userToken) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); - ArgumentNullException.ThrowIfNull(fileName, nameof(fileName)); + ArgumentNullException.ThrowIfNull(address); + ArgumentNullException.ThrowIfNull(fileName); FileStream? fs = null; AsyncOperation asyncOp = StartAsyncOperation(userToken); @@ -1474,8 +1474,8 @@ namespace System.Net public void UploadStringAsync(Uri address, string? method, string data, object? userToken) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); - ArgumentNullException.ThrowIfNull(data, nameof(data)); + ArgumentNullException.ThrowIfNull(address); + ArgumentNullException.ThrowIfNull(data); if (method == null) { method = MapToDefaultMethod(address); @@ -1525,8 +1525,8 @@ namespace System.Net public void UploadDataAsync(Uri address, string? method, byte[] data, object? userToken) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); - ArgumentNullException.ThrowIfNull(data, nameof(data)); + ArgumentNullException.ThrowIfNull(address); + ArgumentNullException.ThrowIfNull(data); if (method == null) { method = MapToDefaultMethod(address); @@ -1566,8 +1566,8 @@ namespace System.Net public void UploadFileAsync(Uri address, string? method, string fileName, object? userToken) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); - ArgumentNullException.ThrowIfNull(fileName, nameof(fileName)); + ArgumentNullException.ThrowIfNull(address); + ArgumentNullException.ThrowIfNull(fileName); if (method == null) { method = MapToDefaultMethod(address); @@ -1605,8 +1605,8 @@ namespace System.Net public void UploadValuesAsync(Uri address, string? method, NameValueCollection data, object? userToken) { - ArgumentNullException.ThrowIfNull(address, nameof(address)); - ArgumentNullException.ThrowIfNull(data, nameof(data)); + ArgumentNullException.ThrowIfNull(address); + ArgumentNullException.ThrowIfNull(data); if (method == null) { method = MapToDefaultMethod(address); diff --git a/src/libraries/System.Reflection.TypeExtensions/src/System/Reflection/TypeExtensions.cs b/src/libraries/System.Reflection.TypeExtensions/src/System/Reflection/TypeExtensions.cs index 6c020bb..f931cbe 100644 --- a/src/libraries/System.Reflection.TypeExtensions/src/System/Reflection/TypeExtensions.cs +++ b/src/libraries/System.Reflection.TypeExtensions/src/System/Reflection/TypeExtensions.cs @@ -11,14 +11,14 @@ namespace System.Reflection [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] this Type type, Type[] types) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetConstructor(types); } public static ConstructorInfo[] GetConstructors( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] this Type type) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetConstructors(); } @@ -26,7 +26,7 @@ namespace System.Reflection [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] this Type type, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetConstructors(bindingAttr); } @@ -39,7 +39,7 @@ namespace System.Reflection | DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicNestedTypes)] this Type type) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetDefaultMembers(); } @@ -47,7 +47,7 @@ namespace System.Reflection [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicEvents)] this Type type, string name) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetEvent(name); } @@ -56,14 +56,14 @@ namespace System.Reflection string name, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetEvent(name, bindingAttr); } public static EventInfo[] GetEvents( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicEvents)] this Type type) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetEvents(); } @@ -71,7 +71,7 @@ namespace System.Reflection [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicEvents | DynamicallyAccessedMemberTypes.NonPublicEvents)] this Type type, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetEvents(bindingAttr); } @@ -79,7 +79,7 @@ namespace System.Reflection [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] this Type type, string name) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetField(name); } @@ -88,14 +88,14 @@ namespace System.Reflection string name, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetField(name, bindingAttr); } public static FieldInfo[] GetFields( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] this Type type) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetFields(); } @@ -103,20 +103,20 @@ namespace System.Reflection [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] this Type type, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetFields(bindingAttr); } public static Type[] GetGenericArguments(this Type type) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetGenericArguments(); } public static Type[] GetInterfaces( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] this Type type) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetInterfaces(); } @@ -130,7 +130,7 @@ namespace System.Reflection | DynamicallyAccessedMemberTypes.PublicNestedTypes)] this Type type, string name) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetMember(name); } @@ -139,7 +139,7 @@ namespace System.Reflection string name, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetMember(name, bindingAttr); } @@ -152,7 +152,7 @@ namespace System.Reflection | DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicNestedTypes)] this Type type) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetMembers(); } @@ -160,7 +160,7 @@ namespace System.Reflection [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] this Type type, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetMembers(bindingAttr); } @@ -168,7 +168,7 @@ namespace System.Reflection [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] this Type type, string name) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetMethod(name); } @@ -177,7 +177,7 @@ namespace System.Reflection string name, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetMethod(name, bindingAttr); } @@ -186,14 +186,14 @@ namespace System.Reflection string name, Type[] types) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetMethod(name, types); } public static MethodInfo[] GetMethods( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] this Type type) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetMethods(); } @@ -201,7 +201,7 @@ namespace System.Reflection [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] this Type type, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetMethods(bindingAttr); } @@ -210,7 +210,7 @@ namespace System.Reflection string name, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetNestedType(name, bindingAttr); } @@ -218,14 +218,14 @@ namespace System.Reflection [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicNestedTypes | DynamicallyAccessedMemberTypes.NonPublicNestedTypes)] this Type type, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetNestedTypes(bindingAttr); } public static PropertyInfo[] GetProperties( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] this Type type) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetProperties(); } @@ -233,7 +233,7 @@ namespace System.Reflection [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] this Type type, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetProperties(bindingAttr); } @@ -241,7 +241,7 @@ namespace System.Reflection [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] this Type type, string name) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetProperty(name); } @@ -250,7 +250,7 @@ namespace System.Reflection string name, BindingFlags bindingAttr) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetProperty(name, bindingAttr); } @@ -259,7 +259,7 @@ namespace System.Reflection string name, Type? returnType) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetProperty(name, returnType); } @@ -269,19 +269,19 @@ namespace System.Reflection Type? returnType, Type[] types) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.GetProperty(name, returnType, types); } public static bool IsAssignableFrom(this Type type, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] Type? c) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.IsAssignableFrom(c); } public static bool IsInstanceOfType(this Type type, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? o) { - ArgumentNullException.ThrowIfNull(type, nameof(type)); + ArgumentNullException.ThrowIfNull(type); return type.IsInstanceOfType(o); } } @@ -291,20 +291,20 @@ namespace System.Reflection [RequiresUnreferencedCode("Types might be removed")] public static Type[] GetExportedTypes(this Assembly assembly) { - ArgumentNullException.ThrowIfNull(assembly, nameof(assembly)); + ArgumentNullException.ThrowIfNull(assembly); return assembly.GetExportedTypes(); } public static Module[] GetModules(this Assembly assembly) { - ArgumentNullException.ThrowIfNull(assembly, nameof(assembly)); + ArgumentNullException.ThrowIfNull(assembly); return assembly.GetModules(); } [RequiresUnreferencedCode("Types might be removed")] public static Type[] GetTypes(this Assembly assembly) { - ArgumentNullException.ThrowIfNull(assembly, nameof(assembly)); + ArgumentNullException.ThrowIfNull(assembly); return assembly.GetTypes(); } } @@ -313,37 +313,37 @@ namespace System.Reflection { public static MethodInfo? GetAddMethod(this EventInfo eventInfo) { - ArgumentNullException.ThrowIfNull(eventInfo, nameof(eventInfo)); + ArgumentNullException.ThrowIfNull(eventInfo); return eventInfo.GetAddMethod(); } public static MethodInfo? GetAddMethod(this EventInfo eventInfo, bool nonPublic) { - ArgumentNullException.ThrowIfNull(eventInfo, nameof(eventInfo)); + ArgumentNullException.ThrowIfNull(eventInfo); return eventInfo.GetAddMethod(nonPublic); } public static MethodInfo? GetRaiseMethod(this EventInfo eventInfo) { - ArgumentNullException.ThrowIfNull(eventInfo, nameof(eventInfo)); + ArgumentNullException.ThrowIfNull(eventInfo); return eventInfo.GetRaiseMethod(); } public static MethodInfo? GetRaiseMethod(this EventInfo eventInfo, bool nonPublic) { - ArgumentNullException.ThrowIfNull(eventInfo, nameof(eventInfo)); + ArgumentNullException.ThrowIfNull(eventInfo); return eventInfo.GetRaiseMethod(nonPublic); } public static MethodInfo? GetRemoveMethod(this EventInfo eventInfo) { - ArgumentNullException.ThrowIfNull(eventInfo, nameof(eventInfo)); + ArgumentNullException.ThrowIfNull(eventInfo); return eventInfo.GetRemoveMethod(); } public static MethodInfo? GetRemoveMethod(this EventInfo eventInfo, bool nonPublic) { - ArgumentNullException.ThrowIfNull(eventInfo, nameof(eventInfo)); + ArgumentNullException.ThrowIfNull(eventInfo); return eventInfo.GetRemoveMethod(nonPublic); } } @@ -358,7 +358,7 @@ namespace System.Reflection /// This maybe public static bool HasMetadataToken(this MemberInfo member) { - ArgumentNullException.ThrowIfNull(member, nameof(member)); + ArgumentNullException.ThrowIfNull(member); try { @@ -380,7 +380,7 @@ namespace System.Reflection /// public static int GetMetadataToken(this MemberInfo member) { - ArgumentNullException.ThrowIfNull(member, nameof(member)); + ArgumentNullException.ThrowIfNull(member); int token = GetMetadataTokenOrZeroOrThrow(member); @@ -413,7 +413,7 @@ namespace System.Reflection { public static MethodInfo GetBaseDefinition(this MethodInfo method) { - ArgumentNullException.ThrowIfNull(method, nameof(method)); + ArgumentNullException.ThrowIfNull(method); return method.GetBaseDefinition(); } } @@ -422,13 +422,13 @@ namespace System.Reflection { public static bool HasModuleVersionId(this Module module) { - ArgumentNullException.ThrowIfNull(module, nameof(module)); + ArgumentNullException.ThrowIfNull(module); return true; // not expected to fail on platforms with Module.ModuleVersionId built-in. } public static Guid GetModuleVersionId(this Module module) { - ArgumentNullException.ThrowIfNull(module, nameof(module)); + ArgumentNullException.ThrowIfNull(module); return module.ModuleVersionId; } } @@ -437,37 +437,37 @@ namespace System.Reflection { public static MethodInfo[] GetAccessors(this PropertyInfo property) { - ArgumentNullException.ThrowIfNull(property, nameof(property)); + ArgumentNullException.ThrowIfNull(property); return property.GetAccessors(); } public static MethodInfo[] GetAccessors(this PropertyInfo property, bool nonPublic) { - ArgumentNullException.ThrowIfNull(property, nameof(property)); + ArgumentNullException.ThrowIfNull(property); return property.GetAccessors(nonPublic); } public static MethodInfo? GetGetMethod(this PropertyInfo property) { - ArgumentNullException.ThrowIfNull(property, nameof(property)); + ArgumentNullException.ThrowIfNull(property); return property.GetGetMethod(); } public static MethodInfo? GetGetMethod(this PropertyInfo property, bool nonPublic) { - ArgumentNullException.ThrowIfNull(property, nameof(property)); + ArgumentNullException.ThrowIfNull(property); return property.GetGetMethod(nonPublic); } public static MethodInfo? GetSetMethod(this PropertyInfo property) { - ArgumentNullException.ThrowIfNull(property, nameof(property)); + ArgumentNullException.ThrowIfNull(property); return property.GetSetMethod(); } public static MethodInfo? GetSetMethod(this PropertyInfo property, bool nonPublic) { - ArgumentNullException.ThrowIfNull(property, nameof(property)); + ArgumentNullException.ThrowIfNull(property); return property.GetSetMethod(nonPublic); } } diff --git a/src/libraries/System.Runtime/tests/System/ArgumentNullExceptionTests.cs b/src/libraries/System.Runtime/tests/System/ArgumentNullExceptionTests.cs index 7838446..3a5e3ad 100644 --- a/src/libraries/System.Runtime/tests/System/ArgumentNullExceptionTests.cs +++ b/src/libraries/System.Runtime/tests/System/ArgumentNullExceptionTests.cs @@ -68,7 +68,6 @@ namespace System.Tests } [Fact] - [ActiveIssue("https://github.com/dotnet/csharplang/issues/287")] public static void ThrowIfNull_UsesArgumentExpression() { object something = null; diff --git a/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/CallerArgumentExpressionAttributeTests.cs b/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/CallerArgumentExpressionAttributeTests.cs index 975690e..f0a374e 100644 --- a/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/CallerArgumentExpressionAttributeTests.cs +++ b/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/CallerArgumentExpressionAttributeTests.cs @@ -7,204 +7,25 @@ namespace System.Runtime.CompilerServices.Tests { public static class CallerArgumentExpressionAttributeTests { - public static string IntParamMethod(int val, [CallerArgumentExpression("val")] string expr = null) + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData("paramName")] + public static void Ctor_ParameterName_Roundtrip(string value) { - return expr; - } - - [Theory, InlineData("testParamName"), InlineData(""), InlineData(null)] - public static void ArgumentToCallerArgumentExpressionSetsParameterNameProperty(string paramName) - { - var attr = new CallerArgumentExpressionAttribute(paramName); - - Assert.Equal(paramName, attr.ParameterName); - } - - [Fact] - public static void SuppliedArgumentOverridesExpression() - { - int notVal = 0; - - string suppliedVal = "supplied value"; - Assert.Equal(suppliedVal, IntParamMethod(notVal, suppliedVal)); - - Assert.Equal(IntParamMethod(notVal), IntParamMethodPassthrough(notVal)); - } - - private static string IntParamMethodPassthrough(int val, [CallerArgumentExpression("val")] string expr = null) - { - return IntParamMethod(val, expr); - } - - [Fact] - public static void InvalidParameterName() - { - int notVal = 0; - - Assert.Null(InvalidParameterNameMethod(notVal)); - } - - private static string InvalidParameterNameMethod(int val, [CallerArgumentExpression("notVal")] string expr = null) - { - return expr; - } - - [Fact] - public static void NullParameterName() - { - int notVal = 0; - - Assert.Null(NullParameterNameMethod(notVal)); - } - - private static string NullParameterNameMethod(int val, [CallerArgumentExpression(null)] string expr = null) - { - return expr; - } - - [Fact] - public static void OverloadedMethodPrecedence() - { - int notVal = 0; - - Assert.Equal(OverloadedMethodReturn, OverloadedMethod(notVal)); - } - - private const string OverloadedMethodReturn = "not CallerArgumentExpression"; - - private static string OverloadedMethod(int val) - { - return OverloadedMethodReturn; - } - - private static string OverloadedMethod(int val, [CallerArgumentExpression(null)] string expr = null) - { - return expr; - } - - [Fact] - [ActiveIssue("https://github.com/dotnet/roslyn/issues/19605")] - public static void SimpleExpression() - { - int notVal = 0; - - Assert.Equal("notVal", IntParamMethod(notVal)); - } - - [Fact] - [ActiveIssue("https://github.com/dotnet/roslyn/issues/19605")] - public static void ComplexExpression() - { - int x = 5; - - Assert.Equal("Math.Min(x + 20, x * x)", - IntParamMethod(Math.Min(x + 20, x * x))); - } - - [Fact] - [ActiveIssue("https://github.com/dotnet/roslyn/issues/19605")] - public static void SurroundingWhitespaceHandling() - { - int notVal = 0; - - Assert.Equal("notVal", IntParamMethod(notVal)); - } - - [Fact] - [ActiveIssue("https://github.com/dotnet/roslyn/issues/19605")] - public static void InternalWhitespaceHandling() - { - int notVal = 0; - - Assert.Equal("notVal + 20", IntParamMethod(notVal + 20)); - - Assert.Equal(@"Math.Min(notVal * 2, - notVal + 20)", - IntParamMethod(Math.Min(notVal * 2, - notVal + 20))); - } - - [Fact] - [ActiveIssue("https://github.com/dotnet/roslyn/issues/19605")] - public static void InternalCommentHandling() - { - int notVal = 0; - - Assert.Equal("notVal + /*comment*/20", IntParamMethod(notVal + /*comment*/20)); - Assert.Equal("notVal + 20 //comment", - IntParamMethod(notVal + 20 //comment - )); + var caea = new CallerArgumentExpressionAttribute(value); + Assert.Equal(value, caea.ParameterName); } [Fact] - [ActiveIssue("https://github.com/dotnet/roslyn/issues/19605")] - public static void OptionalParameterHandling() + public static void BasicTest() { - string suppliedVal = "supplied value"; - Assert.Equal("suppliedVal", OptionalParamMethod(suppliedVal)); - Assert.Equal("suppliedVal", OptionalParamMethod(val: suppliedVal)); - - Assert.Equal("StringConst + \" string literal\"", OptionalParamMethod()); - - Assert.Equal("\"no file\"", CompilerSuppliedParamMethod()); + // Just a quick test to validate basic behavior. Compiler tests validate it fully. + Assert.Equal("\"hello\"", GetValue("hello")); + Assert.Equal("3 + 2", GetValue(3 + 2)); + Assert.Equal("new object()", GetValue(new object())); } - private const string StringConst = "hello"; - - private static string OptionalParamMethod(string val = StringConst + " string literal", [CallerArgumentExpression("val")] string expr = null) - { - return expr; - } - - private static string CompilerSuppliedParamMethod([CallerFilePath] string val = "no file", [CallerArgumentExpression("val")] string expr = null) - { - return expr; - } - - [Fact] - [ActiveIssue("https://github.com/dotnet/roslyn/issues/19605")] - public static void ExtensionMethodThisParameterHandling() - { - int notVal = 0; - - Assert.Equal("notVal", notVal.ExtensionMethod()); - } - - private static string ExtensionMethod(this int val, [CallerArgumentExpression("val")] string expr = null) - { - return expr; - } - - [Fact] - [ActiveIssue("https://github.com/dotnet/roslyn/issues/19605")] - public static void InstanceMethodThisHandling() - { - var instance = new InstanceTest(); - - Assert.Equal("instance", instance.Method()); - Assert.Equal("new InstanceTest()", new InstanceTest().Method()); - Assert.Equal("(instance ?? new InstanceTest())", (instance ?? new InstanceTest()).Method()); - - Assert.Equal("", instance.NoThisMethodCaller()); - Assert.Equal("this", instance.ThisMethodCaller()); - } - - private class InstanceTest - { - public string NoThisMethodCaller() - { - return Method(); - } - - public string ThisMethodCaller() - { - return this.Method(); - } - - public string Method([CallerArgumentExpression("this")] string expr = null) - { - return expr; - } - } + private static string GetValue(object argument, [CallerArgumentExpression("argument")] string expr = null) => expr; } }