Re: 4.0 Beta 2 Due Out on Tuesday, got your bug reports in?

new topic     » goto parent     » topic index » view thread      » older message » newer message
ChrisB said...

Oh, I see, so with warning effectively overrides without warning.

Yes, and does that surprise you? The reverse is also true - without warning overrides with warning

ChrisB said...

I would say however there is an ambiguity in there, since the code with the 'disputed' variable occurs after the without warning, so without warning should turn off warnings until they are turned back on again with with warning. This just seems the logical way to do it to me. Maybe not the easier way though.

That is exactly what is happening already. The usage checking occurs whenever a block of code ends - such as the end of a routine, a 'switch', a loop, a source file, ... When a block ends, usage of variables declared in that block is checked using whatever the warning setting is at that time.

In this specific instance, just before the end of the file, the warnings are turned on. So when the end of file is reached, Euphoria checks the usage of variables declared at the file level, based on that with warnings statement. Thus we get the message. This is not a bug in the warning reporting system. If anything is a bug it is that final line of code. It should be removed.

But that begs the question, "why is check_calls declared at all and why is it assigned anything?" Both the declaration and the assignment are redundant and could be seen as a coding mistake - thus the warning.

Now consider what you seem to be asking for - that declarations occuring whilst a without warning is active should be immune from usage checking.

---- file begins ---- 
without warning 
integer foo 
procA() 
with warning 
procB() 
---- file ends ---- 

When this file ends, foo is still not used and warnings are on. So should a message be issued or not? Remember, usage checking occurs at the end of a block, which is when variables go out of scope. (Of course none of this applies to exposed variables - global, public, or export ones.) If we didn't do usage checking at the end of a block, when else could be do it? It doesn't make sense to do it while a variable is still in scope because it cound have been used after the usage check.

It is hard to see the intention of the author of v3 machine.e, but I think what was being attempted by the final with warning was to restore the warnings to whatever they were when the file began. But as you can see, this is not the way that usage checking works. Now, in OpenEuphoria v4 we have better ways to do that sort of thing.

---- file begins ---- 
with warning save -- Save whatever warnings are active 
without warning 
integer foo 
procA() 
with warning restore -- Restore from the last save point. 
procB() 
---- file ends ---- 
ChrisB said...
someone said...

The warning is properly triggered since the declared variable never appears to the right of an equals sign.

Yes it does though

-- variables and routines used in safe.e 
without warning 
integer check_calls 
check_calls = 1 

What do you mean by "Yes it does though"? The example code you supplied does not issue any warning message.

By the way, OpenEuphoria now issues differently worded messages now ...

-- variables and routines used in safe.e 
with warning 
integer check_calls 
check_calls = 1 

Warning ( not_used ): 
    <0320>:: testw.ex - module variable 'check_calls' is assigned but never used 

-- variables and routines used in safe.e 
with warning 
integer check_calls 

Warning ( not_used ): 
    <0229>:: testw.ex - module variable 'check_calls' is not used 

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu