question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
gallandarakhneorgcommented, Aug 17, 2020

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.

1reaction
gallandarakhneorgcommented, Jun 22, 2020

Excellent, happy to help with “testing” and “breaking things” (the easy part…) 😉

Now, per se, occurrence.configFile is a String field in the event object and COULD be potentially changed right? The thing is that debug does not change that at all. Is this what you mean? But how does SARL know if a given function (debug here) changes or not an argument? It is a String object so it can be changed right?

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.

Ohh is is the case that any changes to String will actualy generate a new String, not just change the referenced one? So yes any String cannot be changed per se. But this is just because it is a String, this reasoning does not apply in general.

It applies to all the types that are known to be immutable. There is a couple of them: Number, URL, UUID, etc.

So are you saying that the SARL compiler should never care about Strings passed as arguments?

Yes. Because it cannot have synchronization issue with them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RequestCache being used in an invalid context - Jira - Atlassian
Each occurrence of "RequestCache being used in an invalid context" is a separate bug. These are the two specific issues that describe these...
Read more >
HTMLInputElement: invalid event - Web APIs | MDN
The invalid event fires when a submittable element has been checked for validity and doesn't satisfy its constraints.
Read more >
Invalid value for prop `reset` on <input> tag - Stack Overflow
Issue. You are passing a reset prop/attribute to an input element that is an invalid attribute value, it's a function, not a string...
Read more >
Troubleshoot directory synchronization errors with event 6941
Cause. This issue may occur if user objects in the on-premises Active Directory Domain Services (AD DS) schema have duplicate or invalid alias...
Read more >
ANDI - Alerts
When ANDI is launched, it automatically analyzes every HTML element currently on the page looking for conditions that cause accessibility issues.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found