This is issue #15602. Closures’ underlying top-level method tables are made when the surrounding function is defined because a function call that rebuilds a method table (which we can do to global scope functions with @eval) is a lot slower than one that conditionally assigns one of several existing functions to a variable. At least now we get a warning, and it should be heeded because we could either get the “all definitions run” effect or the “redefinitions become failed assignments” effect.
It’s fine in the global scope, it’s just a footgun during a repeatable function call.
Incidentally, the let block isn’t necessary here, x -> x^m stably captures the value because there’s only 1 assignment with a type-stable value. if flag m=2 else m=3 end would be problematic though, in which case the let block helps.