Invalid warning "Possible invalid usage of ‘occurrence’"
See original GitHub issue@gallandarakhneorg , I want to follow up on error 28a:
Message: Possible invalid usage of ‘occurrence’. A impure function is detected into the sequence of calls on ‘occurrence’. Because a impure function has a possible side effect and side effect is not allowed on ‘occurrence’, it may cause an unexpected or invalid running behavior. You have to ensure by yourself that the usage of ‘occurrence’ is valid
See the code that is giving me this warning (that I want to get rid of):
on E_SetupPlayer [occurrence.agentName == this.agentName] {
debug("Starting to register new behaviors and skills using {0} file", occurrence.configFile)
val teamRoles = occurrence.teamRoles
and the definition of the event is just:
event E_SetupPlayer {
var agentName : String
var configDir : String
var configFile : String
var teamRoles : Map<String, Integer>
var centralBuilder : String
new(agentName : String, configDir : String, configFile : String, teamRoles : Map<String, Integer>, centralBuilder : String) {
this.agentName = agentName
this.configDir = configDir
this.configFile = configFile
this.teamRoles = teamRoles
this.centralBuilder = centralBuilder
}
}
Now why a simple assignment like:
val teamRoles = occurrence.teamRoles
would give this warning, I am not using any (unpure) function at all. I don’t even know how one would re-write such assignment.
Thanks!
_Originally posted by @ssardina in https://github.com/sarl/sarl/issues/1010#issuecomment-646935197_
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top GitHub Comments
The SARL validator is now checking if the called feature is of immutable type (list of immutable types). If it is the case, no warning is generated because there is no chance to have a side-effect on the usage of
occurrence
.A
String
object is immutable by definition (same as in Java). Currently, except if a SARL function is declared as@Pure
, SARL assumes it is impure. But, this assumption may be wrong. That’s why the warning is make: notify the developper that a problem may exists.It applies to all the types that are known to be immutable. There is a couple of them: Number, URL, UUID, etc.
Yes. Because it cannot have synchronization issue with them.