-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check types of LHS and RHS in assignment "to identifier" (#187)
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 * If types have same base array type, but dimensions differ, an `IncompatibleDimensionError` is recorded. This is tested, for example, with ``` bit[3] b; qubit[2] q; b = measure q; ``` * If 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. Otherwise `CastError`. * 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: * Fix erroneous `Type` of integer literal. Before we had UInt even though in the data we stored the sign of the literal. The type is now `Int`. * Introduce semantic errors: `IncompatibleDimensionError` and `CastError`. 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 an `IncompatibleTypes` error instead.
- Loading branch information
Showing
6 changed files
with
177 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters