Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Revert making Nullable<T> readonly#15198

Merged
stephentoub merged 2 commits intodotnet:masterfrom
stephentoub:nullable_revert
Nov 23, 2017
Merged

Revert making Nullable<T> readonly#15198
stephentoub merged 2 commits intodotnet:masterfrom
stephentoub:nullable_revert

Conversation

@stephentoub
Copy link
Member

{
private readonly bool hasValue; // Do not rename (binary serialization)
internal readonly T value; // Do not rename (binary serialization)
internal T value; // Do not rename (binary serialization)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment why this cannot be readonly?

Copy link
Member Author

@stephentoub stephentoub Nov 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add. The test I've added in corefx will also fail if this is made readonly.

@stephentoub stephentoub merged commit f2fbb1c into dotnet:master Nov 23, 2017
@stephentoub stephentoub deleted the nullable_revert branch November 23, 2017 16:06
dotnet-bot pushed a commit to dotnet/corert that referenced this pull request Nov 23, 2017
* Revert making Nullable<T> readonly

* Address PR feedback

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
stephentoub added a commit to dotnet/corert that referenced this pull request Nov 23, 2017
* Revert making Nullable<T> readonly

* Address PR feedback

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
@VSadov
Copy link
Member

VSadov commented Nov 23, 2017

After thinking a bit about this, it looks like a bug/oversight in Nullable.
ToString should do something like ‘this?.ToString() ?? “” ‘

Mutable Nullable is less convenient and is unlikely intentional. Methods like ToString can change the state. Even T being readonly or a primitive would not help much. ToString could still do anything - as gross as ‘this = null’.

I guess we are keeping it as is anyways...

dotnet-bot pushed a commit to dotnet/corefx that referenced this pull request Jan 13, 2018
* Revert making Nullable<T> readonly

* Address PR feedback

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
dotnet-bot pushed a commit to dotnet/corefx that referenced this pull request Jan 13, 2018
* Revert making Nullable<T> readonly

* Address PR feedback

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
safern pushed a commit to dotnet/corefx that referenced this pull request Jan 16, 2018
* Revert making Nullable<T> readonly

* Address PR feedback

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
safern pushed a commit to dotnet/corefx that referenced this pull request Jan 16, 2018
* Revert making Nullable<T> readonly

* Address PR feedback

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants