Discouraged use of the feature 'occurrence'. What should we do?

16 views
Skip to first unread message

Dani Manjah

unread,
Sep 11, 2019, 10:43:09 AM9/11/19
to sarl
Hello, 

I have been developping recently in SARL for my research project in MAs at UCLouvain. 

Till now, all have been quite good however, I have a question aboute occurrence. Indeed, I am faced with this issue that when I access an event attributes I receive a warning : Discouraged use of the feature occurrence. 

Example of a code : 
 
event ElementInformation {
    val information : UDP_Message_Base
    
    new(info : UDP_Message_Base) {
                this.information = info}}

behavior ElementRole {
uses Logging, ElementCapacity

on ElementInformation {
                   InformationAnalysis(occurrence.information)
}}

Launches : 
Discouraged use of the feature 'occurrence'. You should not use the feature 'occurrence', or one of its member as argument of an action because it may be change by a border effect.

Why is this warning raised and how could we do things properly? 

Thank you,
Dani Manjah

Stéphane Galland

unread,
Sep 12, 2019, 10:23:41 AM9/12/19
to sarl
Dear Dani.

This warning is normal, and may considered by the SARL developpers in order to have a code without "bugs".

In the semantic specification of SARL, events are assumed to be "read-only" structures in order to avoid any invalid side-effects when an multiple event handlers are run on the same event, such as:

on ElementInformation {
   // do something with the occurrence
}

on ElementInformation {
  // do another thing with the occurrence
}

In the previous example, the two "occurrence"s point to the same event instance.
The warning is generated by the SARL compiler when it cannot determine if side effect may be applied to the occurrence instance.

In your example: "InformationAnalysis(occurrence.information)"
the SARL compiler cannot be sure that the InformationAnalysis function is changing the content of the "information" field of occurrence (refer to the parameter passing by reference from the Java specification).
Then, the SARL compiler generates a warning to notify you about this case and for ensuring by yourself that this usage of occurrence does not produce side effect.

If you are sure that your code does not apply a side effect on the occurrence, then you could ignore this warning.

Any way, the next version of SARL will have a more detailled warning message in order to make the understanding easier.

All the best.
Reply all
Reply to author
Forward
0 new messages