Re: symbol resolution (was:EuCOM : Attn Matt : String Return Value)
- Posted by Matt Lewis <matthewwalkerlewis at ?m?il.com> Oct 11, 2007
- 862 views
Pete Lomax wrote: > > Matt Lewis wrote: > > > > What if main.e had also included libAmisc.e? > > > > }}} <eucode> > > main.e > > global Z > > include libAmisc.e > > if Z then > > include libA.e > > global Z > > include libAmisc.e > > if Z then > > </eucode> {{{ > > Now how would the interpreter handle this? > > > Well, yes, that would break it for sure, ... but ... that code has been broken > since the year dot (without any warning) so I struggle to accept that example > as relevant. Yes, the point is that we're trying to fix things so that we can reasonably use third party code without having to modify any of it to make it play nicely together. This particular exercise is basically taking things to their logical conclusions, and to try to get it right the first time, rather than to have to revisit this later. I extended CChris' question to cover a more worrisome example, basically in an effort to explain why I disagreed with him. > > It has to be an error > <snip> > > I bet that I'll find a lot of this in various libraries of mine. > > I am quite worried that absolute torrents of the warning you propose will > occur > in legacy code. On a lesser note, it seems to me that while you could give > said > warning in the libA standalone case, it would be nigh on impossible for the > code snippet above to actually produce a compile error? Why are you worried? Adding a warning doesn't create the problem, it just alerts us to a problem that already exists, and gives us a chance to fix it before it starts causing problems. While there are some warnings that can be ignored (like short circuits--assuming you understand the implications), this is one that should really be corrected. You're right about the compile error. The problem here is that it would use the *wrong* Z, so not a compile error, but a bug that could be fixed based on the warning. Here's how you might get a compile error:
--main.ex global constant Z = "main" include libA.e --libA.e global constant Z = "libA" include libAmisc.e --libAmisc.e printf(1, "libAmisc.e: Z = '%s'\n", {Z})
Now, if you include libAmisc.e in main.ex before libA.e, you'll get the wrong Z. Or, if libA.e is included before Z is declared in main.ex, you'll get the correct Z, but only as long as there's not a Z declared earlier (including, of course, in files like libB.e). Now, as a thought experiment, replace Z with something like TRUE. Matt