-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fixing System.Array constructor #107266
Fixing System.Array constructor #107266
Conversation
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan.cs
Show resolved
Hide resolved
@@ -166,7 +167,7 @@ public ReadOnlyTensorSpan(Array? array, scoped ReadOnlySpan<int> start, scoped R | |||
this = default; | |||
return; // returns default | |||
} | |||
if (!typeof(T).IsValueType && array.GetType() != typeof(T[])) | |||
if (array.GetType().GetElementType() != typeof(T)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a correct fix. But I'd like us to get an issue logged around this, as this seems like a pit of failure here.
In particular, since Array
is "untyped" and due to how new[] {...}
works, it means that users can get into these types of silent failures; when they likely expected it to be implicitly typed as double[]
like [...]
would've been.
So I think we may want to consider if this should be a constructor or instead some named Create*
method where *
is an appropriate suffix.
/backport to release/9.0 |
Started backporting to release/9.0: https://github.com/dotnet/runtime/actions/runs/10779752164 |
/azp run |
You have several pipelines (over 10) configured to build pull requests in this repository. Specify which pipelines you would like to run by using /azp run [pipelines] command. You can specify multiple pipelines using a comma separated list. |
a706e72
to
bee3313
Compare
* fixing System.Array constructor * adding back in co-varience check and tests
* fixing System.Array constructor * adding back in co-varience check and tests
Fixes #106534. Fixes the check in the System.Array constructor to make sure the type of the Array matches the
T
that was used.