Skip to content

Commit f221445

Browse files
committed
Fix build errors from merge conflicts and compiler update
1 parent c4ff48e commit f221445

File tree

9 files changed

+73
-73
lines changed

9 files changed

+73
-73
lines changed

src/System.Private.CoreLib/shared/System/DateTimeOffset.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ private DateTimeOffset(SerializationInfo info, StreamingContext context)
625625
throw new ArgumentNullException(nameof(info));
626626
}
627627

628-
_dateTime = (DateTime)info.GetValue("DateTime", typeof(DateTime)); // Do not rename (binary serialization)
629-
_offsetMinutes = (short)info.GetValue("OffsetMinutes", typeof(short)); // Do not rename (binary serialization)
628+
_dateTime = (DateTime)info.GetValue("DateTime", typeof(DateTime))!; // Do not rename (binary serialization)
629+
_offsetMinutes = (short)info.GetValue("OffsetMinutes", typeof(short))!; // Do not rename (binary serialization)
630630
}
631631

632632
// Returns the hash code for this DateTimeOffset.

src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ internal static Task<TResult> GetTaskForResult(TResult result)
895895
// For Boolean, we cache all possible values.
896896
if (typeof(TResult) == typeof(bool)) // only the relevant branches are kept for each value-type generic instantiation
897897
{
898-
bool value = (bool)(object?)result;
898+
bool value = (bool)(object)result!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34976
899899
Task<bool> task = value ? AsyncTaskCache.TrueTask : AsyncTaskCache.FalseTask;
900900
return Unsafe.As<Task<TResult>>(task); // UnsafeCast avoids type check we know will succeed
901901
}
@@ -905,7 +905,7 @@ internal static Task<TResult> GetTaskForResult(TResult result)
905905
// Compare to constants to avoid static field access if outside of cached range.
906906
// We compare to the upper bound first, as we're more likely to cache miss on the upper side than on the
907907
// lower side, due to positive values being more common than negative as return values.
908-
int value = (int)(object?)result;
908+
int value = (int)(object)result!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34976
909909
if (value < AsyncTaskCache.EXCLUSIVE_INT32_MAX &&
910910
value >= AsyncTaskCache.INCLUSIVE_INT32_MIN)
911911
{
@@ -915,16 +915,16 @@ internal static Task<TResult> GetTaskForResult(TResult result)
915915
}
916916
// For other known value types, we only special-case 0 / default(TResult).
917917
else if (
918-
(typeof(TResult) == typeof(uint) && default == (uint)(object?)result) ||
919-
(typeof(TResult) == typeof(byte) && default(byte) == (byte)(object?)result) ||
920-
(typeof(TResult) == typeof(sbyte) && default(sbyte) == (sbyte)(object?)result) ||
921-
(typeof(TResult) == typeof(char) && default(char) == (char)(object?)result) ||
922-
(typeof(TResult) == typeof(long) && default == (long)(object?)result) ||
923-
(typeof(TResult) == typeof(ulong) && default == (ulong)(object?)result) ||
924-
(typeof(TResult) == typeof(short) && default(short) == (short)(object?)result) ||
925-
(typeof(TResult) == typeof(ushort) && default(ushort) == (ushort)(object?)result) ||
926-
(typeof(TResult) == typeof(IntPtr) && default == (IntPtr)(object?)result) ||
927-
(typeof(TResult) == typeof(UIntPtr) && default == (UIntPtr)(object?)result))
918+
(typeof(TResult) == typeof(uint) && default == (uint)(object)result!) ||
919+
(typeof(TResult) == typeof(byte) && default(byte) == (byte)(object)result!) ||
920+
(typeof(TResult) == typeof(sbyte) && default(sbyte) == (sbyte)(object)result!) ||
921+
(typeof(TResult) == typeof(char) && default(char) == (char)(object)result!) ||
922+
(typeof(TResult) == typeof(long) && default == (long)(object)result!) ||
923+
(typeof(TResult) == typeof(ulong) && default == (ulong)(object)result!) ||
924+
(typeof(TResult) == typeof(short) && default(short) == (short)(object)result!) ||
925+
(typeof(TResult) == typeof(ushort) && default(ushort) == (ushort)(object)result!) ||
926+
(typeof(TResult) == typeof(IntPtr) && default == (IntPtr)(object)result!) ||
927+
(typeof(TResult) == typeof(UIntPtr) && default == (UIntPtr)(object)result!)) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34976
928928
{
929929
return s_defaultResultTask;
930930
}

