There is no context to infer the closure's argument types from

In have 2 longer DSL rule files and each time they get loaded I’m getting some warnings, but they are still loaded and work fine.

However, I want to fix those issues, but have no clue where to look at, because the message doesn’t include a hint on the specific rule or line of code?

How can I narrow down the statements?

2023-08-14 21:00:34.926 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'roller.rules'
2023-08-14 21:00:39.903 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'roller.rules', using it anyway:
There is no context to infer the closure's argument types from. Consider typing the arguments or put the closures into a typed context.
There is no context to infer the closure's argument types from. Consider typing the arguments or put the closures into a typed context.
2023-08-14 21:00:40.010 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'scenes.rules'
2023-08-14 21:00:50.970 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'scenes.rules', using it anyway:
This expression is not allowed in this context, since it doesn't cause any side effects.

You’ll often see this error if you’ve declared and initialized a variable to null without providing a type. Since it’s initialized to null there is no hint to the parser to infer the type of the variable. This is the one exception to the rule-of-thumb to no force the type of variables in Rules DSL.

var myTimer = null; // generates warning
var Timer myTimer = null; // no warning

All I can recommend is look for all your variable definitions (and argument definitions if you have lambdas) and make sure they all are initially populated with something with a type and not null.

hmm

in roller.rules I have

val int offRollerSunrise = 45
val int offRollerSunset = 45
val int offRollerSunsetSZ = 120
val int offLightOn = 45
val int offLateOff = 240

and in scene.rules I have

val String source_tv = "tv:dvbs"
val String source_hdmi1 = "extInput:hdmi?port=1"
val String source_hdmi2 = "extInput:hdmi?port=2"
val String source_hdmi3 = "extInput:hdmi?port=3"
val String source_hdmi4 = "extInput:hdmi?port=4"

var String ChanName -> changed to var String ChanName = ""
var pos = Shutter_WohnZ_2sw.state -> changed to var Number:Dimensionless pos = Shutter_WohnZ_2sw.state

that’s it

That parts a bad idea in Rules DSL but not related to your specific problem. Rules DSL will fight against you if you try to force the types of your variables. And it’s outright stupid in the way it handles primitives so those should be avoided unless absolutely necessary. It looks like the parsing is O(x^n) process where n is the number of primitives involved in a calculation. I had one relatively simple calculation involving primitives that added minutes to how long it takes to load that rule on a relatively well provisioned Intel machine (not an RPi).

Do not force the types of variables unless they are initialized to null meaning there is no way for the parser to infer type.

val offRollerSunrise = 45
val offRollerSunset = 45
val offRollerSunsetSZ = 120
val offLightOn = 45
val int offLateOff = 240

If you just, use Number, not primitives. In those rare cases where you do need a primitive (e.g. a call to a Java class which required a primitive) wait until the last moment and then call intValue on the Number.

Anyway, back to the problem at hand.

So those are all of the global variables?

What about lambdas?

There is no such thing as a Number:Dimensionless in rules. That should be throwing a syntatic error. Assuming Shutter_WohnZ_2sw is a Number:Dimensionless do you mean:

var pos = Shutter_WohnZ_2sw.state as QuantityType<?>

or if you want to make sure it’s a percent

var pos = (Shutter_WohnZ_2sw.state as QuantityType<?>).toUnit('%')

Also again, what about lambda’s in this file too?

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.