I have a function like this:
function(append_one ones)
list(APPEND one_more ${${ones}} "1")
set(${ones} ${one_more} PARENT_SCOPE)
endfunction()
So that I can call it repeatedly:
append_one(mylist)
append_one(mylist)
append_one(mylist)
append_one(mylist)
mylist would accordingly be "1;1;1;1" and everything is fine.
Now, for the same reason i called my function parameter ones, the caller might come to the same naming-decision:
append_one(ones)
append_one(ones)
append_one(ones)
append_one(ones)
And this is where everything breaks. Inside append_one ${ones} == "ones", therefore ${${ones}} == "ones" and so on. The result on the caller's side is then ${ones} == "ones;1". The parameter shadows the variable from the parent scope and dereferencing thus resolves to itself. This is in contrast to mylist as the variable name, where ${ones} == "mylist" and ${${ones}} == "" or "1;1" etc..
The obvious answer is to just dont do that and not choose a name that results in the parameter shadowing my variable. However, I'm not always in control of the caller's side and this behavior could lead to some very surprising errors.
This leads me to my question: How do I properly deal with function parameters that possibly shadow variables in the parent scope? Do I plaster my functions with checks for ${ones} == "ones"? Is there some naming convention? Or do I just accept it and hope for the best?