src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -540,104 +540,104 @@ private int FindElement(string name)
540540
public bool GetBoolean(string name)
541541
{
542542
Type foundType;
543-
object? value = GetElement(name, out foundType);
544-
return ReferenceEquals(foundType, typeof(bool)) ? (bool)value : _converter.ToBoolean(value!); // if value is null To* method will either deal with it or throw
543+
object value = GetElement(name, out foundType)!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34976
544+
return ReferenceEquals(foundType, typeof(bool)) ? (bool)value : _converter.ToBoolean(value); // if value is null To* method will either deal with it or throw
545545
}
546546

547547
public char GetChar(string name)
548548
{
549549
Type foundType;
550-
object? value = GetElement(name, out foundType);
551-
return ReferenceEquals(foundType, typeof(char)) ? (char)value : _converter.ToChar(value!);
550+
object value = GetElement(name, out foundType)!;
551+
return ReferenceEquals(foundType, typeof(char)) ? (char)value : _converter.ToChar(value);
552552
}
553553

554554
[CLSCompliant(false)]
555555
public sbyte GetSByte(string name)
556556
{
557557
Type foundType;
558-
object? value = GetElement(name, out foundType);
559-
return ReferenceEquals(foundType, typeof(sbyte)) ? (sbyte)value : _converter.ToSByte(value!);
558+
object value = GetElement(name, out foundType)!;
559+
return ReferenceEquals(foundType, typeof(sbyte)) ? (sbyte)value : _converter.ToSByte(value);
560560
}
561561

562562
public byte GetByte(string name)
563563
{
564564
Type foundType;
565-
object? value = GetElement(name, out foundType);
566-
return ReferenceEquals(foundType, typeof(byte)) ? (byte)value : _converter.ToByte(value!);
565+
object value = GetElement(name, out foundType)!;
566+
return ReferenceEquals(foundType, typeof(byte)) ? (byte)value : _converter.ToByte(value);
567567
}
568568

569569
public short GetInt16(string name)
570570
{
571571
Type foundType;
572-
object? value = GetElement(name, out foundType);
573-
return ReferenceEquals(foundType, typeof(short)) ? (short)value : _converter.ToInt16(value!);
572+
object value = GetElement(name, out foundType)!;
573+
return ReferenceEquals(foundType, typeof(short)) ? (short)value : _converter.ToInt16(value);
574574
}
575575

576576
[CLSCompliant(false)]
577577
public ushort GetUInt16(string name)
578578
{
579579
Type foundType;
580-
object? value = GetElement(name, out foundType);
581-
return ReferenceEquals(foundType, typeof(ushort)) ? (ushort)value : _converter.ToUInt16(value!);
580+
object value = GetElement(name, out foundType)!;
581+
return ReferenceEquals(foundType, typeof(ushort)) ? (ushort)value : _converter.ToUInt16(value);
582582
}
583583

584584
public int GetInt32(string name)
585585
{
586586
Type foundType;
587-
object? value = GetElement(name, out foundType);
588-
return ReferenceEquals(foundType, typeof(int)) ? (int)value : _converter.ToInt32(value!);
587+
object value = GetElement(name, out foundType)!;
588+
return ReferenceEquals(foundType, typeof(int)) ? (int)value : _converter.ToInt32(value);
589589
}
590590

591591
[CLSCompliant(false)]
592592
public uint GetUInt32(string name)
593593
{
594594
Type foundType;
595-
object? value = GetElement(name, out foundType);
596-
return ReferenceEquals(foundType, typeof(uint)) ? (uint)value : _converter.ToUInt32(value!);
595+
object value = GetElement(name, out foundType)!;
596+
return ReferenceEquals(foundType, typeof(uint)) ? (uint)value : _converter.ToUInt32(value);
597597
}
598598

599599
public long GetInt64(string name)
600600
{
601601
Type foundType;
602-
object? value = GetElement(name, out foundType);
603-
return ReferenceEquals(foundType, typeof(long)) ? (long)value : _converter.ToInt64(value!);
602+
object value = GetElement(name, out foundType)!;
603+
return ReferenceEquals(foundType, typeof(long)) ? (long)value : _converter.ToInt64(value);
604604
}
605605

606606
[CLSCompliant(false)]
607607
public ulong GetUInt64(string name)
608608
{
609609
Type foundType;
610-
object? value = GetElement(name, out foundType);
611-
return ReferenceEquals(foundType, typeof(ulong)) ? (ulong)value : _converter.ToUInt64(value!);
610+
object value = GetElement(name, out foundType)!;
611+
return ReferenceEquals(foundType, typeof(ulong)) ? (ulong)value : _converter.ToUInt64(value);
612612
}
613613

614614
public float GetSingle(string name)
615615
{
616616
Type foundType;
617-
object? value = GetElement(name, out foundType);
618-
return ReferenceEquals(foundType, typeof(float)) ? (float)value : _converter.ToSingle(value!);
617+
object value = GetElement(name, out foundType)!;
618+
return ReferenceEquals(foundType, typeof(float)) ? (float)value : _converter.ToSingle(value);
619619
}
620620

621621

622622
public double GetDouble(string name)
623623
{
624624
Type foundType;
625-
object? value = GetElement(name, out foundType);
626-
return ReferenceEquals(foundType, typeof(double)) ? (double)value : _converter.ToDouble(value!);
625+
object value = GetElement(name, out foundType)!;
626+
return ReferenceEquals(foundType, typeof(double)) ? (double)value : _converter.ToDouble(value);
627627
}
628628

629629
public decimal GetDecimal(string name)
630630
{
631631
Type foundType;
632-
object? value = GetElement(name, out foundType);
633-
return ReferenceEquals(foundType, typeof(decimal)) ? (decimal)value : _converter.ToDecimal(value!);
632+
object value = GetElement(name, out foundType)!;
633+
return ReferenceEquals(foundType, typeof(decimal)) ? (decimal)value : _converter.ToDecimal(value);
634634
}
635635

636636
public DateTime GetDateTime(string name)
637637
{
638638
Type foundType;
639-
object? value = GetElement(name, out foundType);
640-
return ReferenceEquals(foundType, typeof(DateTime)) ? (DateTime)value : _converter.ToDateTime(value!);
639+
object value = GetElement(name, out foundType)!;
640+
return ReferenceEquals(foundType, typeof(DateTime)) ? (DateTime)value : _converter.ToDateTime(value);
641641
}
642642

643643
public string? GetString(string name)

src/System.Private.CoreLib/shared/System/Text/UTF8Encoding.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable enable
65
// The worker functions in this file was optimized for performance. If you make changes
76
// you should use care to consider all of the interesting cases.
87

@@ -11,6 +10,7 @@
1110
// The fast loops attempts to blaze through as fast as possible with optimistic range checks,
1211
// processing multiple characters at a time, and falling back to the slow loop for all special cases.
1312

13+
#nullable enable
1414
using System;
1515
using System.Buffers;
1616
using System.Diagnostics;
@@ -139,7 +139,7 @@ public override unsafe int GetByteCount(char[] chars, int index, int count)
139139
ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
140140
}
141141

142-
if (chars.Length - index < count)
142+
if (chars!.Length - index < count) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
143143
{
144144
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
145145
}
@@ -166,7 +166,7 @@ public override unsafe int GetByteCount(string chars)
166166

167167
fixed (char* pChars = chars)
168168
{
169-
return GetByteCountCommon(pChars, chars.Length);
169+
return GetByteCountCommon(pChars, chars!.Length); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
170170
}
171171
}
172172

@@ -233,7 +233,7 @@ private unsafe int GetByteCountCommon(char* pChars, int charCount)
233233
}
234234

235235
[MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetCharCountCommon
236-
private protected sealed override unsafe int GetByteCountFast(char* pChars, int charsLength, EncoderFallback fallback, out int charsConsumed)
236+
private protected sealed override unsafe int GetByteCountFast(char* pChars, int charsLength, EncoderFallback? fallback, out int charsConsumed)
237237
{
238238
// The number of UTF-8 code units may exceed the number of UTF-16 code units,
239239
// so we'll need to check for overflow before casting to Int32.
@@ -276,12 +276,12 @@ public override unsafe int GetBytes(string s, int charIndex, int charCount,
276276
resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
277277
}
278278

279-
if (s.Length - charIndex < charCount)
279+
if (s!.Length - charIndex < charCount) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
280280
{
281281
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.s, ExceptionResource.ArgumentOutOfRange_IndexCount);
282282
}
283283

284-
if ((uint)byteIndex > bytes.Length)
284+
if ((uint)byteIndex > bytes!.Length) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
285285
{
286286
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index);
287287
}
@@ -326,12 +326,12 @@ public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
326326
resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
327327
}
328328

329-
if (chars.Length - charIndex < charCount)
329+
if (chars!.Length - charIndex < charCount) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
330330
{
331331
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCount);
332332
}
333333

