Require a range constraint in ConstrainedScalarSubtypeSymbol - #172
Conversation
VHDL's `range_constraint` rule is `**range** range`, so a subtype indication is either a bare type mark - modelled as `SimpleSubtypeSymbol` - or a type mark followed by the `range` keyword *and* a range. A form like `integer range` doesn't exist, which leaves `ConstrainedScalarSubtypeSymbol` without a state where its constraint is absent. The `constraint` parameter therefore loses its `None` default and is typed `Range` instead of `Nullable[Range]`, in `ScalarConstraint` as well as in `ConstrainedScalarSubtypeSymbol`. The `Constraint` property is non-optional accordingly. A range constraint written as a range attribute (`natural range vector'range`) is a range too: `RangeFromName` referring to a `RangeAttributeSymbol`. It is now shown as a second example on the class and covered by a testcase, because that form was the reason the parameter was optional. Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Documentation | 4 minor |
| ErrorProne | 2 critical |
🟢 Metrics 0 complexity · 0 duplication
Metric Results Complexity 0 Duplication 0
🟢 Coverage 100.00% diff coverage · +0.00% coverage variation
Metric Results Coverage variation ✅ +0.00% coverage variation Diff coverage ✅ 100.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (6e8fca2) 5219 4641 88.93% Head commit (d7c8157) 5219 (+0) 4641 (+0) 88.93% (+0.00%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#172) 3 3 100.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #172 +/- ##
=======================================
Coverage 87.14% 87.14%
=======================================
Files 24 24
Lines 5219 5219
Branches 446 446
=======================================
Hits 4548 4548
Misses 578 578
Partials 93 93
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
|
/cc @domWalters |
|
CI: 53 jobs succeeded, 9 skipped, 1 failed — run 30947957072. All unit-test jobs pass on every platform and Python version. The one failure is
The |
Co-authored-by: Patrick Lehmann <Paebbels@gmail.com>
Changes
ConstrainedScalarSubtypeSymbol's range constraint is now mandatory.VHDL's grammar leaves no state in which this class has no constraint:
The
rangekeyword is always followed by a range, so a subtype indication is either a bare type mark — modelled asSimpleSubtypeSymbol— or a type mark with a range. There isintegerand there isinteger range 0 to 5, but nointeger range.constraintloses itsNonedefault and is typedRangeinstead ofNullable[Range], inScalarConstraintas well as inConstrainedScalarSubtypeSymbol.Constraintproperty returnsRange.Documentation
ScalarConstraintstates why the range is mandatory, citing therange_constraintrule.ConstrainedScalarSubtypeSymbolgained a second example for the range-attribute form,subtype index is natural range vector'range;, which is aRangeFromNamereferring to aRangeAttributeSymbol. That form was the reason the parameter was optional, and it is a range like any other.Unit Tests
test_ScalarConstraint_RangeIsMandatoryandtest_ConstrainedScalarSubtypeSymbol_withoutConstraintnow assert that omitting the constraint raises aTypeError; previously both asserted thatConstraintisNone.test_ScalarConstraint_WithRangeAttributecovers the range-attribute form.465 tests pass (was 464).
Notes
range <>— as intype matrix is array (natural range <>) of bit;— is anindex_subtype_definition, not a subtype indication.ArrayTypemodels it as a dimension (List[Range]), so it never reaches this class.This is a breaking change, so the next release is a minor one: v0.39.0 rather than v0.38.1. #168 has to be retitled and its version bump adjusted once this is merged.
pyGHDL.dom needs a companion change.
GetScalarConstrainedSubtypeFromNodepassesNonewhen GHDL reports the range constraint as anAttribute_Name, with a# TODO: Get actual range from AttributeName node?. Nothing raises, so this is not a crash — butConstraintwould holdNonein violation of its type._Translate.pyalready builds exactly the right object one function further down (RangeFromName(node, RangeAttributeSymbol(node, GetName(node)))), so the fix is a few lines. Filed in the findings notebook.