vscode-rpgle icon indicating copy to clipboard operation
vscode-rpgle copied to clipboard

Lint Option: Input parameters not changed within a procedure should be specified with CONST

Open priceaj opened this issue 3 years ago • 8 comments

priceaj avatar Nov 18 '21 18:11 priceaj

Been thinking about this. Quite a lot to think about. One case I can think would be tricky is if a parameter gets passed into another procedure, and it's passed by reference and changed inside of it.

worksofliam avatar Jan 23 '22 20:01 worksofliam

I think you have to assume that if its not passed as a constant in the PI then it will be changed in the underlying procedure. This is fine though as Eventually you will get to the bottom of the stack and where the variable is not changed it will suggest it to be a CONST... then the procedure above will do the same... until we get back to the top level

priceaj avatar Jan 23 '22 21:01 priceaj

i.e. if a variable can be changed assume it will be changed

priceaj avatar Jan 23 '22 21:01 priceaj

Yup that makes sense! Unless the linter has the prototype and then we can tell if it's ref/const/value!

worksofliam avatar Jan 23 '22 21:01 worksofliam

Yeah although the PI/PR have to be aligned right?

priceaj avatar Jan 23 '22 21:01 priceaj

Ignore that I see what you are saying, yeah I think you need to look at the prototype for the called procedure, failing that you will need to look at the interface if its in the same source and a prototype is not declared

priceaj avatar Jan 23 '22 21:01 priceaj

Thinking about it, I think we also need to hope no one actually uses overloading!! Because then you have to match a signature of the call to one of the overloaded procedures (I'm not entirely sure what the rules are for this as I've never actually used it!)


Edit

Looks like Scott Klement has kindly put a presentation together for this: https://www.scottklement.com/presentations/Overloading%20Subprocedures%20in%20RPG.pdf

Although I do wonder if you hit an overload statement in the PR then just say it's a modification to the variable, and come back to it if anyone requests it!

priceaj avatar Jan 23 '22 21:01 priceaj

Good share - forgot about that completely!

worksofliam avatar Jan 23 '22 22:01 worksofliam