Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

type hinting #44

Open
Fusselwurm opened this issue Sep 1, 2018 · 5 comments
Open

type hinting #44

Fusselwurm opened this issue Sep 1, 2018 · 5 comments

Comments

@Fusselwurm
Copy link
Contributor

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", {}]); 
}
@LordGolias
Copy link
Owner

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.

@Fusselwurm
Copy link
Contributor Author

$ 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)

🤷‍♂️

@LordGolias
Copy link
Owner

Let me re-phrase: my argument is that this is a bug in the Linter: _foo should be Anything, not Nothing.

@Fusselwurm
Copy link
Contributor Author

yes. so on further experimentation, it seems tthat

_foo = call {
    call foo;
};
// _foo is Nothing
_foo = call {
    call foo
};
// _foo is Anything

@LordGolias
Copy link
Owner

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants