# Unexpected evaluation behavior for typed elements

**URL:** <https://forum.sensmetry.com/t/unexpected-evaluation-behavior-for-typed-elements/288>\
**Category:** Bug Reports\
**Tags:** automator, sysmlv2\
**Created:** [November 8, 2025, 8:35pm UTC](https://forum.sensmetry.com/t/unexpected-evaluation-behavior-for-typed-elements/288 "2025-11-08T20:35:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbussemaker](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@jbussemaker](https://forum.sensmetry.com/u/jbussemaker)\
**Post date:** [November 8, 2025, 8:35pm UTC](https://forum.sensmetry.com/t/unexpected-evaluation-behavior-for-typed-elements/288/1 "2025-11-08T20:35:27Z")

</div>

Hello,

See the model below:

```sysml
package CalcTypingTest {
    part def A {
        attribute b : ScalarValues::Real;
        attribute c : ScalarValues::Real = 5.0;
        attribute d : ScalarValues::Real = b * c;
    }
    part a : A {
        :>> b = 3.0;
        assert constraint { d == 15.0 }
    }
}

```

When I try to load the model and evaluate the constraint in part a, I get the following error:

```auto
<source>:5:44: error (type-error): Invalid operator '*' for types 'element' and 'rational'

```

What I would have expected is that the constraint evaluates to true, because b is redefined in the part usage.

I used the following code:

```python
import syside

model, _ = syside.load_model(['calc_typing.sysml'])
with model.documents[0].lock() as doc:
    # Get the constraint in part a
    package: syside.Package = doc.root_node.children.elements[0]
    part_a: syside.PartUsage = package.children.elements[1]
    constraint: syside.AssertConstraintUsage = part_a.children.elements[1]
    assert isinstance(constraint, syside.AssertConstraintUsage)

    # Evaluate the expression
    expression = constraint.asserted_constraint.result_expression
    evaluated_value, report = syside.Compiler().evaluate(expression, model.environment.lib)

    print(evaluated_value)
    if report.fatal:
        print('\n'.join([str(diag) for diag in report.diagnostics]))

```

Greetings,  
Jasper

---

<div class="post-metadata">

**Author:** ![Daumantas](https://yyz2.discourse-cdn.com/flex008/user_avatar/forum.sensmetry.com/daumantas/32/19_2.png) [@Daumantas](https://forum.sensmetry.com/u/Daumantas)\
**Post date:** [November 10, 2025, 7:18am UTC](https://forum.sensmetry.com/t/unexpected-evaluation-behavior-for-typed-elements/288/2 "2025-11-10T07:18:58Z")

</div>

Hi Jasper,

This happens because `d` is being evaluated in the scope of `A` (technically in the scope of constraint) which has no `b` value. You need to add `scope=part_a` to `Compiler().evaluate(...)`, e.g.

```python
evaluated_value, report = syside.Compiler().evaluate(
    expression, scope=part_a, stdlib=model.environment.lib
)

```

It then prints `True`.

---

<div class="post-metadata">

**Author:** ![jbussemaker](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@jbussemaker](https://forum.sensmetry.com/u/jbussemaker)\
**Post date:** [November 11, 2025, 8:20am UTC](https://forum.sensmetry.com/t/unexpected-evaluation-behavior-for-typed-elements/288/3 "2025-11-11T08:20:16Z")

</div>

Hi Daumantas,

Ah I missed that, this indeed fixes it but it is quite non-intuitive.  
Also, if I for example change the SysML model to:

```auto
package CalcTypingTest {

    part def A {
        attribute b : ScalarValues::Real;
        attribute c : ScalarValues::Real = 5.0;

        attribute d : ScalarValues::Real = b * c;
    }

    part a : A {
        :>> b = 3.0;
    }

    assert constraint { a.d == 15.0 }
}

```

And the Python script to:

```python
import syside

model, _ = syside.load_model(['model.sysml'])
with model.documents[0].lock() as doc:
    # Get the constraint in part a
    package: syside.Package = doc.root_node.children.elements[0]
    part_a: syside.PartUsage = package.children.elements[1]
    constraint: syside.AssertConstraintUsage = package.children.elements[2]
    assert isinstance(constraint, syside.AssertConstraintUsage)

    # Evaluate the expression
    expression = constraint.asserted_constraint.result_expression
    evaluated_value, report = syside.Compiler().evaluate(expression, model.environment.lib)

    print(evaluated_value)
    if report.fatal:
        print('\n'.join([str(diag) for diag in report.diagnostics]))

```

Then I have the same problem. Also this one is fixed by adding the scope, however you can imagine that there will be cases where there will be constraints that reference something somewhere else in the model, or even involve multiple elements (multiple scopes), and then I cannot use this scope mechanism anymore.

Best would be if Syside automatically determines which elements are involved and automatically applies redefinitions, without the user needing to add the scope.

Greetings,  
Jasper

---

<div class="post-metadata">

**Author:** ![Daumantas](https://yyz2.discourse-cdn.com/flex008/user_avatar/forum.sensmetry.com/daumantas/32/19_2.png) [@Daumantas](https://forum.sensmetry.com/u/Daumantas)\
**Post date:** [November 11, 2025, 8:34am UTC](https://forum.sensmetry.com/t/unexpected-evaluation-behavior-for-typed-elements/288/4 "2025-11-11T08:34:03Z")

</div>

> Best would be if Syside automatically determines which elements are involved and automatically applies redefinitions, without the user needing to add the scope.

I will see if we can figure something out.

Otherwise, `assert constraint { a.d == 15.0 }` evaluating `d` not in the scope of `a` looks like a separate bug.

---

<div class="post-metadata">

**Author:** ![Daumantas](https://yyz2.discourse-cdn.com/flex008/user_avatar/forum.sensmetry.com/daumantas/32/19_2.png) [@Daumantas](https://forum.sensmetry.com/u/Daumantas)\
**Post date:** [November 11, 2025, 8:56am UTC](https://forum.sensmetry.com/t/unexpected-evaluation-behavior-for-typed-elements/288/5 "2025-11-11T08:56:13Z")

</div>

> I will see if we can figure something out.

Changed the search to consider owning types if a match was not found in current scope. Will be in either 0.8.2 release or the next after.

> Otherwise, `assert constraint { a.d == 15.0 }` evaluating `d` not in the scope of `a` looks like a separate bug.

Already fixed for the next release, for [Mass rollup example from Introduction to the SysML v2 Language - #15 by Daumantas](https://forum.sensmetry.com/t/mass-rollup-example-from-introduction-to-the-sysml-v2-language/256/15)

---

<div class="post-metadata">

**Author:** ![jbussemaker](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@jbussemaker](https://forum.sensmetry.com/u/jbussemaker)\
**Post date:** [November 11, 2025, 9:16am UTC](https://forum.sensmetry.com/t/unexpected-evaluation-behavior-for-typed-elements/288/6 "2025-11-11T09:16:04Z")

</div>

Ah cool, I’ll try it out once the next release is ready 😃
