Skip to content

Commit 0ad8948

Browse files
committed
Add readonly modifier to standard library structs.
The remaining non-readonly structs are: - `Nullable<T>` (not sure why) - `ValueTuple<...>` (as it's mutable) Fixes #893.
1 parent d4fa579 commit 0ad8948

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

standard/standard-library.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ It is expected that a conforming C# implementation will supply a significantly
2121

2222
## C.2 Standard Library Types defined in ISO/IEC 23271
2323

24+
> *Note:* Some `struct` types below have the `readonly` modifier. This modifier was not available
25+
> when ISO/IEC 23271 was released, but is required for conforming implementations of this specification. *end note*
26+
2427
```csharp
2528
namespace System
2629
{
@@ -91,10 +94,10 @@ namespace System
9194
public AttributeTargets ValidOn { get; }
9295
}
9396

94-
public struct Boolean { }
95-
public struct Byte { }
96-
public struct Char { }
97-
public struct Decimal { }
97+
public readonly struct Boolean { }
98+
public readonly struct Byte { }
99+
public readonly struct Char { }
100+
public readonly struct Decimal { }
98101
public abstract class Delegate { }
99102

100103
public class DivideByZeroException : ArithmeticException
@@ -104,7 +107,7 @@ namespace System
104107
public DivideByZeroException(string message, Exception innerException);
105108
}
106109

107-
public struct Double { }
110+
public readonly struct Double { }
108111

109112
public abstract class Enum : ValueType
110113
{
@@ -137,10 +140,10 @@ namespace System
137140
Exception innerException);
138141
}
139142

140-
public struct Int16 { }
141-
public struct Int32 { }
142-
public struct Int64 { }
143-
public struct IntPtr { }
143+
public readonly struct Int16 { }
144+
public readonly struct Int32 { }
145+
public readonly struct Int64 { }
146+
public readonly struct IntPtr { }
144147

145148
public class InvalidCastException : Exception
146149
{
@@ -215,8 +218,8 @@ namespace System
215218
public OverflowException(string message, Exception innerException);
216219
}
217220

218-
public struct SByte { }
219-
public struct Single { }
221+
public readonly struct SByte { }
222+
public readonly struct Single { }
220223

221224
public sealed class StackOverflowException : Exception
222225
{
@@ -240,10 +243,10 @@ namespace System
240243
Exception innerException);
241244
}
242245

243-
public struct UInt16 { }
244-
public struct UInt32 { }
245-
public struct UInt64 { }
246-
public struct UIntPtr { }
246+
public readonly struct UInt16 { }
247+
public readonly struct UInt32 { }
248+
public readonly struct UInt64 { }
249+
public readonly struct UIntPtr { }
247250

248251
public struct ValueTuple<T1>
249252
{
@@ -506,16 +509,16 @@ namespace System.Runtime.CompilerServices
506509
void OnCompleted(Action continuation);
507510
}
508511

509-
public struct TaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion
512+
public readonly struct TaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion
510513
{
511514
public bool IsCompleted { get; }
512515
public void GetResult();
513516
}
514517

515-
public struct TaskAwaiter<T> : ICriticalNotifyCompletion, INotifyCompletion
518+
public readonly struct TaskAwaiter<TResult> : ICriticalNotifyCompletion, INotifyCompletion
516519
{
517520
public bool IsCompleted { get; }
518-
public T GetResult();
521+
public TResult GetResult();
519522
}
520523

521524
public readonly struct ValueTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion
@@ -524,10 +527,10 @@ namespace System.Runtime.CompilerServices
524527
public void GetResult();
525528
}
526529

527-
public readonly struct ValueTaskAwaiter<T> : ICriticalNotifyCompletion, INotifyCompletion
530+
public readonly struct ValueTaskAwaiter<TResult> : ICriticalNotifyCompletion, INotifyCompletion
528531
{
529532
public bool IsCompleted { get; }
530-
public T GetResult();
533+
public TResult GetResult();
531534
}
532535

533536
}
@@ -556,12 +559,12 @@ namespace System.Threading.Tasks
556559
```csharp
557560
namespace System
558561
{
559-
public ref struct ReadOnlySpan<T>
562+
public readonly ref struct ReadOnlySpan<T>
560563
{
561564
public int Length { get; }
562565
public ref readonly T this[int index] { get; }
563566
}
564-
public ref struct Span<T>
567+
public readonly ref struct Span<T>
565568
{
566569
public int Length { get; }
567570
public ref T this[int index] { get; }

0 commit comments

Comments
 (0)