Wrong metadata-feature-body error?

Hi guys,

I’m getting a metadata-feature-body validation error when defining a metadata field that concatenates strings.

Example model:

package Package {

    metadata def MyMetadata {
        attribute strParam1 : ScalarValues::String;
        attribute strParam2 : ScalarValues::String;
        attribute strParam3 : ScalarValues::String;
    }

    attribute packageLevelReusableString = "string1";

    part def MyPart2 {

        attribute reusableString = "string2";

        enum def EnumDef {
            EnumValue = "string3";
        }

        @MyMetadata {
            strParam1 = "static_" + packageLevelReusableString;
            strParam2 = "static_" + reusableString;
            strParam3 = "static_" + EnumDef::EnumValue;
        }
    }
}

Script:

import syside

# model, diag = syside.try_load_model(['model.sysml'])  # v0.11.0
model, diag = syside.try_load_model_unlocked(['model.sysml'])  # v1.0.1
print(diag)

with model.documents[-1].lock() as doc:
    root_node = doc.root_node
    package: syside.Package = root_node.children.elements[0]

    metadata_el = package.children.elements[2].children.elements[2]
    assert isinstance(metadata_el, syside.MetadataUsage)

    for usage in metadata_el.children.elements:
        # value, report = syside.Compiler().evaluate_feature(usage, usage, model.lib)  # v0.11.0
        value, report = syside.Compiler().evaluate_feature(
            syside.vm.Context(model.lib), usage, usage)  # v1.0.1
        assert not report.fatal
        print(f'{usage.name} = {value}')

Output:

model.sysml:21:25: error (metadata-feature-body): Metadata body feature value must be model-level evaluable
strParam1 = static_string1
strParam2 = static_string2
strParam3 = static_string3

I’m getting the error only for strParam2 (highlighting "static_" + reusableString), however attribute value evaluation is correct!

The only difference is that reusableString is inside a part def, whereas the other is not (strParam1). However, an enum def inside a part def is fine (strParam3)…

Is this an error on my part or an oversight in Syside?

Greetings,
Jasper

Hi Jasper,

This is consistent with the specification where for FeatureReferenceExpression to be model-level evaluable:

What this means is that the referenced feature may have a different value depending on the context, though I think that the specification is inconsistent here because a bound feature value cannot be redefined anyway. In this case, model-level evaluable should be propagated from the feature value alone.

Evaluation has nothing to do with the diagnostic as the current evaluation sits somewhere in between model-level and full runtime.

Thank you for the clarification.
Indeed in this case the value is bound, so it can’t change in different contexts…