This repository was archived by the owner on Jul 1, 2023. It is now read-only.
[Tensor] Add precondition in 'Tensor.init(arrayLiteral:)' to reject 'init()' calls. #336
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A long-standing issue in Swift is that labeled variadic parameters can accept 0 arguments when a label does not exist. Here is a related discussion on Swift Evolution: Should labeled variadic parameters accept 0 arguments?
When there is no
Tensor.init()
, aninit()
expression will resolve to a call toinit(arrayLiteral:)
with no arguments, which is semantically invalid forTensor
,ShapedArray
, andShapedArraySlice
. Declaring aninit()
with an@available(*, unavailable)
does not work becuase the type checker would still resolveinit()
calls toinit(arrayLiteral:)
. Before Swift supports finer control over labeled variadic parameters, the only thing we can do is to fail early at run-time.XCTest does not yet provide test utilities for crashers. We can add such a test utility along with tests for such run-time errors later.
Resolves TF-644.