Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate ValueBuffer.IsEmpty #23428

Closed
roji opened this issue Nov 21, 2020 · 2 comments
Closed

Investigate ValueBuffer.IsEmpty #23428

roji opened this issue Nov 21, 2020 · 2 comments
Labels
closed-no-further-action The issue is closed and no further action is planned.

Comments

@roji
Copy link
Member

roji commented Nov 21, 2020

We have an assertion in the ctor that this will never happen? What about _value.Length == 0?

(originally from #23423 (comment))

@ajcvickers
Copy link
Member

@roji This is a struct, which means it always has an implicit parameterless constructor. It is this constructor that allows IsEmpty to return true. The parameterless constructor is (at least conceptually) called when the struct is used as a field, variable, etc. that is not explicitly initialized. We then use IsEmpty to check for this. If you create an explicit ValueBuffer for an array, then that array must not be null. So the array being null is a valid state for the ValueBuffer--it means it's the default instance. But setting the array to null in this constructor is not allowed.

@roji
Copy link
Member Author

roji commented Nov 22, 2020

Thanks @ajcvickers, makes sense. I'll leave _values annotated as non-nullable - as all accessors currently assume that they're never called with _values null - and suppress the warning in IsEmpty. In effect, the only thing you can do with the empty ValueBuffer is to check that it is the empty ValueBuffer.

@roji roji closed this as completed Nov 22, 2020
@roji roji added the closed-no-further-action The issue is closed and no further action is planned. label Nov 22, 2020
@smitpatel smitpatel removed their assignment Jan 12, 2022
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned.
Projects
None yet
Development

No branches or pull requests

3 participants