Part of the reason OP liked the `if assignment` was to avoid polluting the higher-level scope with a variable that is only needed during the if statement.
Your solution fixes the error, but at the cost of losing the upside OP saw.
The issue is now you have a potential nil value hanging around in the code with no real reason for its existence. Three refactors and some moving around later and you manage to hit a runtime panic in production.
Your solution fixes the error, but at the cost of losing the upside OP saw.