multiplicity-range-bound-result-types
Available in: KerML, SysML
This checks that multiplicity range bounds expression is an integer.
Note that while the specification also says to check that the values are also
non-negative if the expression is model-level evaluable, this check is instead
moved to multiplicity-range-bounds rule for clarity as values are not types.
Specification
The
resultsof theboundExpression(s)of aMultiplicityRangemust be typed byScalarValues::Integerfrom the Kernel Data Types Library. If aboundis model-level evaluable, then it must evaluate to a non-negative value.
Example
attribute x : ScalarValues::Real;
part p [x]; // error
Use an integer, or better yet, natural:
attribute x : ScalarValues::Natural;
part p [x]; // ok
Options
lint.multiplicity-range-bound-result-typesAllows checking bounds conformance against
naturalinstead which cannot be negative by definition.Subtraction of two naturals can result in a negative value and returns an integer:
attribute a : ScalarValues::Natural; attribute b : ScalarValues::Natural; attribute c = a - b; part p [c]; // error
Cast the result to
Natural:attribute a : ScalarValues::Natural; attribute b : ScalarValues::Natural; attribute c = (a - b) as ScalarValues::Natural; part p [c]; // ok
While this may increase verbosity, it is also easier to manually review and add a constraint that
a >= beven ifa - bwas not evaluable.