undeclared variables getting through in Strict Compilation mode
dochawk at gmail.com
Tue Feb 17 12:13:55 EST 2015
On Mon, Feb 16, 2015 at 10:14 PM, J. Landman Gay <jacque at hyperactivesw.com>
> It threw no error loading prAry, and it turned into the correct array.
>> Single step into the calling handler, and prAry and the global prAry was
> This is correct behavior, at least when explicit variables is off (if it's
> on, you shouldn't be able to compile at all.) An undeclared variable will
> be automatically created and will be local to that specific handler.
Agreed--but strict compilation was on (I always have it on, unless I want
to check one more thing after the shadow bug bites).
> Strict compilation was set in the preferences; I checked. I can't use
>> explicit variables without a significant code rewrite, as "long name"
>> produces a result that is incompatible with, well, livecode.
> I can't imagine why the long name would cause any trouble, but that's a
> different problem. Anyway, "strict compilation" is the same thing as
> explicit variables. Preferences just gives it a different, presumably more
> descriptive, name.
put "cd " & theLin & " of stack rawForms" into tgCd
if the scNam of tgCd is empty then
This works with strict compilation, but not explicitVariables.
And on further review, that's not the same form that comes from long name,
which is where I had thought that code was coming from.
> The issue here seems to be that you had explicit variables turned on but
> you didn't get a warning about the undeclared global variable.
>> I added "global prAry" after the local declarations, and everything worked
> Right. A global declared inside a handler can only be accessed within that
> handler. If you want to see and use it in other handlers, you need to
> declare it in each one where it's used. That's why when you stepped out of
> the handler it seemed to disappear. If you had checked "the globals" it
> should have been there, but you wouldn't see it in the variable watcher
> because it isn't available to that particular handler without a declaration.
> The alternative is to declare it once outside of all handlers, where it
> will be available to all of them below the declaration.
> So, if I understand right, you had explicit variables turned on but you
> didn't get a flag about the undeclared global. Instead, the editor acted as
> though explicit variables was off and automatically created a local
> variable. It may have something to do with the contortions the engine goes
> through to prevent conflicts with libraries that don't declare variables.
> (Richard G. discussed that a few days ago.) Basically it needs to turn off
> explicit variables, compile, and then reset it again to your preference
OK--but I don't have *any* external libraries. Could it be doing this with
its own libraries?
Dr. Richard E. Hawkins, Esq.
More information about the Use-livecode