SkaceKamen / vscode-sqflint

SQF Language server extension
MIT License
19 stars 9 forks source link

Problems linting macro expansions #125

Open mwpowellhtx opened 1 year ago

mwpowellhtx commented 1 year ago

This did not appear to be an issue a day or so ago, unless possibly there was a dependency update or something like that. I have not investigated that aspect. Currently running v0.12.1 although apparently the latest documented branch is v0.12.0 maybe that was never pushed, I do not know.

Okay, on with the specific report. Have some macro definitions, i.e.

#define HTRES_SET3(obj,var,val,pub) obj setVariable ["KPLIB_htres" + #var,val,pub]
#define HTRES_SET2(obj,var,val) obj setVariable ["KPLIB_htres" + #var,val]
// // Have tried with and without the macro expansions, same results
// #define HTRES_SET(obj,var) obj setVariable ["KPLIB_htres" + #var,var]
#define HTRES_SET(obj,var) HTRES_SET2(obj,var,var)

And in the SQF code:

HTRES_SET2(_target,_unitPos);

And as far as I can tell the same line in natural language form, not macro code generated, is fine.

_target setVariable ["KPLIB_htres_unitPos", _unitPos];

But that's sort of the point, the macro shorthand, to save a breath and/or a keystroke or two and not get stuck in the weeds of the longhand, needs to be dependable without throwing spurious false positives. Illustration below; I'll walk you through it.

image

  1. Lift the function from the namespace. Verified that is there.
  2. Invoke that function with the _mission. Have verified that the call works, yields correct results, although LINT is not a runtime thing, so would not know this.
  3. Then we want to set the _unitPos should be expanding as "KPLIB_htres_unitPos" variable on the _target object. Again, appears fine in natural language form, but seems to have broken in some recent version of LINT and/or one of its dependencies.

And for reference purposes, identifying the _target object correctly from the _mission object. Have verified I have both.

image

And the error:

[{
    "resource": "/l:/Source/Arma/Arma 3/KP-Liberation/kp-lib-refactor-mwpowellhtx/Missionframework/modules/0936_htres/fnc/fn_htres_onStartingCalculateContainerUnitPos.sqf",
    "owner": "_generated_diagnostic_collection_name_#1",
    "severity": 8,
    "message": "Encountered \",\".\r\nWas expecting one of:\r\n    \"=\" ...\r\n    \">\" ...\r\n    \"<\" ...\r\n    \">=\" ...\r\n    \"<=\" ...\r\n    \"!\" ...\r\n    \"not \" ...\r\n    \"==\" ...\r\n    \"||\" ...\r\n    \"&&\" ...\r\n    \"+\" ...\r\n    \"-\" ...\r\n    \"*\" ...\r\n    \"/\" ...\r\n    \"^\" ...\r\n    \"%\" ...\r\n    \"mod\" ...\r\n    \">>\" ...\r\n    \"#\" ...\r\n    \"switch\" ...\r\n    \"true\" ...\r\n    \"false\" ...\r\n    \"try\" ...\r\n    \"with\" ...\r\n    \"then\" ...\r\n    \"exitWith\" ...\r\n    \"throw\" ...\r\n    \"else\" ...\r\n    \"if\" ...\r\n    \"waitUntil\" ...\r\n    \"findIf\" ...\r\n    \"apply\" ...\r\n    \"select\" ...\r\n    \"and\" ...\r\n    \"or\" ...\r\n    <INTEGER_LITERAL> ...\r\n    <FLOATING_POINT_LITERAL> ...\r\n    <STRING_LITERAL> ...\r\n    <STRING_LITERAL_OTHER> ...\r\n    <IDENTIFIER> ...\r\n    \"(\" ...\r\n    \")\" ...\r\n    \"{\" ...\r\n    \"[\" ...\r\n    \"!=\" ...\r\n    ",
    "source": "sqflint",
    "startLineNumber": 48,
    "startColumn": 9,
    "endLineNumber": 48,
    "endColumn": 10
}]

I have no idea what this means, it certainly seems to be a false positive, maybe a white space issue, who knows.

Current vscode details, yes, I know, a bit behind the current 1.74.1 whatever it is, but still, the actual sqflint plugin has not changed, unless maybe one of its feature dependencies has changed from under it.

Version: 1.68.1 (system setup)
Commit: 30d9c6cd9483b2cc586687151bcbcd635f373630
Date: 2022-06-14T12:48:58.283Z
Electron: 17.4.7
Chromium: 98.0.4758.141
Node.js: 16.13.0
V8: 9.8.177.13-electron.0
OS: Windows_NT x64 10.0.19041
mwpowellhtx commented 1 year ago

So, when I use the correct macro, then I get warning, again, seems like a false positive.

private _unitPos = [_mission] call _calculateContainerUnitPos;
HTRES_SET(_target,_unitPos);
// Expanded code equivalent:
_target setVariable ["KPLIB_htres" + "_unitPos", _unitPos];
//                                               ^^^^^^^^

The warning:

[{
    "resource": "/l:/Source/Arma/Arma 3/KP-Liberation/kp-lib-refactor-mwpowellhtx/Missionframework/modules/0936_htres/fnc/fn_htres_onStartingCalculateContainerUnitPos.sqf",
    "owner": "_generated_diagnostic_collection_name_#1",
    "severity": 4,
    "message": "Possibly undefined variable var",
    "source": "sqflint",
    "startLineNumber": 48,
    "startColumn": 49,
    "endLineNumber": 48,
    "endColumn": 52
}]

Which I suppose is a plausible warning, but even when I feed _unitPos a hard, not assumed functional return, value, I get the same thing, i.e.

_unitPos = 1;
SkaceKamen commented 1 year ago

Yea the macro expansion is very rough (it's incomplete, I know), I'll look into it if I have time but no promise :)

mwpowellhtx commented 1 year ago

No worries, thanks. Some of it here was my own confusion, includes, definitions, etc. But there are still 'moments'. Thanks...

mwpowellhtx commented 1 year ago

Also maybe a helpful take away... Do A3 SQF includes benefit from header guards in the same way that C/C++ headers have guards? i.e.

#ifndef SUCHANDSUCH
#define SUCHANDSUCH

#endif // SUCHANDSUCH