sqf
sqf copied to clipboard
type hinting
Hey, is there any way I can tell sqflint to assume a certain type for a var?
Explanation: I'm working with some code that is… rather dynamic, as in:
_foo = ["methodName", _parameters] call {
_this call (uiNamespace getVariable ["myScript", {}]);
};
…after which sqflint assumes _foo to be of type Nothing
.
Which is not very helpful, because it will then go and cry wolf at every corner.
Being able to hint to a type would be neat, for example:
/*string*/ _foo = ["methodName", _parameters] call {
_this call (uiNamespace getVariable ["myScript", {}]);
}
From the code alone, I would argue that _foo should be Anything
, not Nothing
. I.e. there is nothing from the code that sugests that _foo will be assigned to Nothing
.
$ python sqflint.py <<SQF
> _foo = ["methodName", _parameters] call {
> _this call (uiNamespace getVariable ["myScript", {}]);
> };
> if (_foo == "bar") then {
> hint "x";
> };
>
> SQF
[1,22]:warning:Local variable "_parameters" is not from this scope (not private)
[1,0]:warning:Local variable "_foo" assigned to an outer scope (not private)
[4,4]:warning:Local variable "_foo" is not from this scope (not private)
[4,9]:error:Binary operator "==" arguments must be [(String,String),(Config,Config),(Display,Display),(Control,Control),(TeamMember,TeamMember),(NetObject,NetObject),(Task,Task),(Location,Location),(Number,Number),(String,String),(Object,Object),(Group,Group),(Side,Side)] (lhs is Nothing, rhs is String)
:man_shrugging:
Let me re-phrase: my argument is that this is a bug in the Linter: _foo should be Anything, not Nothing.
yes. so on further experimentation, it seems tthat
_foo = call {
call foo;
};
// _foo is Nothing
_foo = call {
call foo
};
// _foo is Anything
Now I see. So, we take the last statement of call to take its return type. It happens that the Linter currently takes ; to denote when we want to return Nothing instead of Anything (wrongly). As a consequence, it made _foo to be Nothing.