Bug 3506 – [module] Imports should be valid at any scope

Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2009-11-13T16:37:00Z
Last change time
2015-06-09T05:13:49Z
Assigned to
nobody
Creator
leandro.lucarella

Comments

Comment #0 by leandro.lucarella — 2009-11-13T16:37:38Z
Imports should be valid at any scope, like classes, structs, and functions. This is specially useful for unit tests for example, currently this idiom is needed: version (unittest) import foo; unittest { foo.bar(); } It would be much nicer to be able to just write: unittest { import foo; foo.bar(); } This brings more locality to the code. This limitation is like C's (pre C99) inability to add variable declarations after the first statement. It easier to refactor code this way too, if I move the unittest (function, class or whatever) to another file, my imports are moved too without any further work, now I have to track all the import and remove/add appropriately.
Comment #1 by code — 2012-02-14T05:40:37Z
cat > foo.d << CODE void bar() {} CODE cat > ut.d << CODE unittest { import foo; foo.bar(); } CODE dmd -c -unittest ut.d