this is correct.
but the issue here the strange behavior (which is allowed thought with warning).
so, in your opinion that a warning is issued so you are in your own , or should it be a bug report specially we did not know from where such behavior originate.
If you lie by saying something is const and then modifying it then bad stuff can happen (and you get a warning). Why this is allowed at all is for convenience when working in the REPL.
I’d argue that when the compiler detects the code is doing something that will produce incorrect/irrational behavior, it should be an error not a warning.
I don’t see what’s gained by making a warning into an error. The “strange” behavior will not cause the runtime to behave in any strange way by itself so this is very different from other cases where we throw an error since there’s no way we can proceed. In general, the warning are not printing to be ignored.
the warning tell the user take care the value of a constant changed.
but it is a lie the constant have two values old and new. i think it should change the value from old value to the new one.
That’s not possible to do (at least AFAIU not trivially). The choice is to either change the warning to be more descriptive or make it an error to redefine a constant.
@yuyichao
It probably isn’t easy to do, but then again Julia already has immutable types. How about converting the type of the constant quantity to an immutable type (perhaps behind the scenes)?
I’m not exactly sure what you are suggesting but it’s already an immutable type in this case. FWIW, turning that warning into an error is trivial, just that it’s unclear what it helps. For people doing interactive work it allows the code to work with the caveat that the function using them should be redefined for the effect to be seen consistently. For people doing this by accident, the warning should be a clear enough signal. For the runtime itself, this won’t cause any crashing so it is OK to keep running.