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 results of the bound Expression(s) of a MultiplicityRange must be typed by ScalarValues::Integer from the Kernel Data Types Library. If a bound is 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-types

    Allows checking bounds conformance against natural instead 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 >= b even if a - b was not evaluable.