Why import statements are not allowed in function bodies (or any block of code)?

Bill Baxter dnewsgroup at billbaxter.com
Sun Jan 27 19:16:25 PST 2008


Leandro Lucarella wrote:
> Is there any good reason for not allowing import statements in function
> bodies or any code block? I think it would be really useful for avoid
> namespace polution, specially in unittests (it's really ugly to import
> things a module will never use except for unittesting).
> 

Did someone already suggest using the version(UnitTest) workaround?

I do remember hearing some reason before, like it makes it easier for 
tools to scrape out all the imports from a file.  But seems like a lame 
excuse to me now that DMD can spit out a list of imports itself.  I 
would guess it's just a matter of not having a pressing enough need for 
it.  But it would be nice.

--bb



More information about the Digitalmars-d mailing list