334-
if ((uint)byteIndex > bytes.Length)
334+
if ((uint)byteIndex > bytes!.Length) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
335335
{
336336
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index);
337337
}
@@ -444,7 +444,7 @@ public override unsafe int GetCharCount(byte[] bytes, int index, int count)
444444
ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
445445
}
446446

447-
if (bytes.Length - index < count)
447+
if (bytes!.Length - index < count) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
448448
{
449449
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
450450
}
@@ -511,12 +511,12 @@ public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount,
511511
resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
512512
}
513513

514-
if (bytes.Length - byteIndex < byteCount)
514+
if (bytes!.Length - byteIndex < byteCount) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
515515
{
516516
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
517517
}
518518

519-
if ((uint)charIndex > (uint)chars.Length)
519+
if ((uint)charIndex > (uint)chars!.Length) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
520520
{
521521
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_Index);
522522
}
@@ -614,7 +614,7 @@ private protected sealed override unsafe int GetCharsFast(byte* pBytes, int byte
614614
return (int)(pOutputBufferRemaining - pChars);
615615
}
616616

617-
private protected sealed override unsafe int GetCharsWithFallback(ReadOnlySpan<byte> bytes, int originalBytesLength, Span<char> chars, int originalCharsLength, DecoderNLS decoder)
617+
private protected sealed override unsafe int GetCharsWithFallback(ReadOnlySpan<byte> bytes, int originalBytesLength, Span<char> chars, int originalCharsLength, DecoderNLS? decoder)
618618
{
619619
// We special-case DecoderReplacementFallback if it's telling us to write a single U+FFFD char,
620620
// since we believe this to be relatively common and we can handle it more efficiently than
@@ -673,7 +673,7 @@ public override unsafe string GetString(byte[] bytes, int index, int count)
673673
resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
674674
}
675675

676-
if (bytes.Length - index < count)
676+
if (bytes!.Length - index < count) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
677677
{
678678
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
679679
}
@@ -723,7 +723,7 @@ private unsafe int GetCharCountCommon(byte* pBytes, int byteCount)
723723
}
724724

725725
[MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetCharCountCommon
726-
private protected sealed override unsafe int GetCharCountFast(byte* pBytes, int bytesLength, DecoderFallback fallback, out int bytesConsumed)
726+
private protected sealed override unsafe int GetCharCountFast(byte* pBytes, int bytesLength, DecoderFallback? fallback, out int bytesConsumed)
727727
{
728728
// The number of UTF-16 code units will never exceed the number of UTF-8 code units,
729729
// so the addition at the end of this method will not overflow.

src/System.Private.CoreLib/shared/System/TimeZoneInfo.AdjustmentRule.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ private AdjustmentRule(SerializationInfo info, StreamingContext context)
249249
throw new ArgumentNullException(nameof(info));
250250
}
251251

252-
_dateStart = (DateTime)info.GetValue("DateStart", typeof(DateTime)); // Do not rename (binary serialization)
253-
_dateEnd = (DateTime)info.GetValue("DateEnd", typeof(DateTime)); // Do not rename (binary serialization)
254-
_daylightDelta = (TimeSpan)info.GetValue("DaylightDelta", typeof(TimeSpan)); // Do not rename (binary serialization)
255-
_daylightTransitionStart = (TransitionTime)info.GetValue("DaylightTransitionStart", typeof(TransitionTime)); // Do not rename (binary serialization)
256-
_daylightTransitionEnd = (TransitionTime)info.GetValue("DaylightTransitionEnd", typeof(TransitionTime)); // Do not rename (binary serialization)
252+
_dateStart = (DateTime)info.GetValue("DateStart", typeof(DateTime))!; // Do not rename (binary serialization)
253+
_dateEnd = (DateTime)info.GetValue("DateEnd", typeof(DateTime))!; // Do not rename (binary serialization)
254+
_daylightDelta = (TimeSpan)info.GetValue("DaylightDelta", typeof(TimeSpan))!; // Do not rename (binary serialization)
255+
_daylightTransitionStart = (TransitionTime)info.GetValue("DaylightTransitionStart", typeof(TransitionTime))!; // Do not rename (binary serialization)
256+
_daylightTransitionEnd = (TransitionTime)info.GetValue("DaylightTransitionEnd", typeof(TransitionTime))!; // Do not rename (binary serialization)
257257

258258
object? o = info.GetValueNoThrow("BaseUtcOffsetDelta", typeof(TimeSpan)); // Do not rename (binary serialization)
259259
if (o != null)

0 commit comments

Comments
 (0)