From the documentation of Function, I take this example (slightly simplified). Renaming the dummy or bound variable (y->y$ in the inner Function) is necessary in:
In[1206]:= Function[x, Function[y, f[x, y]]][y]
Out[1206]= Function[y$, f[y, y$]]
so that, for example,
In[1215]:= Function[x, Function[y, f[x, y]]][y][1]
Out[1215]= f[y, 1]
because
In[1211]:= Function[y$, f[y, y$]][1]
Out[1211]= f[y, 1]
Without renaming, we would obtain a different and generally wrong value
In[1212]:= Function[y, f[y, y]][1]
Out[1212]= f[1, 1]
The documentation shows that renaming occurs even if it is not necessary:
In[1213]:= Function[x, Function[y, f[x, y]]][1]
Out[1213]= Function[y$, f[1, y$]]
Indeed, the choice of parameter name y should have no consequence on the function value.
Now let me try:
In[1214]:= Function[x, Function[y, f[x, y]]][y$]
Out[1214]= Function[y$, f[y$, y$]]
which is the same as Function[y, f[y, y]] that is wrong, as explained above.
So it looks to me like a plain fat bug, is not it?
Edited after comments
The bug is equivalent to:
In[1335]:= With[{x = y$}, Function[y, f[x, y]]]
Out[1335]= Function[y$, f[y$, y$]]
In this related case on the contrary no renaming occurs:
In[1338]:= Function[y, f[x, y]] /. x -> y$
Out[1338]= Function[y, f[y$, y]]
That is because the job of ReplaceAll is just to replace, not to detect name conflict.
Uniqueor some such thing that couldn't be hacked. But the simple rule is, "Don't ever end your variables with a $." (A similar renaming occurs inDynamicModule, but with$$.) – Michael E2 Dec 28 '21 at 17:10Blockwas using internally single $-ending name but I can't prove it so I was probably mistaken. – Pierre ALBARÈDE Dec 28 '21 at 18:09Block[]does not rename variables.Module[]andDynamicModule[]rename variables, but they use a different mechanism than the one you're discussing. – Michael E2 Dec 28 '21 at 18:19Function[t, Function[u$, t + u$]]@u$where name conflict should be resolved byu$$but is not. Amazingly,Function[t, Function[u$$, t + u$$]]@u$$resolves name conflict withu$$$. This is weird. – Pierre ALBARÈDE Jan 04 '22 at 11:26With(notBlock) that also uses single $-ended names internally. The above link shows thatWithhas nearly the same problem asFunctionand indeedWith[{x=y},f[x]]may not be discernible fromFunction[x,f[x]][y]. – Pierre ALBARÈDE Jan 04 '22 at 11:40