From 4adb4abf3dbeff4fb3070315368f49d66c732862 Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Mon, 3 Jun 2019 17:17:26 -0700 Subject: [PATCH 1/5] Fix some nullable annotations from API Review --- .../System.Private.CoreLib.csproj | 3 +- .../shared/System/Activator.RuntimeType.cs | 4 +-- .../shared/System/Activator.cs | 2 +- .../shared/System/AppContext.cs | 4 +-- .../ComponentModel/DefaultValueAttribute.cs | 2 +- .../System/Globalization/TimeSpanParse.cs | 9 +++--- .../shared/System/Nullable.cs | 2 ++ .../shared/System/Reflection/Assembly.cs | 22 +++++++------- .../shared/System/Reflection/AssemblyName.cs | 2 +- .../shared/System/Reflection/Emit/Opcode.cs | 2 ++ .../shared/System/Reflection/FieldInfo.cs | 2 +- .../shared/System/Reflection/IReflect.cs | 2 +- .../shared/System/Reflection/MemberFilter.cs | 2 +- .../shared/System/Reflection/MethodInfo.cs | 10 +++---- .../shared/System/Reflection/Module.cs | 6 ++-- .../shared/System/Reflection/PropertyInfo.cs | 8 ++--- .../shared/System/Reflection/SignatureType.cs | 6 ++-- .../shared/System/Reflection/TypeDelegator.cs | 2 +- .../shared/System/Reflection/TypeFilter.cs | 2 +- .../ManifestBasedResourceGroveler.cs | 2 +- .../System/Resources/ResourceReader.Core.cs | 2 +- .../shared/System/Resources/ResourceSet.cs | 2 +- .../shared/System/String.Comparison.cs | 24 +++++---------- .../shared/System/String.Manipulation.cs | 18 ++++------- .../Threading/Tasks/TaskContinuation.cs | 3 ++ .../System/Threading/Tasks/ValueTask.cs | 2 ++ .../shared/System/TimeSpan.cs | 12 ++++---- .../shared/System/Type.Helpers.cs | 4 +-- .../shared/System/Type.cs | 30 +++++++++---------- .../Runtime/InteropServices/ComActivator.cs | 2 +- .../src/System/Reflection/CustomAttribute.cs | 2 +- .../Reflection/Emit/ConstructorBuilder.cs | 2 ++ .../Reflection/Emit/DynamicILGenerator.cs | 6 ++++ .../System/Reflection/Emit/DynamicMethod.cs | 8 ++--- .../src/System/Reflection/Emit/EnumBuilder.cs | 2 +- .../Emit/GenericTypeParameterBuilder.cs | 2 +- .../src/System/Reflection/Emit/ILGenerator.cs | 4 +-- .../System/Reflection/Emit/MethodBuilder.cs | 22 ++++++++------ .../Emit/MethodBuilderInstantiation.cs | 6 ++-- .../System/Reflection/Emit/PropertyBuilder.cs | 4 +-- .../System/Reflection/Emit/SymbolMethod.cs | 2 ++ .../src/System/Reflection/Emit/SymbolType.cs | 2 +- .../src/System/Reflection/Emit/TypeBuilder.cs | 5 +++- .../Emit/TypeBuilderInstantiation.cs | 2 +- .../Emit/XXXOnTypeBuilderInstantiation.cs | 8 +++-- .../src/System/Reflection/MdFieldInfo.cs | 4 +++ .../src/System/Reflection/RtFieldInfo.cs | 2 ++ .../Reflection/RuntimeConstructorInfo.cs | 2 ++ .../System/Reflection/RuntimeMethodInfo.cs | 19 +++++++----- .../System/Reflection/RuntimePropertyInfo.cs | 8 ++--- .../src/System/RtType.cs | 8 ++--- .../src/System/StartupHookProvider.cs | 2 +- 52 files changed, 166 insertions(+), 149 deletions(-) diff --git a/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/System.Private.CoreLib.csproj index 6b3daed95f37..b3646fc0571f 100644 --- a/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -54,8 +54,7 @@ prompt 4 true - - $(NoWarn);649,1573,1591,0419,3021,CS8609 + $(NoWarn);649,1573,1591,0419,3021 enable diff --git a/src/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs b/src/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs index bd7670f9e312..72e312aae7ec 100644 --- a/src/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs +++ b/src/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs @@ -116,7 +116,7 @@ public static partial class Activator if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime) { // WinRT type - we have to use Type.GetType - type = Type.GetType(typeName + ", " + assemblyString, true /*throwOnError*/, ignoreCase); + type = Type.GetType(typeName + ", " + assemblyString, throwOnError: true, ignoreCase); } else { @@ -131,7 +131,7 @@ public static partial class Activator type = assembly!.GetType(typeName, throwOnError: true, ignoreCase); } - object? o = CreateInstance(type, bindingAttr, binder, args, culture, activationAttributes); + object? o = CreateInstance(type!, bindingAttr, binder, args, culture, activationAttributes); return o != null ? new ObjectHandle(o) : null; } diff --git a/src/System.Private.CoreLib/shared/System/Activator.cs b/src/System.Private.CoreLib/shared/System/Activator.cs index 8d6610f6a94f..0426211c7638 100644 --- a/src/System.Private.CoreLib/shared/System/Activator.cs +++ b/src/System.Private.CoreLib/shared/System/Activator.cs @@ -45,7 +45,7 @@ public static partial class Activator public static ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture, object?[]? activationAttributes) { Assembly assembly = Assembly.LoadFrom(assemblyFile); - Type t = assembly.GetType(typeName, true, ignoreCase); + Type t = assembly.GetType(typeName, throwOnError: true, ignoreCase)!; object? o = CreateInstance(t, bindingAttr, binder, args, culture, activationAttributes); diff --git a/src/System.Private.CoreLib/shared/System/AppContext.cs b/src/System.Private.CoreLib/shared/System/AppContext.cs index 7f81a4346753..730b63091db9 100644 --- a/src/System.Private.CoreLib/shared/System/AppContext.cs +++ b/src/System.Private.CoreLib/shared/System/AppContext.cs @@ -17,14 +17,14 @@ public static partial class AppContext private static Dictionary? s_switches; private static string? s_defaultBaseDirectory; - public static string? BaseDirectory + public static string BaseDirectory { get { // The value of APP_CONTEXT_BASE_DIRECTORY key has to be a string and it is not allowed to be any other type. // Otherwise the caller will get invalid cast exception return (string?)GetData("APP_CONTEXT_BASE_DIRECTORY") ?? - (s_defaultBaseDirectory ?? (s_defaultBaseDirectory = GetBaseDirectoryCore())); + (s_defaultBaseDirectory ?? (s_defaultBaseDirectory = GetBaseDirectoryCore())) ?? string.Empty; } } diff --git a/src/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs b/src/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs index 97aceddb70f0..2a67357ed9e2 100644 --- a/src/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs +++ b/src/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs @@ -30,7 +30,7 @@ public class DefaultValueAttribute : Attribute /// class, converting the specified value to the specified type, and using the U.S. English /// culture as the translation context. /// - public DefaultValueAttribute(Type? type, string? value) + public DefaultValueAttribute(Type type, string? value) { // The null check and try/catch here are because attributes should never throw exceptions. // We would fail to load an otherwise normal class. diff --git a/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs b/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs index 6b4ea6a7c936..20669bf13753 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs @@ -655,7 +655,7 @@ internal static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan return false; } - internal static TimeSpan ParseExactMultiple(ReadOnlySpan input, string?[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles) + internal static TimeSpan ParseExactMultiple(ReadOnlySpan input, string[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles) { var parseResult = new TimeSpanResult(throwOnFailure: true, originalTimeSpanString: input); bool success = TryParseExactMultipleTimeSpan(input, formats, formatProvider, styles, ref parseResult); @@ -663,7 +663,7 @@ internal static TimeSpan ParseExactMultiple(ReadOnlySpan input, string?[] return parseResult.parsedTimeSpan; } - internal static bool TryParseExactMultiple(ReadOnlySpan input, string?[]? formats, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result) + internal static bool TryParseExactMultiple(ReadOnlySpan input, string[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result) { var parseResult = new TimeSpanResult(throwOnFailure: false, originalTimeSpanString: input); @@ -1669,7 +1669,7 @@ internal void SkipBlanks() } /// Common private ParseExactMultiple method called by both ParseExactMultiple and TryParseExactMultiple. - private static bool TryParseExactMultipleTimeSpan(ReadOnlySpan input, string?[]? formats, IFormatProvider? formatProvider, TimeSpanStyles styles, ref TimeSpanResult result) + private static bool TryParseExactMultipleTimeSpan(ReadOnlySpan input, string[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles, ref TimeSpanResult result) { if (formats == null) { @@ -1690,8 +1690,7 @@ private static bool TryParseExactMultipleTimeSpan(ReadOnlySpan input, stri // one of the formats. for (int i = 0; i < formats.Length; i++) { - // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) - if (formats[i] == null || formats[i]!.Length == 0) + if (formats[i] == null || formats[i].Length == 0) { return result.SetBadFormatSpecifierFailure(); } diff --git a/src/System.Private.CoreLib/shared/System/Nullable.cs b/src/System.Private.CoreLib/shared/System/Nullable.cs index a34769645895..8d308a758deb 100644 --- a/src/System.Private.CoreLib/shared/System/Nullable.cs +++ b/src/System.Private.CoreLib/shared/System/Nullable.cs @@ -71,10 +71,12 @@ public override int GetHashCode() return hasValue ? value.GetHashCode() : 0; } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override string? ToString() { return hasValue ? value.ToString() : ""; } +#pragma warning restore CS8609 [NonVersionable] public static implicit operator Nullable(T value) diff --git a/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs b/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs index 78ab61b4a350..aa9cd55055f2 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs @@ -92,9 +92,9 @@ public virtual Type[] GetTypes() public virtual AssemblyName GetName() => GetName(copiedName: false); public virtual AssemblyName GetName(bool copiedName) { throw NotImplemented.ByDesign; } - public virtual Type GetType(string name) => GetType(name, throwOnError: false, ignoreCase: false); - public virtual Type GetType(string name, bool throwOnError) => GetType(name, throwOnError: throwOnError, ignoreCase: false); - public virtual Type GetType(string name, bool throwOnError, bool ignoreCase) { throw NotImplemented.ByDesign; } + public virtual Type? GetType(string name) => GetType(name, throwOnError: false, ignoreCase: false); + public virtual Type? GetType(string name, bool throwOnError) => GetType(name, throwOnError: throwOnError, ignoreCase: false); + public virtual Type? GetType(string name, bool throwOnError, bool ignoreCase) { throw NotImplemented.ByDesign; } public virtual bool IsDefined(Type attributeType, bool inherit) { throw NotImplemented.ByDesign; } @@ -110,7 +110,7 @@ public virtual Type[] GetTypes() public object? CreateInstance(string typeName, bool ignoreCase) => CreateInstance(typeName, ignoreCase, BindingFlags.Public | BindingFlags.Instance, binder: null, args: null, culture: null, activationAttributes: null); public virtual object? CreateInstance(string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder? binder, object[]? args, CultureInfo? culture, object[]? activationAttributes) { - Type t = GetType(typeName, throwOnError: false, ignoreCase: ignoreCase); + Type? t = GetType(typeName, throwOnError: false, ignoreCase: ignoreCase); if (t == null) return null; @@ -120,7 +120,7 @@ public virtual Type[] GetTypes() public virtual event ModuleResolveEventHandler ModuleResolve { add { throw NotImplemented.ByDesign; } remove { throw NotImplemented.ByDesign; } } public virtual Module? ManifestModule { get { throw NotImplemented.ByDesign; } } - public virtual Module GetModule(string name) { throw NotImplemented.ByDesign; } + public virtual Module? GetModule(string name) { throw NotImplemented.ByDesign; } public Module[] GetModules() => GetModules(getResourceModules: false); public virtual Module[] GetModules(bool getResourceModules) { throw NotImplemented.ByDesign; } @@ -324,19 +324,19 @@ public static Assembly LoadFrom(string assemblyFile) return AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath); } - public static Assembly LoadFrom(string? assemblyFile, byte[]? hashValue, AssemblyHashAlgorithm hashAlgorithm) + public static Assembly LoadFrom(string assemblyFile, byte[]? hashValue, AssemblyHashAlgorithm hashAlgorithm) { throw new NotSupportedException(SR.NotSupported_AssemblyLoadFromHash); } public static Assembly UnsafeLoadFrom(string assemblyFile) => LoadFrom(assemblyFile); - public Module LoadModule(string? moduleName, byte[]? rawModule) => LoadModule(moduleName, rawModule, null); - public virtual Module LoadModule(string? moduleName, byte[]? rawModule, byte[]? rawSymbolStore) { throw NotImplemented.ByDesign; } + public Module LoadModule(string moduleName, byte[]? rawModule) => LoadModule(moduleName, rawModule, null); + public virtual Module LoadModule(string moduleName, byte[]? rawModule, byte[]? rawSymbolStore) { throw NotImplemented.ByDesign; } - public static Assembly ReflectionOnlyLoad(byte[]? rawAssembly) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } - public static Assembly ReflectionOnlyLoad(string? assemblyString) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } - public static Assembly ReflectionOnlyLoadFrom(string? assemblyFile) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } + public static Assembly ReflectionOnlyLoad(byte[] rawAssembly) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } + public static Assembly ReflectionOnlyLoad(string assemblyString) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } + public static Assembly ReflectionOnlyLoadFrom(string assemblyFile) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } public virtual SecurityRuleSet SecurityRuleSet => SecurityRuleSet.None; } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs b/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs index ffdac5666525..9bc3ea099f90 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs @@ -172,7 +172,7 @@ public void SetPublicKey(byte[]? publicKey) // The compressed version of the public key formed from a truncated hash. // Will throw a SecurityException if _publicKey is invalid - public byte[] GetPublicKeyToken() + public byte[]? GetPublicKeyToken() { if (_publicKeyToken == null) _publicKeyToken = ComputePublicKeyToken(); diff --git a/src/System.Private.CoreLib/shared/System/Reflection/Emit/Opcode.cs b/src/System.Private.CoreLib/shared/System/Reflection/Emit/Opcode.cs index a2d5792c6ab6..b9b799d2f31b 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/Emit/Opcode.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/Emit/Opcode.cs @@ -183,9 +183,11 @@ public override int GetHashCode() return Value; } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override string? ToString() { return Name; } +#pragma warning restore CS8609 } } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs index 3ef9765a424c..7af1c782f1fc 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs @@ -66,7 +66,7 @@ protected FieldInfo() { } [DebuggerHidden] [DebuggerStepThrough] - public void SetValue(object? obj, object value) => SetValue(obj, value, BindingFlags.Default, Type.DefaultBinder, null); + public void SetValue(object? obj, object? value) => SetValue(obj, value, BindingFlags.Default, Type.DefaultBinder, null); public abstract void SetValue(object? obj, object? value, BindingFlags invokeAttr, Binder? binder, CultureInfo? culture); [CLSCompliant(false)] diff --git a/src/System.Private.CoreLib/shared/System/Reflection/IReflect.cs b/src/System.Private.CoreLib/shared/System/Reflection/IReflect.cs index f37389c1cd92..f3658899d924 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/IReflect.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/IReflect.cs @@ -67,7 +67,7 @@ public interface IReflect // For the default binder, the most specific method will be selected. // // This will invoke a specific member... - object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters); + object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters); // Return the underlying Type that represents the IReflect Object. For expando object, // this is the (Object) IReflectInstance.GetType(). For Type object it is this. diff --git a/src/System.Private.CoreLib/shared/System/Reflection/MemberFilter.cs b/src/System.Private.CoreLib/shared/System/Reflection/MemberFilter.cs index ae91b620a6a0..07198cbc4e05 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/MemberFilter.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/MemberFilter.cs @@ -4,5 +4,5 @@ namespace System.Reflection { - public delegate bool MemberFilter(MemberInfo m, object filterCriteria); + public delegate bool MemberFilter(MemberInfo m, object? filterCriteria); } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs index ccc67f328caa..5a04921a74b8 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs @@ -13,15 +13,15 @@ protected MethodInfo() { } public override MemberTypes MemberType => MemberTypes.Method; public virtual ParameterInfo? ReturnParameter { get { throw NotImplemented.ByDesign; } } - public virtual Type? ReturnType { get { throw NotImplemented.ByDesign; } } + public virtual Type ReturnType { get { throw NotImplemented.ByDesign; } } public override Type[] GetGenericArguments() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } - public virtual MethodInfo? GetGenericMethodDefinition() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } - public virtual MethodInfo? MakeGenericMethod(params Type[] typeArguments) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } + public virtual MethodInfo GetGenericMethodDefinition() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } + public virtual MethodInfo MakeGenericMethod(params Type[] typeArguments) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } - public abstract MethodInfo? GetBaseDefinition(); + public abstract MethodInfo GetBaseDefinition(); - public abstract ICustomAttributeProvider? ReturnTypeCustomAttributes { get; } + public abstract ICustomAttributeProvider ReturnTypeCustomAttributes { get; } public virtual Delegate CreateDelegate(Type delegateType) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } public virtual Delegate CreateDelegate(Type delegateType, object? target) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/Module.cs b/src/System.Private.CoreLib/shared/System/Reflection/Module.cs index 72d49d50e25e..77fbc0fc655b 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/Module.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/Module.cs @@ -70,7 +70,7 @@ protected Module() { } public virtual Type? GetType(string className, bool ignoreCase) => GetType(className, throwOnError: false, ignoreCase: ignoreCase); public virtual Type? GetType(string className, bool throwOnError, bool ignoreCase) { throw NotImplemented.ByDesign; } - public virtual Type[] FindTypes(TypeFilter? filter, object filterCriteria) + public virtual Type[] FindTypes(TypeFilter? filter, object? filterCriteria) { Type[] c = GetTypes(); int cnt = 0; @@ -140,8 +140,8 @@ public virtual Type[] FindTypes(TypeFilter? filter, object filterCriteria) public override string ToString() => ScopeName; - public static readonly TypeFilter FilterTypeName = (m, c) => FilterTypeNameImpl(m, c, StringComparison.Ordinal); - public static readonly TypeFilter FilterTypeNameIgnoreCase = (m, c) => FilterTypeNameImpl(m, c, StringComparison.OrdinalIgnoreCase); + public static readonly TypeFilter FilterTypeName = (m, c) => FilterTypeNameImpl(m, c!, StringComparison.Ordinal); + public static readonly TypeFilter FilterTypeNameIgnoreCase = (m, c) => FilterTypeNameImpl(m, c!, StringComparison.OrdinalIgnoreCase); private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public; diff --git a/src/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs index 65697c1d756b..663d52dbb7c5 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs @@ -45,16 +45,16 @@ protected PropertyInfo() { } public virtual object? GetValue(object? obj, object?[]? index) => GetValue(obj, BindingFlags.Default, binder: null, index: index, culture: null); public abstract object? GetValue(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? index, CultureInfo? culture); - public virtual object GetConstantValue() { throw NotImplemented.ByDesign; } - public virtual object GetRawConstantValue() { throw NotImplemented.ByDesign; } + public virtual object? GetConstantValue() { throw NotImplemented.ByDesign; } + public virtual object? GetRawConstantValue() { throw NotImplemented.ByDesign; } [DebuggerHidden] [DebuggerStepThrough] public void SetValue(object? obj, object? value) => SetValue(obj, value, index: null); [DebuggerHidden] [DebuggerStepThrough] - public virtual void SetValue(object? obj, object? value, object[]? index) => SetValue(obj, value, BindingFlags.Default, binder: null, index: index, culture: null); - public abstract void SetValue(object? obj, object? value, BindingFlags invokeAttr, Binder? binder, object[]? index, CultureInfo? culture); + public virtual void SetValue(object? obj, object? value, object?[]? index) => SetValue(obj, value, BindingFlags.Default, binder: null, index: index, culture: null); + public abstract void SetValue(object? obj, object? value, BindingFlags invokeAttr, Binder? binder, object?[]? index, CultureInfo? culture); public override bool Equals(object? obj) => base.Equals(obj); public override int GetHashCode() => base.GetHashCode(); diff --git a/src/System.Private.CoreLib/shared/System/Reflection/SignatureType.cs b/src/System.Private.CoreLib/shared/System/Reflection/SignatureType.cs index d5674bcb67b7..b59e245e869a 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/SignatureType.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/SignatureType.cs @@ -111,11 +111,11 @@ public sealed override Type MakeArrayType(int rank) public sealed override Type GetNestedType(string name, BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType); public sealed override Type[] GetNestedTypes(BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType); public sealed override PropertyInfo[] GetProperties(BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType); - public sealed override object InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) => throw new NotSupportedException(SR.NotSupported_SignatureType); + public sealed override object InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) => throw new NotSupportedException(SR.NotSupported_SignatureType); protected sealed override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[]? types, ParameterModifier[]? modifiers) => throw new NotSupportedException(SR.NotSupported_SignatureType); protected sealed override MethodInfo GetMethodImpl(string name, int genericParameterCount, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[]? types, ParameterModifier[]? modifiers) => throw new NotSupportedException(SR.NotSupported_SignatureType); protected sealed override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers) => throw new NotSupportedException(SR.NotSupported_SignatureType); - public sealed override MemberInfo[] FindMembers(MemberTypes memberType, BindingFlags bindingAttr, MemberFilter? filter, object filterCriteria) => throw new NotSupportedException(SR.NotSupported_SignatureType); + public sealed override MemberInfo[] FindMembers(MemberTypes memberType, BindingFlags bindingAttr, MemberFilter? filter, object? filterCriteria) => throw new NotSupportedException(SR.NotSupported_SignatureType); public sealed override MemberInfo[] GetMember(string name, BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType); public sealed override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType); public sealed override MemberInfo[] GetDefaultMembers() => throw new NotSupportedException(SR.NotSupported_SignatureType); @@ -129,7 +129,7 @@ public sealed override Type MakeArrayType(int rank) protected sealed override bool IsCOMObjectImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType); protected sealed override bool IsPrimitiveImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType); public sealed override IEnumerable CustomAttributes => throw new NotSupportedException(SR.NotSupported_SignatureType); - public sealed override Type[] FindInterfaces(TypeFilter filter, object filterCriteria) => throw new NotSupportedException(SR.NotSupported_SignatureType); + public sealed override Type[] FindInterfaces(TypeFilter filter, object? filterCriteria) => throw new NotSupportedException(SR.NotSupported_SignatureType); public sealed override InterfaceMapping GetInterfaceMap(Type interfaceType) => throw new NotSupportedException(SR.NotSupported_SignatureType); protected sealed override bool IsContextfulImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType); public sealed override bool IsEnum => throw new NotSupportedException(SR.NotSupported_SignatureType); diff --git a/src/System.Private.CoreLib/shared/System/Reflection/TypeDelegator.cs b/src/System.Private.CoreLib/shared/System/Reflection/TypeDelegator.cs index 81112c9d10a0..a31367a00009 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/TypeDelegator.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/TypeDelegator.cs @@ -35,7 +35,7 @@ public TypeDelegator(Type delegatingType) public override int MetadataToken => typeImpl.MetadataToken; public override object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, - object[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) + object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) { return typeImpl.InvokeMember(name, invokeAttr, binder, target, args, modifiers, culture, namedParameters); } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/TypeFilter.cs b/src/System.Private.CoreLib/shared/System/Reflection/TypeFilter.cs index eb049f81f902..befa09ac32f8 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/TypeFilter.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/TypeFilter.cs @@ -4,5 +4,5 @@ namespace System.Reflection { - public delegate bool TypeFilter(Type m, object filterCriteria); + public delegate bool TypeFilter(Type m, object? filterCriteria); } diff --git a/src/System.Private.CoreLib/shared/System/Resources/ManifestBasedResourceGroveler.cs b/src/System.Private.CoreLib/shared/System/Resources/ManifestBasedResourceGroveler.cs index f7f551b17c99..a03ec6622880 100644 --- a/src/System.Private.CoreLib/shared/System/Resources/ManifestBasedResourceGroveler.cs +++ b/src/System.Private.CoreLib/shared/System/Resources/ManifestBasedResourceGroveler.cs @@ -444,7 +444,7 @@ private void HandleSatelliteMissing() satAssemName += ", Version=" + _mediator.SatelliteContractVersion.ToString(); } - byte[] token = _mediator.MainAssembly.GetName().GetPublicKeyToken(); + byte[] token = _mediator.MainAssembly.GetName().GetPublicKeyToken()!; int iLen = token.Length; StringBuilder publicKeyTok = new StringBuilder(iLen * 2); diff --git a/src/System.Private.CoreLib/shared/System/Resources/ResourceReader.Core.cs b/src/System.Private.CoreLib/shared/System/Resources/ResourceReader.Core.cs index 94f7f62c8d05..f6c9caff9ef2 100644 --- a/src/System.Private.CoreLib/shared/System/Resources/ResourceReader.Core.cs +++ b/src/System.Private.CoreLib/shared/System/Resources/ResourceReader.Core.cs @@ -79,7 +79,7 @@ private void InitializeBinaryFormatter() // create an unbound delegate that can accept a BinaryFormatter instance as object return (Func)typeof(ResourceReader) .GetMethod(nameof(CreateUntypedDelegate), BindingFlags.NonPublic | BindingFlags.Static)! - .MakeGenericMethod(s_binaryFormatterType)! + .MakeGenericMethod(s_binaryFormatterType) .Invoke(null, new object[] { binaryFormatterDeserialize })!; }); #pragma warning restore CS8634 diff --git a/src/System.Private.CoreLib/shared/System/Resources/ResourceSet.cs b/src/System.Private.CoreLib/shared/System/Resources/ResourceSet.cs index 4f5edf8426b0..dfd2a7f251aa 100644 --- a/src/System.Private.CoreLib/shared/System/Resources/ResourceSet.cs +++ b/src/System.Private.CoreLib/shared/System/Resources/ResourceSet.cs @@ -120,7 +120,7 @@ public virtual Type GetDefaultReader() public virtual Type GetDefaultWriter() { Assembly resourceWriterAssembly = Assembly.Load("System.Resources.Writer, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); - return resourceWriterAssembly.GetType("System.Resources.ResourceWriter", true); + return resourceWriterAssembly.GetType("System.Resources.ResourceWriter", throwOnError: true)!; } public virtual IDictionaryEnumerator GetEnumerator() diff --git a/src/System.Private.CoreLib/shared/System/String.Comparison.cs b/src/System.Private.CoreLib/shared/System/String.Comparison.cs index 6bf3de78fe40..d0d49b88a3b2 100644 --- a/src/System.Private.CoreLib/shared/System/String.Comparison.cs +++ b/src/System.Private.CoreLib/shared/System/String.Comparison.cs @@ -251,14 +251,10 @@ public static int Compare(string? strA, string? strB, StringComparison compariso // to determine whether it is lexicographically less, equal, or greater, and then a // negative integer, 0, or a positive integer is returned; respectively. // - public static int Compare(string? strA, string? strB, CultureInfo culture, CompareOptions options) + public static int Compare(string? strA, string? strB, CultureInfo? culture, CompareOptions options) { - if (culture == null) - { - throw new ArgumentNullException(nameof(culture)); - } - - return culture.CompareInfo.Compare(strA, strB, options); + CultureInfo compareCulture = culture ?? CultureInfo.CurrentCulture; + return compareCulture.CompareInfo.Compare(strA, strB, options); } @@ -269,7 +265,7 @@ public static int Compare(string? strA, string? strB, CultureInfo culture, Compa // The case-sensitive option is set by ignoreCase, and the culture is set // by culture // - public static int Compare(string? strA, string? strB, bool ignoreCase, CultureInfo culture) + public static int Compare(string? strA, string? strB, bool ignoreCase, CultureInfo? culture) { var options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None; return Compare(strA, strB, culture, options); @@ -328,7 +324,7 @@ public static int Compare(string? strA, int indexA, string? strB, int indexB, in // beginning at indexB of the same length. Case sensitivity is determined by the ignoreCase boolean, // and the culture is set by culture. // - public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, bool ignoreCase, CultureInfo culture) + public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, bool ignoreCase, CultureInfo? culture) { var options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None; return Compare(strA, indexA, strB, indexB, length, culture, options); @@ -339,13 +335,9 @@ public static int Compare(string? strA, int indexA, string? strB, int indexB, in // at indexA of length length is compared with the substring of strB // beginning at indexB of the same length. // - public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, CultureInfo culture, CompareOptions options) + public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, CultureInfo? culture, CompareOptions options) { - if (culture == null) - { - throw new ArgumentNullException(nameof(culture)); - } - + CultureInfo compareCulture = culture ?? CultureInfo.CurrentCulture; int lengthA = length; int lengthB = length; @@ -359,7 +351,7 @@ public static int Compare(string? strA, int indexA, string? strB, int indexB, in lengthB = Math.Min(lengthB, strB.Length - indexB); } - return culture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, options); + return compareCulture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, options); } public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, StringComparison comparisonType) diff --git a/src/System.Private.CoreLib/shared/System/String.Manipulation.cs b/src/System.Private.CoreLib/shared/System/String.Manipulation.cs index 74fff875d69d..1cd2b74b558b 100644 --- a/src/System.Private.CoreLib/shared/System/String.Manipulation.cs +++ b/src/System.Private.CoreLib/shared/System/String.Manipulation.cs @@ -1702,13 +1702,10 @@ public string ToLower() } // Creates a copy of this string in lower case. The culture is set by culture. - public string ToLower(CultureInfo culture) + public string ToLower(CultureInfo? culture) { - if (culture == null) - { - throw new ArgumentNullException(nameof(culture)); - } - return culture.TextInfo.ToLower(this); + CultureInfo cult = culture ?? CultureInfo.CurrentCulture; + return cult.TextInfo.ToLower(this); } // Creates a copy of this string in lower case based on invariant culture. @@ -1723,13 +1720,10 @@ public string ToUpper() } // Creates a copy of this string in upper case. The culture is set by culture. - public string ToUpper(CultureInfo culture) + public string ToUpper(CultureInfo? culture) { - if (culture == null) - { - throw new ArgumentNullException(nameof(culture)); - } - return culture.TextInfo.ToUpper(this); + CultureInfo cult = culture ?? CultureInfo.CurrentCulture; + return cult.TextInfo.ToUpper(this); } //Creates a copy of this string in upper case based on invariant culture. diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs index fbe77339ccaf..24c756e34d62 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs @@ -341,6 +341,7 @@ internal override void Run(Task completedTask, bool canInlineContinuationTask) else continuationTask.InternalCancel(false); } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) internal override Delegate[]? GetDelegateContinuationsForDebugger() { if (m_task.m_action == null) @@ -350,6 +351,8 @@ internal override void Run(Task completedTask, bool canInlineContinuationTask) return new Delegate[] { m_task.m_action }; } +#pragma warning restore CS8609 + } /// Task continuation for awaiting with a current synchronization context. diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs index 75c6fd9a325c..123800914be5 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs @@ -776,6 +776,7 @@ public TResult Result public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) => new ConfiguredValueTaskAwaitable(new ValueTask(_obj, _result, _token, continueOnCapturedContext)); +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) /// Gets a string-representation of this . public override string? ToString() { @@ -790,5 +791,6 @@ public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCaptu return string.Empty; } +#pragma warning restore CS8609 } } diff --git a/src/System.Private.CoreLib/shared/System/TimeSpan.cs b/src/System.Private.CoreLib/shared/System/TimeSpan.cs index 3c1d5ebe7511..f08b9048d750 100644 --- a/src/System.Private.CoreLib/shared/System/TimeSpan.cs +++ b/src/System.Private.CoreLib/shared/System/TimeSpan.cs @@ -382,7 +382,7 @@ public static bool TryParse(ReadOnlySpan input, IFormatProvider? formatPro { return TimeSpanParse.TryParse(input, formatProvider, out result); } - public static bool TryParseExact(string? input, string? format, IFormatProvider? formatProvider, out TimeSpan result) + public static bool TryParseExact(string? input, string format, IFormatProvider? formatProvider, out TimeSpan result) { if (input == null || format == null) { @@ -396,7 +396,7 @@ public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan fo { return TimeSpanParse.TryParseExact(input, format, formatProvider, TimeSpanStyles.None, out result); } - public static bool TryParseExact(string? input, string?[]? formats, IFormatProvider? formatProvider, out TimeSpan result) + public static bool TryParseExact(string? input, string[] formats, IFormatProvider? formatProvider, out TimeSpan result) { if (input == null) { @@ -405,12 +405,12 @@ public static bool TryParseExact(string? input, string?[]? formats, IFormatProvi } return TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, TimeSpanStyles.None, out result); } - public static bool TryParseExact(ReadOnlySpan input, string?[]? formats, IFormatProvider? formatProvider, out TimeSpan result) + public static bool TryParseExact(ReadOnlySpan input, string[] formats, IFormatProvider? formatProvider, out TimeSpan result) { return TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, TimeSpanStyles.None, out result); } - public static bool TryParseExact(string? input, string? format, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result) + public static bool TryParseExact(string? input, string format, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result) { ValidateStyles(styles, nameof(styles)); if (input == null || format == null) @@ -427,7 +427,7 @@ public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan fo ValidateStyles(styles, nameof(styles)); return TimeSpanParse.TryParseExact(input, format, formatProvider, styles, out result); } - public static bool TryParseExact(string? input, string?[]? formats, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result) + public static bool TryParseExact(string? input, string[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result) { ValidateStyles(styles, nameof(styles)); if (input == null) @@ -438,7 +438,7 @@ public static bool TryParseExact(string? input, string?[]? formats, IFormatProvi return TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, styles, out result); } - public static bool TryParseExact(ReadOnlySpan input, string?[]? formats, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result) + public static bool TryParseExact(ReadOnlySpan input, string[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result) { ValidateStyles(styles, nameof(styles)); return TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, styles, out result); diff --git a/src/System.Private.CoreLib/shared/System/Type.Helpers.cs b/src/System.Private.CoreLib/shared/System/Type.Helpers.cs index 0f171eca2556..16ad1c1d2d1b 100644 --- a/src/System.Private.CoreLib/shared/System/Type.Helpers.cs +++ b/src/System.Private.CoreLib/shared/System/Type.Helpers.cs @@ -113,7 +113,7 @@ public bool IsVisible } } - public virtual Type[] FindInterfaces(TypeFilter filter, object filterCriteria) + public virtual Type[] FindInterfaces(TypeFilter filter, object? filterCriteria) { if (filter == null) throw new ArgumentNullException(nameof(filter)); @@ -140,7 +140,7 @@ public virtual Type[] FindInterfaces(TypeFilter filter, object filterCriteria) return ret; } - public virtual MemberInfo[] FindMembers(MemberTypes memberType, BindingFlags bindingAttr, MemberFilter? filter, object filterCriteria) + public virtual MemberInfo[] FindMembers(MemberTypes memberType, BindingFlags bindingAttr, MemberFilter? filter, object? filterCriteria) { // Define the work arrays MethodInfo?[]? m = null; diff --git a/src/System.Private.CoreLib/shared/System/Type.cs b/src/System.Private.CoreLib/shared/System/Type.cs index 830cbd9d5004..f78c762df917 100644 --- a/src/System.Private.CoreLib/shared/System/Type.cs +++ b/src/System.Private.CoreLib/shared/System/Type.cs @@ -221,12 +221,10 @@ public virtual Type[] GetGenericParameterConstraints() return GetPropertyImpl(name, bindingAttr, null, null, null, null); } - public PropertyInfo? GetProperty(string name, Type returnType) + public PropertyInfo? GetProperty(string name, Type? returnType) { if (name == null) throw new ArgumentNullException(nameof(name)); - if (returnType == null) - throw new ArgumentNullException(nameof(returnType)); return GetPropertyImpl(name, Type.DefaultLookup, null, returnType, null, null); } @@ -290,24 +288,24 @@ protected virtual TypeCode GetTypeCodeImpl() public abstract Guid GUID { get; } - public static Type GetTypeFromCLSID(Guid clsid) => GetTypeFromCLSID(clsid, null, throwOnError: false); - public static Type GetTypeFromCLSID(Guid clsid, bool throwOnError) => GetTypeFromCLSID(clsid, null, throwOnError: throwOnError); - public static Type GetTypeFromCLSID(Guid clsid, string? server) => GetTypeFromCLSID(clsid, server, throwOnError: false); + public static Type? GetTypeFromCLSID(Guid clsid) => GetTypeFromCLSID(clsid, null, throwOnError: false); + public static Type? GetTypeFromCLSID(Guid clsid, bool throwOnError) => GetTypeFromCLSID(clsid, null, throwOnError: throwOnError); + public static Type? GetTypeFromCLSID(Guid clsid, string? server) => GetTypeFromCLSID(clsid, server, throwOnError: false); - public static Type GetTypeFromProgID(string progID) => GetTypeFromProgID(progID, null, throwOnError: false); - public static Type GetTypeFromProgID(string progID, bool throwOnError) => GetTypeFromProgID(progID, null, throwOnError: throwOnError); - public static Type GetTypeFromProgID(string progID, string? server) => GetTypeFromProgID(progID, server, throwOnError: false); + public static Type? GetTypeFromProgID(string progID) => GetTypeFromProgID(progID, null, throwOnError: false); + public static Type? GetTypeFromProgID(string progID, bool throwOnError) => GetTypeFromProgID(progID, null, throwOnError: throwOnError); + public static Type? GetTypeFromProgID(string progID, string? server) => GetTypeFromProgID(progID, server, throwOnError: false); public abstract Type? BaseType { get; } [DebuggerHidden] [DebuggerStepThrough] - public object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object[]? args) => InvokeMember(name, invokeAttr, binder, target, args, null, null, null); + public object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args) => InvokeMember(name, invokeAttr, binder, target, args, null, null, null); [DebuggerHidden] [DebuggerStepThrough] - public object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object[]? args, CultureInfo? culture) => InvokeMember(name, invokeAttr, binder, target, args, null, culture, null); - public abstract object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters); + public object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, CultureInfo? culture) => InvokeMember(name, invokeAttr, binder, target, args, null, culture, null); + public abstract object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters); public Type? GetInterface(string name) => GetInterface(name, ignoreCase: false); public abstract Type? GetInterface(string name, bool ignoreCase); @@ -366,7 +364,7 @@ public override int GetHashCode() } public virtual bool Equals(Type? o) => o == null ? false : object.ReferenceEquals(this.UnderlyingSystemType, o.UnderlyingSystemType); - public static Type ReflectionOnlyGetType(string typeName, bool throwIfNotFound, bool ignoreCase) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } + public static Type? ReflectionOnlyGetType(string typeName, bool throwIfNotFound, bool ignoreCase) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } public static Binder DefaultBinder { @@ -387,9 +385,9 @@ public static Binder DefaultBinder public static readonly Type[] EmptyTypes = Array.Empty(); public static readonly object Missing = System.Reflection.Missing.Value; - public static readonly MemberFilter FilterAttribute = FilterAttributeImpl; - public static readonly MemberFilter FilterName = (m, c) => FilterNameImpl(m, c, StringComparison.Ordinal); - public static readonly MemberFilter FilterNameIgnoreCase = (m, c) => FilterNameImpl(m, c, StringComparison.OrdinalIgnoreCase); + public static readonly MemberFilter FilterAttribute = FilterAttributeImpl!; + public static readonly MemberFilter FilterName = (m, c) => FilterNameImpl(m, c!, StringComparison.Ordinal); + public static readonly MemberFilter FilterNameIgnoreCase = (m, c) => FilterNameImpl(m, c!, StringComparison.OrdinalIgnoreCase); private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public; } diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs b/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs index 34ce4de03ac5..2c4d1a5a2735 100644 --- a/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs +++ b/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs @@ -350,7 +350,7 @@ private static Type FindClassType(Guid clsid, string assemblyPath, string assemb AssemblyLoadContext alc = GetALC(assemblyPath); var assemblyNameLocal = new AssemblyName(assemblyName); Assembly assem = alc.LoadFromAssemblyName(assemblyNameLocal); - Type t = assem.GetType(typeName); + Type? t = assem.GetType(typeName); if (t != null) { return t; diff --git a/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs index d14282e82eb7..9cd4b90d62fc 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs @@ -440,7 +440,7 @@ public override string ToString() #endregion #region Public Members - public virtual Type? AttributeType { get { return Constructor.DeclaringType; } } + public virtual Type AttributeType { get { return Constructor.DeclaringType!; } } public virtual ConstructorInfo Constructor { get { return m_ctor; } } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.cs index 0ac5afd450f2..0ee2ecd2838f 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.cs @@ -190,11 +190,13 @@ public Module GetModule() return m_methodBuilder.GetModule(); } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) // This always returns null. Is that what we want? internal override Type? GetReturnType() { return m_methodBuilder.ReturnType; } +#pragma warning restore CS8609 public string Signature { diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs index 07085d22791d..d9a702b3e75e 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs @@ -738,10 +738,12 @@ internal override byte[] GetLocalsSignature() return m_localSignature; } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) internal override byte[]? GetRawEHInfo() { return m_exceptionHeader; } +#pragma warning restore CS8609 internal override unsafe void GetEHInfo(int excNumber, void* exc) { @@ -768,7 +770,9 @@ internal override unsafe void GetEHInfo(int excNumber, void* exc) } } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) internal override string? GetStringLiteral(int token) { return m_scope.GetString(token); } +#pragma warning restore CS8609 internal override void ResolveToken(int token, out IntPtr typeHandle, out IntPtr methodHandle, out IntPtr fieldHandle) @@ -835,10 +839,12 @@ internal override void ResolveToken(int token, out IntPtr typeHandle, out IntPtr } } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) internal override byte[]? ResolveSignature(int token, int fromMethod) { return m_scope.ResolveSignature(token, fromMethod); } +#pragma warning restore CS8609 internal override MethodInfo GetDynamicMethod() { diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs index 6a8c3401e8a0..9b3fab35addc 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs @@ -490,11 +490,11 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit) public override bool IsDefined(Type attributeType, bool inherit) { return m_dynMethod.IsDefined(attributeType, inherit); } - public override Type? ReturnType { get { return m_dynMethod.ReturnType; } } + public override Type ReturnType { get { return m_dynMethod.ReturnType; } } public override ParameterInfo? ReturnParameter { get { return m_dynMethod.ReturnParameter; } } - public override ICustomAttributeProvider? ReturnTypeCustomAttributes { get { return m_dynMethod.ReturnTypeCustomAttributes; } } + public override ICustomAttributeProvider ReturnTypeCustomAttributes { get { return m_dynMethod.ReturnTypeCustomAttributes; } } // // DynamicMethod specific methods @@ -706,7 +706,6 @@ public override bool IsSecurityTransparent get { return m_owner.IsSecurityTransparent; } } -#pragma warning disable CS8608 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override Type ReturnType { get @@ -714,19 +713,16 @@ public override Type ReturnType return m_owner.m_returnType; } } -#pragma warning restore CS8608 public override ParameterInfo? ReturnParameter { get { return null; } } -#pragma warning disable CS8608 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override ICustomAttributeProvider ReturnTypeCustomAttributes { get { return GetEmptyCAHolder(); } } -#pragma warning restore CS8608 // // private implementation diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs index 68739b04f396..c80df2809c7f 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs @@ -83,7 +83,7 @@ public override Guid GUID BindingFlags invokeAttr, Binder? binder, object? target, - object[]? args, + object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs index 7fb5c8614af4..eb8035a9a3f8 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs @@ -94,7 +94,7 @@ public override Type MakeArrayType(int rank) public override Guid GUID { get { throw new NotSupportedException(); } } - public override object InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) { throw new NotSupportedException(); } + public override object InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) { throw new NotSupportedException(); } public override Assembly Assembly { get { return m_type.Assembly; } } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs index a363f468f78e..4b7c5080344e 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs @@ -1121,7 +1121,7 @@ public virtual void EmitWriteLine(LocalBuilder localBuilder) throw new ArgumentException(SR.NotSupported_OutputStreamUsingTypeBuilder); } parameterTypes[0] = (Type)cls; - MethodInfo? mi = prop.ReturnType!.GetMethod("WriteLine", parameterTypes); + MethodInfo? mi = prop.ReturnType.GetMethod("WriteLine", parameterTypes); if (mi == null) { throw new ArgumentException(SR.Argument_EmitWriteLineType, nameof(localBuilder)); @@ -1161,7 +1161,7 @@ public virtual void EmitWriteLine(FieldInfo fld) throw new NotSupportedException(SR.NotSupported_OutputStreamUsingTypeBuilder); } parameterTypes[0] = (Type)cls; - MethodInfo? mi = prop.ReturnType!.GetMethod("WriteLine", parameterTypes); + MethodInfo? mi = prop.ReturnType.GetMethod("WriteLine", parameterTypes); if (mi == null) { throw new ArgumentException(SR.Argument_EmitWriteLineType, nameof(fld)); diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs index 63e570cfb68f..1b5706d3493c 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs @@ -44,7 +44,7 @@ public sealed class MethodBuilder : MethodInfo // Parameters private SignatureHelper? m_signature; internal Type[]? m_parameterTypes; - private Type? m_returnType; + private Type m_returnType; private Type[]? m_returnTypeRequiredCustomModifiers; private Type[]? m_returnTypeOptionalCustomModifiers; private Type[][]? m_parameterTypeRequiredCustomModifiers; @@ -87,12 +87,12 @@ internal MethodBuilder(string name, MethodAttributes attributes, CallingConventi m_module = mod; m_containingType = type; - // - //if (returnType == null) - //{ - // m_returnType = typeof(void); - //} - //else + + if (returnType == null) + { + m_returnType = typeof(void); + } + else { m_returnType = returnType; } @@ -362,7 +362,7 @@ internal SignatureHelper GetMethodSignature() m_parameterTypes = Array.Empty(); m_signature = SignatureHelper.GetMethodSigHelper(m_module, m_callingConvention, m_inst != null ? m_inst.Length : 0, - m_returnType == null ? typeof(void) : m_returnType, m_returnTypeRequiredCustomModifiers, m_returnTypeOptionalCustomModifiers, + m_returnType, m_returnTypeRequiredCustomModifiers, m_returnTypeOptionalCustomModifiers, m_parameterTypes, m_parameterTypeRequiredCustomModifiers, m_parameterTypeOptionalCustomModifiers); return m_signature; @@ -522,6 +522,7 @@ public override Type? DeclaringType } } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override ICustomAttributeProvider? ReturnTypeCustomAttributes { get @@ -529,6 +530,7 @@ public override ICustomAttributeProvider? ReturnTypeCustomAttributes return null; } } +#pragma warning restore CS8609 public override Type? ReflectedType { @@ -588,7 +590,7 @@ public override MethodInfo GetBaseDefinition() return this; } - public override Type? ReturnType + public override Type ReturnType { get { @@ -647,7 +649,9 @@ public override bool IsDefined(Type attributeType, bool inherit) public override bool IsGenericMethod { get { return m_inst != null; } } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override Type[]? GetGenericArguments() { return m_inst; } +#pragma warning restore CS8609 public override MethodInfo MakeGenericMethod(params Type[] typeArguments) { diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilderInstantiation.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilderInstantiation.cs index 7807b7154441..458ed260e127 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilderInstantiation.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilderInstantiation.cs @@ -88,7 +88,7 @@ public override MethodInfo MakeGenericMethod(params Type[] arguments) #endregion #region Public Abstract\Virtual Members - public override Type? ReturnType + public override Type ReturnType { get { @@ -96,8 +96,8 @@ public override Type? ReturnType } } - public override ParameterInfo? ReturnParameter { get { throw new NotSupportedException(); } } - public override ICustomAttributeProvider? ReturnTypeCustomAttributes { get { throw new NotSupportedException(); } } + public override ParameterInfo ReturnParameter { get { throw new NotSupportedException(); } } + public override ICustomAttributeProvider ReturnTypeCustomAttributes { get { throw new NotSupportedException(); } } public override MethodInfo GetBaseDefinition() { throw new NotSupportedException(); } #endregion } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs index b33b74283282..c65329852db7 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.cs @@ -155,12 +155,12 @@ public override object GetValue(object? obj, BindingFlags invokeAttr, Binder? bi throw new NotSupportedException(SR.NotSupported_DynamicModule); } - public override void SetValue(object? obj, object? value, object[]? index) + public override void SetValue(object? obj, object? value, object?[]? index) { throw new NotSupportedException(SR.NotSupported_DynamicModule); } - public override void SetValue(object? obj, object? value, BindingFlags invokeAttr, Binder? binder, object[]? index, CultureInfo? culture) + public override void SetValue(object? obj, object? value, BindingFlags invokeAttr, Binder? binder, object?[]? index, CultureInfo? culture) { throw new NotSupportedException(SR.NotSupported_DynamicModule); } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolMethod.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolMethod.cs index ea2231ea552c..87775e6b2400 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolMethod.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolMethod.cs @@ -118,6 +118,7 @@ public override RuntimeMethodHandle MethodHandle #endregion #region MethodInfo Overrides +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override Type? ReturnType { get @@ -130,6 +131,7 @@ public override ICustomAttributeProvider? ReturnTypeCustomAttributes { get { return null; } } +#pragma warning restore CS8608 public override object Invoke(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture) { diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolType.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolType.cs index 9f99bad5203f..1a50c73f912d 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolType.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolType.cs @@ -318,7 +318,7 @@ public override Guid GUID } public override object InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, - object[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) + object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) { throw new NotSupportedException(SR.NotSupported_NonReflectedType); } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs index a98c1e940313..9d15357ef3ad 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs @@ -771,7 +771,7 @@ public override Guid GUID } public override object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, - object[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) + object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) { if (!IsCreated()) throw new NotSupportedException(SR.NotSupported_TypeNotYetCreated); @@ -1250,7 +1250,10 @@ public override Type MakeGenericType(params Type[] typeArguments) return TypeBuilderInstantiation.MakeGenericType(this, typeArguments); } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override Type[]? GetGenericArguments() { return m_inst; } +#pragma warning restore CS8609 + // If a TypeBuilder is generic, it must be a generic type definition // All instantiated generic types are TypeBuilderInstantiation. public override bool IsGenericTypeDefinition { get { return IsGenericType; } } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs index 927bd1de6600..8a555a9bf6d7 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs @@ -98,7 +98,7 @@ public override Type MakeArrayType(int rank) return SymbolType.FormCompoundType(s, this, 0)!; } public override Guid GUID { get { throw new NotSupportedException(); } } - public override object InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) { throw new NotSupportedException(); } + public override object InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) { throw new NotSupportedException(); } public override Assembly Assembly { get { return m_type.Assembly; } } public override RuntimeTypeHandle TypeHandle { get { throw new NotSupportedException(); } } public override string? FullName diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs index e3ad63b66bbb..65430397ef4b 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs @@ -74,9 +74,9 @@ public override MethodInfo MakeGenericMethod(params Type[] typeArgs) #endregion #region Public Abstract\Virtual Members - public override Type? ReturnType { get { return m_method.ReturnType; } } - public override ParameterInfo? ReturnParameter { get { throw new NotSupportedException(); } } - public override ICustomAttributeProvider? ReturnTypeCustomAttributes { get { throw new NotSupportedException(); } } + public override Type ReturnType { get { return m_method.ReturnType; } } + public override ParameterInfo ReturnParameter { get { throw new NotSupportedException(); } } + public override ICustomAttributeProvider ReturnTypeCustomAttributes { get { throw new NotSupportedException(); } } public override MethodInfo GetBaseDefinition() { throw new NotSupportedException(); } #endregion } @@ -110,10 +110,12 @@ internal override Type[] GetParameterTypes() return m_ctor.GetParameterTypes(); } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) internal override Type? GetReturnType() { return DeclaringType; } +#pragma warning restore CS8609 #region MemberInfo Overrides public override MemberTypes MemberType { get { return m_ctor.MemberType; } } diff --git a/src/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs index f4cee246cc16..9e7dd0a51d41 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs @@ -66,12 +66,14 @@ public override string Name public override bool IsSecuritySafeCritical { get { return DeclaringType!.IsSecuritySafeCritical; } } public override bool IsSecurityTransparent { get { return DeclaringType!.IsSecurityTransparent; } } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) [DebuggerStepThroughAttribute] [Diagnostics.DebuggerHidden] public override object? GetValueDirect(TypedReference obj) { return GetValue(null); } +#pragma warning restore CS8609 [DebuggerStepThroughAttribute] [Diagnostics.DebuggerHidden] @@ -87,7 +89,9 @@ public override void SetValueDirect(TypedReference obj, object value) return GetValue(false); } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override object? GetRawConstantValue() { return GetValue(true); } +#pragma warning restore CS8609 private object? GetValue(bool raw) { diff --git a/src/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs index ca75d2516607..a5dbc61c4ab5 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs @@ -188,6 +188,7 @@ internal override RuntimeModule GetRuntimeModule() public override object GetRawConstantValue() { throw new InvalidOperationException(); } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) [DebuggerStepThroughAttribute] [Diagnostics.DebuggerHidden] public override object? GetValueDirect(TypedReference obj) @@ -201,6 +202,7 @@ internal override RuntimeModule GetRuntimeModule() return RuntimeFieldHandle.GetValueDirect(this, (RuntimeType)FieldType, &obj, (RuntimeType?)DeclaringType); } } +#pragma warning restore CS8609 [DebuggerStepThroughAttribute] [Diagnostics.DebuggerHidden] diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs index 5d8be5db3ba1..4c95894dc6bb 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs @@ -376,6 +376,7 @@ internal void ThrowNoInvokeException() return RuntimeMethodHandle.InvokeMethod(obj, null, sig, false, wrapExceptions); } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override MethodBody? GetMethodBody() { RuntimeMethodBody? mb = RuntimeMethodHandle.GetMethodBody(this, ReflectedTypeInternal); @@ -383,6 +384,7 @@ internal void ThrowNoInvokeException() mb._methodBase = this; return mb; } +#pragma warning restore CS8609 public override bool IsSecurityCritical { diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs index f60779f1698d..7ff457b4859b 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs @@ -394,6 +394,7 @@ public override CallingConventions CallingConvention } } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override MethodBody? GetMethodBody() { RuntimeMethodBody? mb = RuntimeMethodHandle.GetMethodBody(this, ReflectedTypeInternal); @@ -401,6 +402,8 @@ public override CallingConventions CallingConvention mb._methodBase = this; return mb; } +#pragma warning restore CS8609 + #endregion #region Invocation Logic(On MemberBase) @@ -509,7 +512,6 @@ private void ThrowNoInvokeException() #region MethodInfo Overrides -#pragma warning disable CS8608 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override Type ReturnType { get { return Signature.ReturnType; } @@ -520,6 +522,7 @@ public override ICustomAttributeProvider ReturnTypeCustomAttributes get { return ReturnParameter; } } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override ParameterInfo ReturnParameter { get @@ -528,11 +531,11 @@ public override ParameterInfo ReturnParameter return (m_returnParameter as ParameterInfo)!; } } -#pragma warning restore CS8608 +#pragma warning restore CS8609 public override bool IsCollectible => (RuntimeMethodHandle.GetIsCollectible(new RuntimeMethodHandleInternal(m_handle)) != Interop.BOOL.FALSE); - public override MethodInfo? GetBaseDefinition() + public override MethodInfo GetBaseDefinition() { if (!IsVirtual || IsStatic || m_declaringType == null || m_declaringType.IsInterface) return this; @@ -555,7 +558,7 @@ public override ParameterInfo ReturnParameter declaringType = (RuntimeType)declaringType.BaseType!; } while (declaringType != null); - return (MethodInfo?)RuntimeType.GetMethodBase(baseDeclaringType, baseMethodHandle); + return (MethodInfo)RuntimeType.GetMethodBase(baseDeclaringType, baseMethodHandle)!; } public override Delegate CreateDelegate(Type delegateType) @@ -612,7 +615,7 @@ private Delegate CreateDelegateInternal(Type delegateType, object? firstArgument #endregion #region Generics - public override MethodInfo? MakeGenericMethod(params Type[] methodInstantiation) + public override MethodInfo MakeGenericMethod(params Type[] methodInstantiation) { if (methodInstantiation == null) throw new ArgumentNullException(nameof(methodInstantiation)); @@ -661,7 +664,7 @@ private Delegate CreateDelegateInternal(Type delegateType, object? firstArgument throw; } - return ret; + return ret!; } internal RuntimeType[] GetGenericArgumentsInternal() @@ -680,12 +683,12 @@ public override Type[] GetGenericArguments() return types; } - public override MethodInfo? GetGenericMethodDefinition() + public override MethodInfo GetGenericMethodDefinition() { if (!IsGenericMethod) throw new InvalidOperationException(); - return RuntimeType.GetMethodBase(m_declaringType, RuntimeMethodHandle.StripMethodInstantiation(this)) as MethodInfo; + return (RuntimeType.GetMethodBase(m_declaringType, RuntimeMethodHandle.StripMethodInstantiation(this)) as MethodInfo)!; } public override bool IsGenericMethod diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs index a2bb3c504ecd..3a8ffba31871 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs @@ -248,9 +248,9 @@ internal object GetConstantValue(bool raw) return defaultValue!; } - public override object GetConstantValue() { return GetConstantValue(false); } + public override object? GetConstantValue() { return GetConstantValue(false); } - public override object GetRawConstantValue() { return GetConstantValue(true); } + public override object? GetRawConstantValue() { return GetConstantValue(true); } public override MethodInfo[] GetAccessors(bool nonPublic) { @@ -400,7 +400,7 @@ public override bool CanWrite [DebuggerStepThroughAttribute] [Diagnostics.DebuggerHidden] - public override void SetValue(object? obj, object? value, object[]? index) + public override void SetValue(object? obj, object? value, object?[]? index) { SetValue(obj, value, @@ -412,7 +412,7 @@ public override void SetValue(object? obj, object? value, object[]? index) [DebuggerStepThroughAttribute] [Diagnostics.DebuggerHidden] - public override void SetValue(object? obj, object? value, BindingFlags invokeAttr, Binder? binder, object[]? index, CultureInfo? culture) + public override void SetValue(object? obj, object? value, BindingFlags invokeAttr, Binder? binder, object?[]? index, CultureInfo? culture) { MethodInfo? m = GetSetMethod(true); diff --git a/src/System.Private.CoreLib/src/System/RtType.cs b/src/System.Private.CoreLib/src/System/RtType.cs index c22229a4ea91..ead65ce40204 100644 --- a/src/System.Private.CoreLib/src/System/RtType.cs +++ b/src/System.Private.CoreLib/src/System/RtType.cs @@ -3841,7 +3841,7 @@ public override MemberInfo[] GetDefaultMembers() [DebuggerHidden] public override object? InvokeMember( string name, BindingFlags bindingFlags, Binder? binder, object? target, - object[]? providedArgs, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParams) + object?[]? providedArgs, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParams) { if (IsGenericParameter) throw new InvalidOperationException(SR.Arg_GenericParameter); @@ -3986,7 +3986,7 @@ public override MemberInfo[] GetDefaultMembers() } else if (flds.Length > 0) { - selFld = binder.BindToField(bindingFlags, flds, IsGetField ? Empty.Value : providedArgs![0], culture); + selFld = binder.BindToField(bindingFlags, flds, IsGetField ? Empty.Value : providedArgs![0]!, culture); } if (selFld != null) @@ -4013,7 +4013,7 @@ public override MemberInfo[] GetDefaultMembers() { try { - idx[i] = ((IConvertible)providedArgs![i]).ToInt32(null); + idx[i] = ((IConvertible)providedArgs![i]!).ToInt32(null); } catch (InvalidCastException) { @@ -4614,7 +4614,7 @@ internal static object CreateEnum(RuntimeType enumType, long value) #if FEATURE_COMINTEROP [MethodImpl(MethodImplOptions.InternalCall)] private extern object InvokeDispMethod( - string name, BindingFlags invokeAttr, object target, object[]? args, + string name, BindingFlags invokeAttr, object target, object?[]? args, bool[]? byrefModifiers, int culture, string[]? namedParameters); #endif // FEATURE_COMINTEROP diff --git a/src/System.Private.CoreLib/src/System/StartupHookProvider.cs b/src/System.Private.CoreLib/src/System/StartupHookProvider.cs index 608a0d052d87..220c7bac4bb2 100644 --- a/src/System.Private.CoreLib/src/System/StartupHookProvider.cs +++ b/src/System.Private.CoreLib/src/System/StartupHookProvider.cs @@ -126,7 +126,7 @@ private static void CallStartupHook(StartupHookNameOrPath startupHook) } Debug.Assert(assembly != null); - Type type = assembly.GetType(StartupHookTypeName, throwOnError: true); + Type type = assembly.GetType(StartupHookTypeName, throwOnError: true)!; // Look for a static method without any parameters MethodInfo? initializeMethod = type.GetMethod(InitializeMethodName, From 9d98b4875ae456d3f58cae75c009afabf19d0d15 Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Mon, 3 Jun 2019 23:37:44 -0700 Subject: [PATCH 2/5] PR Feedback --- .../System/Diagnostics/Tracing/EventSource.cs | 10 +++++----- .../shared/System/Nullable.cs | 2 -- .../shared/System/Reflection/Assembly.cs | 2 +- .../shared/System/Reflection/AssemblyName.cs | 2 +- .../Reflection/CustomAttributeNamedArgument.cs | 2 +- .../Reflection/CustomAttributeTypedArgument.cs | 2 +- .../shared/System/Reflection/Emit/Opcode.cs | 2 -- .../shared/System/Reflection/FieldInfo.cs | 4 ++-- .../shared/System/Reflection/MethodBase.cs | 2 +- .../System/Threading/Tasks/TaskContinuation.cs | 4 +--- .../shared/System/Threading/Tasks/ValueTask.cs | 2 -- .../shared/System/Type.Enum.cs | 2 +- .../src/System/Reflection/AssemblyName.CoreCLR.cs | 2 +- .../src/System/Reflection/CustomAttribute.cs | 2 +- .../src/System/Reflection/Emit/AssemblyBuilder.cs | 2 +- .../System/Reflection/Emit/ConstructorBuilder.cs | 5 +---- .../System/Reflection/Emit/DynamicILGenerator.cs | 7 ------- .../src/System/Reflection/Emit/MethodBuilder.cs | 15 ++------------- .../Reflection/Emit/MethodBuilderInstantiation.cs | 2 +- .../System/Reflection/Emit/ParameterBuilder.cs | 2 +- .../src/System/Reflection/Emit/SymbolMethod.cs | 8 ++++---- .../src/System/Reflection/Emit/TypeBuilder.cs | 4 +--- .../Emit/XXXOnTypeBuilderInstantiation.cs | 8 +++----- .../src/System/Reflection/MdFieldInfo.cs | 4 ---- .../src/System/Reflection/RtFieldInfo.cs | 2 -- .../src/System/Reflection/RuntimeAssembly.cs | 4 ++-- .../System/Reflection/RuntimeConstructorInfo.cs | 2 -- .../src/System/Reflection/RuntimeMethodInfo.cs | 15 +++------------ .../src/System/RuntimeHandles.cs | 8 ++++---- .../src/System/ValueType.cs | 2 +- 30 files changed, 40 insertions(+), 90 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs index 6412676f26ee..b316cf936a1c 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs @@ -3521,19 +3521,19 @@ private static void AddProviderEnumKind(ManifestBuilder manifest, FieldInfo stat if (!reflectionOnly && (staticFieldType == typeof(EventOpcode)) || AttributeTypeNamesMatch(staticFieldType, typeof(EventOpcode))) { if (providerEnumKind != "Opcodes") goto Error; - int value = (int)staticField.GetRawConstantValue(); + int value = (int)staticField.GetRawConstantValue()!; manifest.AddOpcode(staticField.Name, value); } else if (!reflectionOnly && (staticFieldType == typeof(EventTask)) || AttributeTypeNamesMatch(staticFieldType, typeof(EventTask))) { if (providerEnumKind != "Tasks") goto Error; - int value = (int)staticField.GetRawConstantValue(); + int value = (int)staticField.GetRawConstantValue()!; manifest.AddTask(staticField.Name, value); } else if (!reflectionOnly && (staticFieldType == typeof(EventKeywords)) || AttributeTypeNamesMatch(staticFieldType, typeof(EventKeywords))) { if (providerEnumKind != "Keywords") goto Error; - ulong value = unchecked((ulong)(long)staticField.GetRawConstantValue()); + ulong value = unchecked((ulong)(long)staticField.GetRawConstantValue()!); manifest.AddKeyword(staticField.Name, value); } #if FEATURE_MANAGED_ETW_CHANNELS && FEATURE_ADVANCED_MANAGED_ETW_CHANNELS @@ -3730,7 +3730,7 @@ private static int GetHelperCallFirstArg(MethodInfo method) #if ES_BUILD_STANDALONE (new ReflectionPermission(ReflectionPermissionFlag.MemberAccess)).Assert(); #endif - byte[] instrs = method.GetMethodBody().GetILAsByteArray()!; + byte[] instrs = method.GetMethodBody()!.GetILAsByteArray()!; int retVal = -1; for (int idx = 0; idx < instrs.Length;) { @@ -5828,7 +5828,7 @@ private string CreateManifestString() bool anyValuesWritten = false; foreach (FieldInfo staticField in staticFields) { - object constantValObj = staticField.GetRawConstantValue(); + object? constantValObj = staticField.GetRawConstantValue(); if (constantValObj != null) { diff --git a/src/System.Private.CoreLib/shared/System/Nullable.cs b/src/System.Private.CoreLib/shared/System/Nullable.cs index 8d308a758deb..a34769645895 100644 --- a/src/System.Private.CoreLib/shared/System/Nullable.cs +++ b/src/System.Private.CoreLib/shared/System/Nullable.cs @@ -71,12 +71,10 @@ public override int GetHashCode() return hasValue ? value.GetHashCode() : 0; } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override string? ToString() { return hasValue ? value.ToString() : ""; } -#pragma warning restore CS8609 [NonVersionable] public static implicit operator Nullable(T value) diff --git a/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs b/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs index aa9cd55055f2..569c5f5c8cae 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs @@ -119,7 +119,7 @@ public virtual Type[] GetTypes() public virtual event ModuleResolveEventHandler ModuleResolve { add { throw NotImplemented.ByDesign; } remove { throw NotImplemented.ByDesign; } } - public virtual Module? ManifestModule { get { throw NotImplemented.ByDesign; } } + public virtual Module ManifestModule { get { throw NotImplemented.ByDesign; } } public virtual Module? GetModule(string name) { throw NotImplemented.ByDesign; } public Module[] GetModules() => GetModules(getResourceModules: false); diff --git a/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs b/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs index 9bc3ea099f90..3de53a141907 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs @@ -226,7 +226,7 @@ public string FullName if (this.Name == null) return string.Empty; // Do not call GetPublicKeyToken() here - that latches the result into AssemblyName which isn't a side effect we want. - byte[] pkt = _publicKeyToken ?? ComputePublicKeyToken(); + byte[]? pkt = _publicKeyToken ?? ComputePublicKeyToken(); return AssemblyNameFormatter.ComputeDisplayName(Name, Version, CultureName, pkt, Flags, ContentType); } } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeNamedArgument.cs b/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeNamedArgument.cs index ee30573b7619..42d280ccd9b3 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeNamedArgument.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeNamedArgument.cs @@ -47,7 +47,7 @@ public CustomAttributeNamedArgument(MemberInfo memberInfo, CustomAttributeTypedA public override string ToString() { if (m_memberInfo == null) - return base.ToString(); + return base.ToString()!; return string.Format("{0} = {1}", MemberInfo.Name, TypedValue.ToString(ArgumentType != typeof(object))); } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeTypedArgument.cs b/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeTypedArgument.cs index 7ccdbe5ba499..6247d73fb8a1 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeTypedArgument.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeTypedArgument.cs @@ -41,7 +41,7 @@ public CustomAttributeTypedArgument(object value) internal string ToString(bool typed) { if (m_argumentType == null) - return base.ToString(); + return base.ToString()!; if (ArgumentType.IsEnum) return string.Format(typed ? "{0}" : "({1}){0}", Value, ArgumentType.FullName); diff --git a/src/System.Private.CoreLib/shared/System/Reflection/Emit/Opcode.cs b/src/System.Private.CoreLib/shared/System/Reflection/Emit/Opcode.cs index b9b799d2f31b..a2d5792c6ab6 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/Emit/Opcode.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/Emit/Opcode.cs @@ -183,11 +183,9 @@ public override int GetHashCode() return Value; } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override string? ToString() { return Name; } -#pragma warning restore CS8609 } } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs index 7af1c782f1fc..cbb04d54a42b 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs @@ -72,9 +72,9 @@ protected FieldInfo() { } [CLSCompliant(false)] public virtual void SetValueDirect(TypedReference obj, object value) { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); } [CLSCompliant(false)] - public virtual object GetValueDirect(TypedReference obj) { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); } + public virtual object? GetValueDirect(TypedReference obj) { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); } - public virtual object GetRawConstantValue() { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); } + public virtual object? GetRawConstantValue() { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); } public virtual Type[] GetOptionalCustomModifiers() { throw NotImplemented.ByDesign; } public virtual Type[] GetRequiredCustomModifiers() { throw NotImplemented.ByDesign; } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs b/src/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs index dcc268228e28..96ca09cf35c8 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs @@ -16,7 +16,7 @@ protected MethodBase() { } public abstract MethodAttributes Attributes { get; } public virtual MethodImplAttributes MethodImplementationFlags => GetMethodImplementationFlags(); public abstract MethodImplAttributes GetMethodImplementationFlags(); - public virtual MethodBody GetMethodBody() { throw new InvalidOperationException(); } + public virtual MethodBody? GetMethodBody() { throw new InvalidOperationException(); } public virtual CallingConventions CallingConvention => CallingConventions.Standard; public bool IsAbstract => (Attributes & MethodAttributes.Abstract) != 0; diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs index 24c756e34d62..f275fd95491a 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs @@ -256,7 +256,7 @@ protected static void InlineIfPossibleOrElseQueue(Task task, bool needsProtectio #if PROJECTN [DependencyReductionRoot] #endif - internal abstract Delegate[] GetDelegateContinuationsForDebugger(); + internal abstract Delegate[]? GetDelegateContinuationsForDebugger(); } /// Provides the standard implementation of a task continuation. @@ -341,7 +341,6 @@ internal override void Run(Task completedTask, bool canInlineContinuationTask) else continuationTask.InternalCancel(false); } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) internal override Delegate[]? GetDelegateContinuationsForDebugger() { if (m_task.m_action == null) @@ -351,7 +350,6 @@ internal override void Run(Task completedTask, bool canInlineContinuationTask) return new Delegate[] { m_task.m_action }; } -#pragma warning restore CS8609 } diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs index 123800914be5..75c6fd9a325c 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs @@ -776,7 +776,6 @@ public TResult Result public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) => new ConfiguredValueTaskAwaitable(new ValueTask(_obj, _result, _token, continueOnCapturedContext)); -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) /// Gets a string-representation of this . public override string? ToString() { @@ -791,6 +790,5 @@ public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCaptu return string.Empty; } -#pragma warning restore CS8609 } } diff --git a/src/System.Private.CoreLib/shared/System/Type.Enum.cs b/src/System.Private.CoreLib/shared/System/Type.Enum.cs index ac610e848437..308b57aefe92 100644 --- a/src/System.Private.CoreLib/shared/System/Type.Enum.cs +++ b/src/System.Private.CoreLib/shared/System/Type.Enum.cs @@ -121,7 +121,7 @@ private void GetEnumData(out string[] enumNames, out Array enumValues) for (int i = 0; i < flds.Length; i++) { names[i] = flds[i].Name; - values[i] = flds[i].GetRawConstantValue(); + values[i] = flds[i].GetRawConstantValue()!; } // Insertion Sort these values in ascending order. diff --git a/src/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs index 6b0b049fe3d3..d57ee6410fca 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs @@ -62,7 +62,7 @@ internal static AssemblyName GetFileInformationCore(string assemblyFile) } [MethodImpl(MethodImplOptions.InternalCall)] - private extern byte[] ComputePublicKeyToken(); + private extern byte[]? ComputePublicKeyToken(); internal void SetProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm) { diff --git a/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs index 9cd4b90d62fc..999327c6f7ee 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs @@ -112,7 +112,7 @@ internal static IList GetCustomAttributesInternal(RuntimeAs // No pseudo attributes for RuntimeAssembly - return GetCustomAttributes((RuntimeModule)target.ManifestModule!, RuntimeAssembly.GetToken(target.GetNativeHandle())); + return GetCustomAttributes((RuntimeModule)target.ManifestModule, RuntimeAssembly.GetToken(target.GetNativeHandle())); } internal static IList GetCustomAttributesInternal(RuntimeParameterInfo target) diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs index ce0438d39648..072b3605ee07 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs @@ -497,7 +497,7 @@ public override FileStream[] GetFiles(bool getResourceModules) return InternalAssembly.GetType(name, throwOnError, ignoreCase); } - public override Module? ManifestModule => _manifestModuleBuilder.InternalModule; + public override Module ManifestModule => _manifestModuleBuilder.InternalModule; public override bool ReflectionOnly => InternalAssembly.ReflectionOnly; diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.cs index 0ee2ecd2838f..4f6e60c60450 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.cs @@ -190,13 +190,10 @@ public Module GetModule() return m_methodBuilder.GetModule(); } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) - // This always returns null. Is that what we want? - internal override Type? GetReturnType() + internal override Type GetReturnType() { return m_methodBuilder.ReturnType; } -#pragma warning restore CS8609 public string Signature { diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs index d9a702b3e75e..10d67104f657 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs @@ -738,12 +738,10 @@ internal override byte[] GetLocalsSignature() return m_localSignature; } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) internal override byte[]? GetRawEHInfo() { return m_exceptionHeader; } -#pragma warning restore CS8609 internal override unsafe void GetEHInfo(int excNumber, void* exc) { @@ -770,10 +768,7 @@ internal override unsafe void GetEHInfo(int excNumber, void* exc) } } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) internal override string? GetStringLiteral(int token) { return m_scope.GetString(token); } -#pragma warning restore CS8609 - internal override void ResolveToken(int token, out IntPtr typeHandle, out IntPtr methodHandle, out IntPtr fieldHandle) { @@ -839,12 +834,10 @@ internal override void ResolveToken(int token, out IntPtr typeHandle, out IntPtr } } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) internal override byte[]? ResolveSignature(int token, int fromMethod) { return m_scope.ResolveSignature(token, fromMethod); } -#pragma warning restore CS8609 internal override MethodInfo GetDynamicMethod() { diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs index 1b5706d3493c..51f30ab9f3d0 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs @@ -86,16 +86,7 @@ internal MethodBuilder(string name, MethodAttributes attributes, CallingConventi m_strName = name; m_module = mod; m_containingType = type; - - - if (returnType == null) - { - m_returnType = typeof(void); - } - else - { - m_returnType = returnType; - } + m_returnType = returnType ?? typeof(void); if ((attributes & MethodAttributes.Static) == 0) { @@ -649,9 +640,7 @@ public override bool IsDefined(Type attributeType, bool inherit) public override bool IsGenericMethod { get { return m_inst != null; } } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) - public override Type[]? GetGenericArguments() { return m_inst; } -#pragma warning restore CS8609 + public override Type[] GetGenericArguments() => m_inst ?? Array.Empty(); public override MethodInfo MakeGenericMethod(params Type[] typeArguments) { diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilderInstantiation.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilderInstantiation.cs index 458ed260e127..00c5412b03e8 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilderInstantiation.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilderInstantiation.cs @@ -96,7 +96,7 @@ public override Type ReturnType } } - public override ParameterInfo ReturnParameter { get { throw new NotSupportedException(); } } + public override ParameterInfo? ReturnParameter { get { throw new NotSupportedException(); } } public override ICustomAttributeProvider ReturnTypeCustomAttributes { get { throw new NotSupportedException(); } } public override MethodInfo GetBaseDefinition() { throw new NotSupportedException(); } #endregion diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.cs index ed96eeedeab0..790175c6fa3a 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.cs @@ -14,7 +14,7 @@ public virtual void SetConstant(object? defaultValue) TypeBuilder.SetConstantValue( _methodBuilder.GetModuleBuilder(), _token.Token, - _position == 0 ? _methodBuilder.ReturnType! : _methodBuilder.m_parameterTypes![_position - 1], + _position == 0 ? _methodBuilder.ReturnType : _methodBuilder.m_parameterTypes![_position - 1], defaultValue); } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolMethod.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolMethod.cs index 87775e6b2400..a2573cc0fb59 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolMethod.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolMethod.cs @@ -13,7 +13,7 @@ internal sealed class SymbolMethod : MethodInfo private Type m_containingType; private string m_name; private CallingConventions m_callingConvention; - private Type? m_returnType; + private Type m_returnType; private MethodToken m_mdMethod; private Type[] m_parameterTypes; private SignatureHelper m_signature; @@ -33,7 +33,7 @@ internal SymbolMethod(ModuleBuilder mod, MethodToken token, Type arrayClass, str m_mdMethod = token; // The ParameterTypes are also a bit interesting in that they may be unbaked TypeBuilders. - m_returnType = returnType; + m_returnType = returnType ?? typeof(void); if (parameterTypes != null) { m_parameterTypes = new Type[parameterTypes.Length]; @@ -118,8 +118,7 @@ public override RuntimeMethodHandle MethodHandle #endregion #region MethodInfo Overrides -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) - public override Type? ReturnType + public override Type ReturnType { get { @@ -127,6 +126,7 @@ public override Type? ReturnType } } +#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override ICustomAttributeProvider? ReturnTypeCustomAttributes { get { return null; } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs index 9d15357ef3ad..806308fe3793 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs @@ -1250,9 +1250,7 @@ public override Type MakeGenericType(params Type[] typeArguments) return TypeBuilderInstantiation.MakeGenericType(this, typeArguments); } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) - public override Type[]? GetGenericArguments() { return m_inst; } -#pragma warning restore CS8609 + public override Type[] GetGenericArguments() => m_inst ?? Array.Empty(); // If a TypeBuilder is generic, it must be a generic type definition // All instantiated generic types are TypeBuilderInstantiation. diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs index 65430397ef4b..750c3e81f20c 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs @@ -75,7 +75,7 @@ public override MethodInfo MakeGenericMethod(params Type[] typeArgs) #region Public Abstract\Virtual Members public override Type ReturnType { get { return m_method.ReturnType; } } - public override ParameterInfo ReturnParameter { get { throw new NotSupportedException(); } } + public override ParameterInfo? ReturnParameter { get { throw new NotSupportedException(); } } public override ICustomAttributeProvider ReturnTypeCustomAttributes { get { throw new NotSupportedException(); } } public override MethodInfo GetBaseDefinition() { throw new NotSupportedException(); } #endregion @@ -110,12 +110,10 @@ internal override Type[] GetParameterTypes() return m_ctor.GetParameterTypes(); } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) - internal override Type? GetReturnType() + internal override Type GetReturnType() { - return DeclaringType; + return m_type; } -#pragma warning restore CS8609 #region MemberInfo Overrides public override MemberTypes MemberType { get { return m_ctor.MemberType; } } diff --git a/src/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs index 9e7dd0a51d41..f4cee246cc16 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs @@ -66,14 +66,12 @@ public override string Name public override bool IsSecuritySafeCritical { get { return DeclaringType!.IsSecuritySafeCritical; } } public override bool IsSecurityTransparent { get { return DeclaringType!.IsSecurityTransparent; } } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) [DebuggerStepThroughAttribute] [Diagnostics.DebuggerHidden] public override object? GetValueDirect(TypedReference obj) { return GetValue(null); } -#pragma warning restore CS8609 [DebuggerStepThroughAttribute] [Diagnostics.DebuggerHidden] @@ -89,9 +87,7 @@ public override void SetValueDirect(TypedReference obj, object value) return GetValue(false); } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override object? GetRawConstantValue() { return GetValue(true); } -#pragma warning restore CS8609 private object? GetValue(bool raw) { diff --git a/src/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs index a5dbc61c4ab5..ca75d2516607 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs @@ -188,7 +188,6 @@ internal override RuntimeModule GetRuntimeModule() public override object GetRawConstantValue() { throw new InvalidOperationException(); } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) [DebuggerStepThroughAttribute] [Diagnostics.DebuggerHidden] public override object? GetValueDirect(TypedReference obj) @@ -202,7 +201,6 @@ internal override RuntimeModule GetRuntimeModule() return RuntimeFieldHandle.GetValueDirect(this, (RuntimeType)FieldType, &obj, (RuntimeType?)DeclaringType); } } -#pragma warning restore CS8609 [DebuggerStepThroughAttribute] [Diagnostics.DebuggerHidden] diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index d5eda80f7de6..9239b12f329d 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -103,7 +103,7 @@ public override AssemblyName GetName(bool copiedName) GetFlags() | AssemblyNameFlags.PublicKey, null); // strong name key pair - Module? manifestModule = ManifestModule; + Module manifestModule = ManifestModule; if (manifestModule != null) { if (manifestModule.MDStreamVersion > 0x10000) @@ -271,7 +271,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont throw new PlatformNotSupportedException(); } - public override Module? ManifestModule + public override Module ManifestModule { get { diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs index 4c95894dc6bb..5d8be5db3ba1 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs @@ -376,7 +376,6 @@ internal void ThrowNoInvokeException() return RuntimeMethodHandle.InvokeMethod(obj, null, sig, false, wrapExceptions); } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override MethodBody? GetMethodBody() { RuntimeMethodBody? mb = RuntimeMethodHandle.GetMethodBody(this, ReflectedTypeInternal); @@ -384,7 +383,6 @@ internal void ThrowNoInvokeException() mb._methodBase = this; return mb; } -#pragma warning restore CS8609 public override bool IsSecurityCritical { diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs index 7ff457b4859b..4378c49074cb 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs @@ -394,7 +394,6 @@ public override CallingConventions CallingConvention } } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override MethodBody? GetMethodBody() { RuntimeMethodBody? mb = RuntimeMethodHandle.GetMethodBody(this, ReflectedTypeInternal); @@ -402,7 +401,6 @@ public override CallingConventions CallingConvention mb._methodBase = this; return mb; } -#pragma warning restore CS8609 #endregion @@ -522,16 +520,9 @@ public override ICustomAttributeProvider ReturnTypeCustomAttributes get { return ReturnParameter; } } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) - public override ParameterInfo ReturnParameter - { - get - { - FetchReturnParameter(); - return (m_returnParameter as ParameterInfo)!; - } - } -#pragma warning restore CS8609 +#pragma warning disable CS6809 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) + public override ParameterInfo ReturnParameter => FetchReturnParameter(); +#pragma warning restore CS6809 public override bool IsCollectible => (RuntimeMethodHandle.GetIsCollectible(new RuntimeMethodHandleInternal(m_handle)) != Interop.BOOL.FALSE); diff --git a/src/System.Private.CoreLib/src/System/RuntimeHandles.cs b/src/System.Private.CoreLib/src/System/RuntimeHandles.cs index 6555a5a14db9..63863277fcc5 100644 --- a/src/System.Private.CoreLib/src/System/RuntimeHandles.cs +++ b/src/System.Private.CoreLib/src/System/RuntimeHandles.cs @@ -1545,15 +1545,15 @@ internal struct CORINFO_EH_CLAUSE } // ILHeader info - internal abstract RuntimeType GetJitContext(out int securityControlFlags); + internal abstract RuntimeType? GetJitContext(out int securityControlFlags); internal abstract byte[] GetCodeInfo(out int stackSize, out int initLocals, out int EHCount); internal abstract byte[] GetLocalsSignature(); internal abstract unsafe void GetEHInfo(int EHNumber, void* exception); - internal abstract byte[] GetRawEHInfo(); + internal abstract byte[]? GetRawEHInfo(); // token resolution - internal abstract string GetStringLiteral(int token); + internal abstract string? GetStringLiteral(int token); internal abstract void ResolveToken(int token, out IntPtr typeHandle, out IntPtr methodHandle, out IntPtr fieldHandle); - internal abstract byte[] ResolveSignature(int token, int fromMethod); + internal abstract byte[]? ResolveSignature(int token, int fromMethod); // internal abstract MethodInfo GetDynamicMethod(); } diff --git a/src/System.Private.CoreLib/src/System/ValueType.cs b/src/System.Private.CoreLib/src/System/ValueType.cs index 34edc8f68ec2..405b88bb50cf 100644 --- a/src/System.Private.CoreLib/src/System/ValueType.cs +++ b/src/System.Private.CoreLib/src/System/ValueType.cs @@ -88,7 +88,7 @@ public override bool Equals(object? obj) [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern int GetHashCodeOfPtr(IntPtr ptr); - public override string ToString() + public override string? ToString() { return this.GetType().ToString(); } From 30402ab51681ee7d256a69acff6c0529d7eb4c6c Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Tue, 4 Jun 2019 14:09:50 -0700 Subject: [PATCH 3/5] PR Feedback --- src/System.Private.CoreLib/shared/System/AppContext.cs | 2 +- .../shared/System/Reflection/MethodInfo.cs | 2 +- .../shared/System/Reflection/ParameterInfo.cs | 2 +- .../shared/System/String.Manipulation.cs | 10 ++-------- .../src/System/AppContext.CoreCLR.cs | 4 ++-- .../src/System/Reflection/Emit/DynamicMethod.cs | 6 +++--- .../src/System/Reflection/Emit/MethodBuilder.cs | 2 +- .../Reflection/Emit/MethodBuilderInstantiation.cs | 2 +- .../src/System/Reflection/Emit/ModuleBuilder.cs | 2 +- .../Reflection/Emit/XXXOnTypeBuilderInstantiation.cs | 2 +- .../src/System/Reflection/RuntimeAssembly.cs | 9 +++------ .../src/System/Reflection/RuntimeMethodInfo.cs | 2 -- src/vm/runtimehandles.cpp | 3 --- 13 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/AppContext.cs b/src/System.Private.CoreLib/shared/System/AppContext.cs index 730b63091db9..758230178da7 100644 --- a/src/System.Private.CoreLib/shared/System/AppContext.cs +++ b/src/System.Private.CoreLib/shared/System/AppContext.cs @@ -24,7 +24,7 @@ public static string BaseDirectory // The value of APP_CONTEXT_BASE_DIRECTORY key has to be a string and it is not allowed to be any other type. // Otherwise the caller will get invalid cast exception return (string?)GetData("APP_CONTEXT_BASE_DIRECTORY") ?? - (s_defaultBaseDirectory ?? (s_defaultBaseDirectory = GetBaseDirectoryCore())) ?? string.Empty; + s_defaultBaseDirectory ?? (s_defaultBaseDirectory = GetBaseDirectoryCore()); } } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs index 5a04921a74b8..3624475b1654 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs @@ -12,7 +12,7 @@ protected MethodInfo() { } public override MemberTypes MemberType => MemberTypes.Method; - public virtual ParameterInfo? ReturnParameter { get { throw NotImplemented.ByDesign; } } + public virtual ParameterInfo ReturnParameter { get { throw NotImplemented.ByDesign; } } public virtual Type ReturnType { get { throw NotImplemented.ByDesign; } } public override Type[] GetGenericArguments() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/ParameterInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/ParameterInfo.cs index 4ad145d9e924..eb0692ec18f6 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/ParameterInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/ParameterInfo.cs @@ -69,7 +69,7 @@ public object GetRealObject(StreamingContext context) if (PositionImpl == -1) { if (MemberImpl.MemberType == MemberTypes.Method) - return ((MethodInfo)MemberImpl).ReturnParameter!; + return ((MethodInfo)MemberImpl).ReturnParameter; else throw new SerializationException(SR.Serialization_BadParameterInfo); } diff --git a/src/System.Private.CoreLib/shared/System/String.Manipulation.cs b/src/System.Private.CoreLib/shared/System/String.Manipulation.cs index 1cd2b74b558b..564fca0dcd97 100644 --- a/src/System.Private.CoreLib/shared/System/String.Manipulation.cs +++ b/src/System.Private.CoreLib/shared/System/String.Manipulation.cs @@ -1696,10 +1696,7 @@ private unsafe string InternalSubString(int startIndex, int length) } // Creates a copy of this string in lower case. The culture is set by culture. - public string ToLower() - { - return CultureInfo.CurrentCulture.TextInfo.ToLower(this); - } + public string ToLower() => ToLower(null); // Creates a copy of this string in lower case. The culture is set by culture. public string ToLower(CultureInfo? culture) @@ -1714,10 +1711,7 @@ public string ToLowerInvariant() return CultureInfo.InvariantCulture.TextInfo.ToLower(this); } - public string ToUpper() - { - return CultureInfo.CurrentCulture.TextInfo.ToUpper(this); - } + public string ToUpper() => ToUpper(null); // Creates a copy of this string in upper case. The culture is set by culture. public string ToUpper(CultureInfo? culture) diff --git a/src/System.Private.CoreLib/src/System/AppContext.CoreCLR.cs b/src/System.Private.CoreLib/src/System/AppContext.CoreCLR.cs index 84313e341e3b..572653e17f32 100644 --- a/src/System.Private.CoreLib/src/System/AppContext.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/AppContext.CoreCLR.cs @@ -17,13 +17,13 @@ internal static unsafe void Setup(char** pNames, char** pValues, int count) } } - private static string? GetBaseDirectoryCore() + private static string GetBaseDirectoryCore() { // Fallback path for hosts that do not set APP_CONTEXT_BASE_DIRECTORY explicitly string? directory = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); if (directory != null && !Path.EndsInDirectorySeparator(directory)) directory += Path.DirectorySeparatorChar; - return directory; + return directory ?? string.Empty; } } } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs index 9b3fab35addc..9901d9cbf23c 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs @@ -492,7 +492,7 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit) public override Type ReturnType { get { return m_dynMethod.ReturnType; } } - public override ParameterInfo? ReturnParameter { get { return m_dynMethod.ReturnParameter; } } + public override ParameterInfo ReturnParameter { get { return m_dynMethod.ReturnParameter; } } public override ICustomAttributeProvider ReturnTypeCustomAttributes { get { return m_dynMethod.ReturnTypeCustomAttributes; } } @@ -714,9 +714,9 @@ public override Type ReturnType } } - public override ParameterInfo? ReturnParameter + public override ParameterInfo ReturnParameter { - get { return null; } + get { return new RuntimeParameterInfo(this, null, m_owner.m_returnType, -1); } } public override ICustomAttributeProvider ReturnTypeCustomAttributes diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs index 51f30ab9f3d0..29fbc8e5a3c9 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs @@ -599,7 +599,7 @@ public override ParameterInfo[] GetParameters() return rmi.GetParameters(); } - public override ParameterInfo? ReturnParameter + public override ParameterInfo ReturnParameter { get { diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilderInstantiation.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilderInstantiation.cs index 00c5412b03e8..458ed260e127 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilderInstantiation.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilderInstantiation.cs @@ -96,7 +96,7 @@ public override Type ReturnType } } - public override ParameterInfo? ReturnParameter { get { throw new NotSupportedException(); } } + public override ParameterInfo ReturnParameter { get { throw new NotSupportedException(); } } public override ICustomAttributeProvider ReturnTypeCustomAttributes { get { throw new NotSupportedException(); } } public override MethodInfo GetBaseDefinition() { throw new NotSupportedException(); } #endregion diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs index f6911ea26170..042cf510bd16 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs @@ -1232,7 +1232,7 @@ private MethodToken GetMethodTokenNoLock(MethodInfo method, bool getGenericTypeD { sigHelp = SignatureHelper.GetMethodSigHelper( this, method.CallingConvention, method.ReturnType, - method.ReturnParameter!.GetRequiredCustomModifiers(), method.ReturnParameter.GetOptionalCustomModifiers(), + method.ReturnParameter.GetRequiredCustomModifiers(), method.ReturnParameter.GetOptionalCustomModifiers(), parameterTypes, requiredCustomModifiers, optionalCustomModifiers); } catch (NotImplementedException) diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs index 750c3e81f20c..532accba5dc9 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs @@ -75,7 +75,7 @@ public override MethodInfo MakeGenericMethod(params Type[] typeArgs) #region Public Abstract\Virtual Members public override Type ReturnType { get { return m_method.ReturnType; } } - public override ParameterInfo? ReturnParameter { get { throw new NotSupportedException(); } } + public override ParameterInfo ReturnParameter { get { throw new NotSupportedException(); } } public override ICustomAttributeProvider ReturnTypeCustomAttributes { get { throw new NotSupportedException(); } } public override MethodInfo GetBaseDefinition() { throw new NotSupportedException(); } #endregion diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index 9239b12f329d..8c60a92427bc 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -104,13 +104,10 @@ public override AssemblyName GetName(bool copiedName) null); // strong name key pair Module manifestModule = ManifestModule; - if (manifestModule != null) + if (manifestModule.MDStreamVersion > 0x10000) { - if (manifestModule.MDStreamVersion > 0x10000) - { - manifestModule.GetPEKind(out PortableExecutableKinds pek, out ImageFileMachine ifm); - an.SetProcArchIndex(pek, ifm); - } + manifestModule.GetPEKind(out PortableExecutableKinds pek, out ImageFileMachine ifm); + an.SetProcArchIndex(pek, ifm); } return an; } diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs index 4378c49074cb..84546a926d8f 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs @@ -520,9 +520,7 @@ public override ICustomAttributeProvider ReturnTypeCustomAttributes get { return ReturnParameter; } } -#pragma warning disable CS6809 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) public override ParameterInfo ReturnParameter => FetchReturnParameter(); -#pragma warning restore CS6809 public override bool IsCollectible => (RuntimeMethodHandle.GetIsCollectible(new RuntimeMethodHandleInternal(m_handle)) != Interop.BOOL.FALSE); diff --git a/src/vm/runtimehandles.cpp b/src/vm/runtimehandles.cpp index 7d18e7a31d32..c22be0fd1021 100644 --- a/src/vm/runtimehandles.cpp +++ b/src/vm/runtimehandles.cpp @@ -2754,9 +2754,6 @@ FCIMPL1(ReflectModuleBaseObject*, AssemblyHandle::GetManifestModule, AssemblyBas DomainAssembly *pAssembly = refAssembly->GetDomainAssembly(); Assembly* currentAssembly = pAssembly->GetCurrentAssembly(); - if (currentAssembly == NULL) - return NULL; - Module *pModule = currentAssembly->GetManifestModule(); DomainFile * pDomainFile = pModule->GetDomainFile(); From b9e65b9ae77fa06a51d6e51ee92426beddd61e58 Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Tue, 4 Jun 2019 15:26:31 -0700 Subject: [PATCH 4/5] More PR Feedback --- .../System.Private.CoreLib.csproj | 1 + .../ManifestBasedResourceGroveler.cs | 16 ++++---- .../System/Reflection/Emit/DynamicMethod.cs | 37 +------------------ .../System/Reflection/Emit/EmptyCAHolder.cs | 17 +++++++++ .../System/Reflection/Emit/MethodBuilder.cs | 10 +---- .../System/Reflection/Emit/SymbolMethod.cs | 7 +--- 6 files changed, 30 insertions(+), 58 deletions(-) create mode 100644 src/System.Private.CoreLib/src/System/Reflection/Emit/EmptyCAHolder.cs diff --git a/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/System.Private.CoreLib.csproj index b3646fc0571f..fa59f80d7452 100644 --- a/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -200,6 +200,7 @@ + diff --git a/src/System.Private.CoreLib/shared/System/Resources/ManifestBasedResourceGroveler.cs b/src/System.Private.CoreLib/shared/System/Resources/ManifestBasedResourceGroveler.cs index a03ec6622880..740429974f0a 100644 --- a/src/System.Private.CoreLib/shared/System/Resources/ManifestBasedResourceGroveler.cs +++ b/src/System.Private.CoreLib/shared/System/Resources/ManifestBasedResourceGroveler.cs @@ -444,15 +444,17 @@ private void HandleSatelliteMissing() satAssemName += ", Version=" + _mediator.SatelliteContractVersion.ToString(); } - byte[] token = _mediator.MainAssembly.GetName().GetPublicKeyToken()!; - - int iLen = token.Length; - StringBuilder publicKeyTok = new StringBuilder(iLen * 2); - for (int i = 0; i < iLen; i++) + byte[]? token = _mediator.MainAssembly.GetName().GetPublicKeyToken(); + if (token != null) { - publicKeyTok.Append(token[i].ToString("x", CultureInfo.InvariantCulture)); + int iLen = token.Length; + StringBuilder publicKeyTok = new StringBuilder(iLen * 2); + for (int i = 0; i < iLen; i++) + { + publicKeyTok.Append(token[i].ToString("x", CultureInfo.InvariantCulture)); + } + satAssemName += ", PublicKeyToken=" + publicKeyTok; } - satAssemName += ", PublicKeyToken=" + publicKeyTok; Debug.Assert(_mediator.NeutralResourcesCulture != null); string missingCultureName = _mediator.NeutralResourcesCulture.Name; diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs index 9901d9cbf23c..c012744de4e8 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs @@ -719,14 +719,7 @@ public override ParameterInfo ReturnParameter get { return new RuntimeParameterInfo(this, null, m_owner.m_returnType, -1); } } - public override ICustomAttributeProvider ReturnTypeCustomAttributes - { - get { return GetEmptyCAHolder(); } - } - - // - // private implementation - // + public override ICustomAttributeProvider ReturnTypeCustomAttributes => new EmptyCAHolder(); internal RuntimeParameterInfo[] LoadParameters() { @@ -742,34 +735,6 @@ internal RuntimeParameterInfo[] LoadParameters() } return m_parameters; } - - // private implementation of CA for the return type - private ICustomAttributeProvider GetEmptyCAHolder() - { - return new EmptyCAHolder(); - } - - /////////////////////////////////////////////////// - // EmptyCAHolder - private class EmptyCAHolder : ICustomAttributeProvider - { - internal EmptyCAHolder() { } - - object[] ICustomAttributeProvider.GetCustomAttributes(Type attributeType, bool inherit) - { - return Array.Empty(); - } - - object[] ICustomAttributeProvider.GetCustomAttributes(bool inherit) - { - return Array.Empty(); - } - - bool ICustomAttributeProvider.IsDefined(Type attributeType, bool inherit) - { - return false; - } - } } } } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/EmptyCAHolder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/EmptyCAHolder.cs new file mode 100644 index 000000000000..111405680607 --- /dev/null +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/EmptyCAHolder.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Reflection.Emit +{ + internal class EmptyCAHolder : ICustomAttributeProvider + { + internal EmptyCAHolder() { } + + object[] ICustomAttributeProvider.GetCustomAttributes(Type attributeType, bool inherit) => Array.Empty(); + + object[] ICustomAttributeProvider.GetCustomAttributes(bool inherit) => Array.Empty(); + + bool ICustomAttributeProvider.IsDefined(Type attributeType, bool inherit) => false; + } +} diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs index 29fbc8e5a3c9..fc0b37935eb1 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs @@ -513,15 +513,7 @@ public override Type? DeclaringType } } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) - public override ICustomAttributeProvider? ReturnTypeCustomAttributes - { - get - { - return null; - } - } -#pragma warning restore CS8609 + public override ICustomAttributeProvider ReturnTypeCustomAttributes => new EmptyCAHolder(); public override Type? ReflectedType { diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolMethod.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolMethod.cs index a2573cc0fb59..a205cfd823a1 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolMethod.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/SymbolMethod.cs @@ -126,12 +126,7 @@ public override Type ReturnType } } -#pragma warning disable CS8609 // TODO-NULLABLE: Covariant return types (https://github.com/dotnet/roslyn/issues/23268) - public override ICustomAttributeProvider? ReturnTypeCustomAttributes - { - get { return null; } - } -#pragma warning restore CS8608 + public override ICustomAttributeProvider ReturnTypeCustomAttributes => new EmptyCAHolder(); public override object Invoke(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture) { From 93d65bec7056bd753e044a7146598dc2f0458349 Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Wed, 5 Jun 2019 12:04:05 -0700 Subject: [PATCH 5/5] Disable corefx tests --- tests/CoreFX/CoreFX.issues.rsp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/CoreFX/CoreFX.issues.rsp b/tests/CoreFX/CoreFX.issues.rsp index bdc931af5cae..517d91883fd7 100644 --- a/tests/CoreFX/CoreFX.issues.rsp +++ b/tests/CoreFX/CoreFX.issues.rsp @@ -56,3 +56,16 @@ -nomethod System.Tests.EnvironmentTests.FailFast_ExceptionStackTrace_StackOverflowException -nomethod System.Tests.EnvironmentTests.FailFast_ExceptionStackTrace_InnerException -nomethod System.Tests.EnvironmentTests.FailFast_ExceptionStackTrace_ArgumentException + +# requires corefx test updates: https://github.com/dotnet/corefx/pull/38269 +-nomethod System.Reflection.Emit.Tests.DynamicMethodctor1.String_Type_TypeArray_Module +-nomethod System.Reflection.Emit.Tests.DynamicMethodctor1.String_Type_TypeArray_Type +-nomethod System.Reflection.Emit.Tests.MethodBuilderGetGenericArguments.GetGenericArguments_NonGenericMethod_ReturnsNull +-nomethod System.Reflection.Emit.Tests.MethodBuilderSetReturnType.SetReturnType_NullReturnType_ReturnsVoid +-nomethod System.Reflection.Emit.Tests.MethodBuilderSetSignature.SetSignature_AllParametersNull +-nomethod System.Reflection.Emit.Tests.MethodBuilderSetSignature.SetSignature_NullReturnType_CustomModifiersSetToWrongTypes +-nomethod System.Reflection.Emit.Tests.TypeBuilderDefineMethodTests.DefineMethod +-nomethod System.Tests.StringTests.CasingNegativeTest +-nomethod System.Tests.StringTests.CompareNegativeTest +-nomethod System.Tests.StringTests.ToLowerNullCulture +-nomethod System.Tests.StringTests.ToUpperNullCulture