From a8b7c2204e167cff2068ff9a72d4238469f70c4b Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Thu, 25 Apr 2019 16:50:53 -0700 Subject: [PATCH] fix build errors after merge Commit migrated from https://github.com/dotnet/coreclr/commit/737907cec8b74abe3b9d3dc1c4501b29c8b7f4a4 --- .../Collections/EmptyReadOnlyDictionaryInternal.cs | 2 +- .../Collections/ObjectModel/ReadOnlyDictionary.cs | 4 ++-- .../Eventing/EventPipeMetadataGenerator.cs | 2 +- .../Diagnostics/Eventing/NativeRuntimeEventSource.cs | 2 +- .../System/Diagnostics/Eventing/XplatEventLogger.cs | 8 ++++---- .../src/System/Reflection/RuntimeModule.cs | 4 ++-- .../src/System/RuntimeHandles.cs | 16 ++++++++-------- .../src/System/Collections/ObjectModel/Collection.cs | 2 +- .../Collections/ObjectModel/ReadOnlyCollection.cs | 2 +- .../src/System/Diagnostics/Contracts/Contracts.cs | 2 +- .../src/System/Diagnostics/Tracing/EventSource.cs | 8 ++++---- .../Diagnostics/Tracing/TraceLogging/NameInfo.cs | 2 +- .../src/System/Reflection/TypeInfo.cs | 2 +- .../src/System/Resources/ResourceReader.Core.cs | 20 ++++++++++---------- 14 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs index b965b84..21d1739 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs @@ -208,7 +208,7 @@ namespace System.Collections } } - public object Value + public object? Value { get { diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs index b70db09..d037851 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs @@ -195,7 +195,7 @@ namespace System.Collections.ObjectModel return key is TKey; } - void IDictionary.Add(object key, object value) + void IDictionary.Add(object key, object? value) { ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection); } @@ -686,7 +686,7 @@ namespace System.Collections.ObjectModel // For example, if the element type of the Array is derived from T, // we can't figure out if we can successfully copy the element beforehand. // - Type targetType = array.GetType().GetElementType(); + Type targetType = array.GetType().GetElementType()!; Type sourceType = typeof(T); if (!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType))) { diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeMetadataGenerator.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeMetadataGenerator.cs index 13aae73..4189d1f 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeMetadataGenerator.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeMetadataGenerator.cs @@ -20,7 +20,7 @@ namespace System.Diagnostics.Tracing EventParameterInfo[] eventParams = new EventParameterInfo[parameters.Length]; for(int i = 0; i < parameters.Length; i++) { - eventParams[i].SetInfo(parameters[i].Name, parameters[i].ParameterType); + eventParams[i].SetInfo(parameters[i].Name!, parameters[i].ParameterType); } return GenerateMetadata( diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.cs index 489754f..b7fc735 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.cs @@ -24,7 +24,7 @@ namespace System.Diagnostics.Tracing internal unsafe void ProcessEvent(uint eventID, uint osThreadID, DateTime timeStamp, Guid activityId, Guid childActivityId, ReadOnlySpan payload) { // Make sure the eventID is valid. - if (eventID >= m_eventData.Length) + if (eventID >= m_eventData!.Length) { return; } diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/XplatEventLogger.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/XplatEventLogger.cs index e6a41d5..f5c38aa 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/XplatEventLogger.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/XplatEventLogger.cs @@ -42,7 +42,7 @@ namespace System.Diagnostics.Tracing private static extern bool IsEventSourceLoggingEnabled(); [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - private static extern void LogEventSource(int eventID, string eventName, string eventSourceName, string payload); + private static extern void LogEventSource(int eventID, string? eventName, string eventSourceName, string payload); static List escape_seq = new List { '\b', '\f', '\n', '\r', '\t', '\"', '\\' }; static Dictionary seq_mapping = new Dictionary() @@ -72,7 +72,7 @@ namespace System.Diagnostics.Tracing } } - private static string Serialize(ReadOnlyCollection? payloadName, ReadOnlyCollection payload, string? eventMessage) + private static string Serialize(ReadOnlyCollection? payloadName, ReadOnlyCollection? payload, string? eventMessage) { if (payloadName == null || payload == null) return string.Empty; @@ -133,7 +133,7 @@ namespace System.Diagnostics.Tracing { if(payload[i] != null) { - sb.Append(payload[i].ToString()); + sb.Append(payload[i]!.ToString()); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644 } break; } @@ -176,7 +176,7 @@ namespace System.Diagnostics.Tracing internal protected override void OnEventWritten(EventWrittenEventArgs eventData) { string? eventFilter = eventSourceEventFilter.Value; - if (string.IsNullOrEmpty(eventFilter) || (eventData.EventName.IndexOf(eventFilter, StringComparison.OrdinalIgnoreCase) >= 0)) + if (string.IsNullOrEmpty(eventFilter) || (eventData.EventName!.IndexOf(eventFilter, StringComparison.OrdinalIgnoreCase) >= 0)) { LogOnEventWritten(eventData); } diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs index 0e67280..500e623 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs @@ -22,10 +22,10 @@ namespace System.Reflection private static extern bool nIsTransientInternal(RuntimeModule module); [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - private static extern void GetScopeName(RuntimeModule module, StringHandleOnStack? retString); + private static extern void GetScopeName(RuntimeModule module, StringHandleOnStack retString); [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - private static extern void GetFullyQualifiedName(RuntimeModule module, StringHandleOnStack? retString); + private static extern void GetFullyQualifiedName(RuntimeModule module, StringHandleOnStack retString); [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern RuntimeType[] GetTypes(RuntimeModule module); diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeHandles.cs b/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeHandles.cs index e6cc9aa..4d234e8 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeHandles.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeHandles.cs @@ -624,15 +624,15 @@ namespace System #endif // FEATURE_TYPEEQUIVALENCE } - // This type is used to remove the expense of having a managed reference object that is dynamically + // This type is used to remove the expense of having a managed reference object that is dynamically // created when we can prove that we don't need that object. Use of this type requires code to ensure - // that the underlying native resource is not freed. + // that the underlying native resource is not freed. // Cases in which this may be used: // 1. When native code calls managed code passing one of these as a parameter // 2. When managed code acquires one of these from an IRuntimeMethodInfo, and ensure that the IRuntimeMethodInfo is preserved // across the lifetime of the RuntimeMethodHandleInternal instance // 3. When another object is used to keep the RuntimeMethodHandleInternal alive. See delegates, CreateInstance cache, Signature structure - // When in doubt, do not use. + // When in doubt, do not use. internal struct RuntimeMethodHandleInternal { internal static RuntimeMethodHandleInternal EmptyHandle @@ -991,15 +991,15 @@ namespace System internal static extern LoaderAllocator GetLoaderAllocator(RuntimeMethodHandleInternal method); } - // This type is used to remove the expense of having a managed reference object that is dynamically + // This type is used to remove the expense of having a managed reference object that is dynamically // created when we can prove that we don't need that object. Use of this type requires code to ensure - // that the underlying native resource is not freed. + // that the underlying native resource is not freed. // Cases in which this may be used: // 1. When native code calls managed code passing one of these as a parameter // 2. When managed code acquires one of these from an RtFieldInfo, and ensure that the RtFieldInfo is preserved // across the lifetime of the RuntimeFieldHandleInternal instance // 3. When another object is used to keep the RuntimeFieldHandleInternal alive. - // When in doubt, do not use. + // When in doubt, do not use. internal struct RuntimeFieldHandleInternal { internal bool IsNullHandle() @@ -1443,7 +1443,7 @@ namespace System [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern void GetSignature( void* pCorSig, int cCorSig, - RuntimeFieldHandleInternal? fieldHandle, IRuntimeMethodInfo? methodHandle, RuntimeType? declaringType); + RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo? methodHandle, RuntimeType? declaringType); #endregion @@ -1531,7 +1531,7 @@ namespace System 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 MethodInfo GetDynamicMethod(); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs index 89817ba..93a048c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs @@ -341,7 +341,7 @@ namespace System.Collections.ObjectModel // For example, if the element type of the Array is derived from T, // we can't figure out if we can successfully copy the element beforehand. // - Type targetType = array.GetType().GetElementType(); + Type targetType = array.GetType().GetElementType()!; Type sourceType = typeof(T); if (!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType))) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs index 99ffd26..10795ac 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs @@ -160,7 +160,7 @@ namespace System.Collections.ObjectModel // For example, if the element type of the Array is derived from T, // we can't figure out if we can successfully copy the element beforehand. // - Type targetType = array.GetType().GetElementType(); + Type targetType = array.GetType().GetElementType()!; Type sourceType = typeof(T); if (!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType))) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs index 26cdc7f..c5dc887 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Contracts/Contracts.cs @@ -655,7 +655,7 @@ namespace System.Diagnostics.Contracts Assembly? probablyNotRewritten = null; for (int i = 0; i < stack.FrameCount; i++) { - Assembly? caller = stack.GetFrame(i)!.GetMethod()?.DeclaringType.Assembly; + Assembly? caller = stack.GetFrame(i)!.GetMethod()?.DeclaringType!.Assembly; if (caller != null && caller != thisAssembly) { probablyNotRewritten = caller; diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index c0416fc..22a64c9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -243,7 +243,7 @@ namespace System.Diagnostics.Tracing { #if FEATURE_EVENTSOURCE_XPLAT - private static readonly EventListener persistent_Xplat_Listener = XplatEventLogger.InitializePersistentListener(); + private static readonly EventListener? persistent_Xplat_Listener = XplatEventLogger.InitializePersistentListener(); #endif //FEATURE_EVENTSOURCE_XPLAT /// @@ -704,7 +704,7 @@ namespace System.Diagnostics.Tracing if (eventID == 0) continue; - byte[] metadata = EventPipeMetadataGenerator.Instance.GenerateEventMetadata(m_eventData[i]); + byte[]? metadata = EventPipeMetadataGenerator.Instance.GenerateEventMetadata(m_eventData[i]); uint metadataLength = (metadata != null) ? (uint)metadata.Length : 0; string eventName = m_eventData[i].Name; @@ -3482,8 +3482,8 @@ namespace System.Diagnostics.Tracing exception = e; } - Debug.Assert((flags & EventManifestOptions.Strict) != 0 && manifest != null); // TODO-NULLABLE: possible bug: if error is thrown before manifest is assigned in non-strict mode, this will NRE - if ((flags & EventManifestOptions.Strict) != 0 && (manifest.Errors.Count > 0 || exception != null)) + // TODO-NULLABLE: possible bug: if error is thrown before manifest is assigned in non-strict mode, this will NRE + if ((flags & EventManifestOptions.Strict) != 0 && (manifest!.Errors.Count > 0 || exception != null)) { string msg = string.Empty; diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs index 48fe8cf..2f6d2f5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs @@ -88,7 +88,7 @@ namespace System.Diagnostics.Tracing { if ((eventHandle = eventHandleTable[descriptor.EventId]) == IntPtr.Zero) { - byte[] metadataBlob = EventPipeMetadataGenerator.Instance.GenerateEventMetadata( + byte[]? metadataBlob = EventPipeMetadataGenerator.Instance.GenerateEventMetadata( descriptor.EventId, name, (EventKeywords)descriptor.Keywords, diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeInfo.cs index 9972073..0a207fd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeInfo.cs @@ -19,7 +19,7 @@ namespace System.Reflection public virtual EventInfo? GetDeclaredEvent(string name) => GetEvent(name, TypeInfo.DeclaredOnlyLookup); public virtual FieldInfo? GetDeclaredField(string name) => GetField(name, TypeInfo.DeclaredOnlyLookup); public virtual MethodInfo? GetDeclaredMethod(string name) => GetMethod(name, TypeInfo.DeclaredOnlyLookup); - public virtual TypeInfo? GetDeclaredNestedType(string name) => GetNestedType(name, TypeInfo.DeclaredOnlyLookup)!.GetTypeInfo(); + public virtual TypeInfo? GetDeclaredNestedType(string name) => GetNestedType(name, TypeInfo.DeclaredOnlyLookup)?.GetTypeInfo(); public virtual PropertyInfo? GetDeclaredProperty(string name) => GetProperty(name, TypeInfo.DeclaredOnlyLookup); public virtual IEnumerable GetDeclaredMethods(string name) diff --git a/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs b/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs index 80958b4..07f0279 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs @@ -20,11 +20,11 @@ namespace System.Resources // statics used to dynamically call into BinaryFormatter // When successfully located s_binaryFormatterType will point to the BinaryFormatter type // and s_deserializeMethod will point to an unbound delegate to the deserialize method. - private static Type s_binaryFormatterType; - private static Func s_deserializeMethod; + private static Type? s_binaryFormatterType; + private static Func? s_deserializeMethod; // This is the constructor the RuntimeResourceSet calls, - // passing in the stream to read from and the RuntimeResourceSet's + // passing in the stream to read from and the RuntimeResourceSet's // internal hash table (hash table of names with file offsets // and values, coupled to this ResourceReader). internal ResourceReader(Stream stream, Dictionary resCache, bool permitDeserialization) @@ -57,7 +57,7 @@ namespace System.Resources Type type = FindType(typeIndex); - object graph = s_deserializeMethod(_binaryFormatter, _store.BaseStream); + object graph = s_deserializeMethod!(_binaryFormatter, _store.BaseStream); // guard against corrupted resources if (graph.GetType() != type) @@ -74,16 +74,16 @@ namespace System.Resources LazyInitializer.EnsureInitialized(ref s_deserializeMethod, () => { - MethodInfo binaryFormatterDeserialize = s_binaryFormatterType.GetMethod("Deserialize", new Type[] { typeof(Stream) }); + MethodInfo binaryFormatterDeserialize = s_binaryFormatterType!.GetMethod("Deserialize", new Type[] { typeof(Stream) })!; // 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) - .Invoke(null, new object[] { binaryFormatterDeserialize }); + .GetMethod(nameof(CreateUntypedDelegate), BindingFlags.NonPublic | BindingFlags.Static)! + .MakeGenericMethod(s_binaryFormatterType)! + .Invoke(null, new object[] { binaryFormatterDeserialize })!; }); - _binaryFormatter = Activator.CreateInstance(s_binaryFormatterType); + _binaryFormatter = Activator.CreateInstance(s_binaryFormatterType!)!; } // generic method that we specialize at runtime once we've loaded the BinaryFormatter type @@ -157,7 +157,7 @@ namespace System.Resources } resourceType = TypeNameFromTypeCode(typeCode); - // The length must be adjusted to subtract off the number + // The length must be adjusted to subtract off the number // of bytes in the 7 bit encoded type code. len -= (int)(_store.BaseStream.Position - (_dataSectionOffset + dataPos)); byte[] bytes = _store.ReadBytes(len); -- 2.7.4