(#5129) Freeze variables after creating them

Variables are supposed to be immutable within a scope, so we freeze them
after creation to avoid any changes to them.