Check types of LHS and RHS in assignment "to identifier" #187
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.
Before there was no checking that the types of the LHS and RHS were valid in assignment, with the exception of checking constness.
This commit introduces some checking in the case that the LHS is represented by an identifier (i.e. not an indexed identifier) Checking if the LHS is an indexed identifier, for example
b[1] = measure q;
remains to be implemented.IncompatibleDimensionError
is recorded. This is tested, for example, withIf the RHS is an integer literal and the LHS is unsigned, then the sign of the literal is examined and the RHS is wrapped in
Cast
if the sign is positive. OtherwiseCastError
.If the type of the RHS can be cast to that of the left, the RHS is wrapped in
Cast
.Otherwise
IncompatibleTypes
is recorded.Several tests of these new behaviors are included.
A few details of things added:
Type
of integer literal. Before we had UInt even though in the data we stored the sign of the literal. The type is nowInt
.IncompatibleDimensionError
andCastError
. The latter is for trying to cast a negative integer literal to an unsigned type. We could perhaps to do better. Perhaps just make this anIncompatibleTypes
error instead.