kayler-renslow / arma-intellij-plugin

A plugin for Intellij IDEA that allows for syntactical analysis, code inspections, and other nifty features for the SQF scripting language in Arma 3.
MIT License
41 stars 10 forks source link

Inspection & BI's magic variables #54

Closed PopinjayJohn closed 6 years ago

PopinjayJohn commented 6 years ago

Plugin Version

1.0.9

Summary

Inspector "Privatization and declaration" should ignore BI's "magic" variables.

Detail

Using BI's "magic" variables such as "paramsArray" makes inspection throw "variable uninitialized", unwanted as it is an variable from the engine and thus always exists. Inspector should ignore any BI magic variables and maybe even warn if trying to overwrite magic variables. However AFAIK there is no exhaustive list of such variables at the moment.

Some magic variables is also scope specific, if at all possible to check if they exist within the correct scope? e.g. thisList will only exist inside an trigger and should probably not be overwritten. Complicated by the fact that no list of scope>>variables exist.

Sidenote: You can find a few more at https://community.bistudio.com/wiki/Magic_Variables

dedmen commented 6 years ago

http://killzonekid.com/arma-scripting-tutorials-special-variables/ Here is a list. They are not "magic" actually. I don't know what you mean by paramsArray that's not a magic variable. Should also respect variables defined by params command but that's got nothing to do with the title or summary of this issue. Some magic variables is also scope specific All are.

editor script fields this, thisList, thisTrigger are special in a different way too. But I don't think that the IDE needs to consider them at all. They appear in Editor scripts which you don't see in the IDE. And if you use things like https://community.bistudio.com/wiki/setTriggerStatements they are in a string that the IDE doesn't parse for variables anyway.

kayler-renslow commented 6 years ago

The Privatization and Declaration inspection was removed in version 2.0.0 due to it being complicated, buggy, slow, and just plain wrong.

PopinjayJohn commented 6 years ago

@kayler-renslow Thank you for resolving the issue, and I hope something like it can be reintroduced in the future.

@dedmen Sorry but I think you misunderstand magic variables, They absolutely exist (well outside of the fantasy meaning) A magic or special, reserved, engine maintained/preset, predefined variable whatever you want to call it is the same thing, commonly A variable declared and maintained by the language/framework/engine and is used without first needing to be declared or fetched in the "code". As paramsArray is set by the engine it is very much a magic variable and overwriting magical variables will cause unintended consequences.

Yes to be pedantic every magic variable exists in a scope, paramsArray does indeed reside in the global scope but variables existing everywhere does not tend to be referred to as scope specific. No, variable declaration in params or any other way is indeed not relevant to this issue.

Yes some magic variables does indeed only exist inside of an specific scope, this, thisList and thisTrigger does only magically exist inside specific scopes without being declared and as such would normally be referred to as scope specific magic variable. No just because some magic variables only exist inside of specific scopes does not make them special in a different way, they very much function the same but locally instead of globally.

They appear in Editor scripts which you don't see in the IDE ? I very much can write scripts utilizing magic variables this, thisList and thisTrigger in the IDE without declaring them as they should never be declared anywhere by me and is declared upon running said script magically by the engine without my intervention. If I use setTriggerStatements I would not expect the IDE to find them as frankly, Writing code in strings to be run is wrong on so many levels.

I hope this cleared it all up for you.

dedmen commented 6 years ago

very much can write scripts utilizing magic variables this, thisList and thisTrigger in the IDE without declaring them as they should never be declared anywhere by me and is declared upon running said script magically by the engine without my intervention.

Problem is that the IDE cannot know if you script is called from somewhere where these variables exist. So you can either always consider them "magic" which would then not detect actual errors with them outside of that context. Or don't, which would then cause a false-positive if it is used in such a context.

Thanks for the paramsArray link. Wiki search didn't find that and I didn't know that existed. ~Are you sure that's a magic engine variable though? Not just a variable set by some BI script?~ Just checked. It's an engine variable together with param1, param2, updateOnly, disabledChatChannels and disabledVoNChannels

btw this, thisList and thisTrigger are actually normal local variables just without the leading underscore. Just in Triggers though. The Editor init script's this is a global variable in missionNamespace. You actually can't overwrite the trigger variables as they are readOnly. But you also don't get an error.