# Why are unrelated symbols localized in Module? [duplicate]

As I understand, an expression like Module[{var},expr[var]] localizes var and evaluates expr[var] with this localized symbol. But the following code behaves as if a pattern created inside the Module were also somehow localized, unlike the variable inside the first part of Module call:

Clear[f, g]
Module[{dsol = DSolve[f''[x] == w^2 f[x], f[x], x]},
g[x_, w_] = f[x] /. First@dsol]


If I replace Module with Block, then, of course, the expression evaluates as expected. But I would still like to make sense of the behavior. So here's the difference between the evaluation in Module and Block:

1. Module:
Clear[f, g]
Module[{dsol = DSolve[f''[x] == w^2 f[x], f[x], x]},
Print[dsol // FullForm];
Print[f[x] // FullForm];
FullForm@Hold[g[x_, w_] = f[x] /. First@dsol] /. HoldPattern[First@dsol] :> RuleCondition[First@dsol]
]

List[List[Rule[f[x],Plus[Times[Power[E,Times[w,x]],C],Times[Power[E,Times[-1,w,x]],C]]]]]
f[x]
Hold[Set[g[Pattern[x$$,Blank[]],Pattern[w$$,Blank[]]],
ReplaceAll[f[x$],List[Rule[f[x],Plus[Times[Power[E,Times[w,x]],C], Times[Power[E,Times[-1,w,x]],C]]]]]]]  1. Block: Clear[f, g] Block[{dsol = DSolve[f''[x] == w^2 f[x], f[x], x]}, Print[dsol // FullForm]; Print[f[x] // FullForm]; FullForm@Hold[g[x_, w_] = f[x] /. First@dsol] /. HoldPattern[First@dsol] :> RuleCondition[First@dsol] ]  List[List[Rule[f[x],Plus[Times[Power[E,Times[w,x]],C],Times[Power[E,Times[-1,w,x]],C]]]]] f[x] Hold[Set[g[Pattern[x,Blank[]],Pattern[w,Blank[]]], ReplaceAll[f[x],List[Rule[f[x],Plus[Times[Power[E,Times[w,x]],C], Times[Power[E,Times[-1,w,x]],C]]]]]]]  Notice how the patterns and placeholders in the former case become x$, w\$ while in the latter they don't. So what's happening? Why are these symbols, in addition to dsol, being localized by Module?