Bug 3505 – [module] static imports should be binded to the leaf module, not the fully qualified name

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

Comments

Comment #0 by leandro.lucarella — 2009-11-13T16:29:18Z
Now static imports uses full qualified module names: static import foo.bar.baz; foo.bar.baz.f(); It would be much nicer to avoid a lot of typing to make them bind to the leaf module: static import foo.bar.baz; baz.f(); This removes a lot of clutter from static import and make renamed import almost useless. I do this manually most of the time: import baz = foo.bar.baz; baz.f(); Which is clumsier. This feature would be great specially if all imports are static by default (see bug 3503).
Comment #1 by wbaxter — 2009-11-14T08:37:38Z
Maybe something like this could be allowed to mean "import renamed to the leaf": import (foo.bar.)MyModule; Sometimes I do want the actually fully qualified name, like for a module like std.string. Having "string" mucks with the type "string". Or maybe parens around the part to keep: import foo.bar.(MyModule);
Comment #2 by leandro.lucarella — 2009-11-14T09:20:25Z
(In reply to comment #1) > Maybe something like this could be allowed to mean "import renamed to the > leaf": > > import (foo.bar.)MyModule; > > Sometimes I do want the actually fully qualified name, like for a module like > std.string. Having "string" mucks with the type "string". Or maybe parens > around the part to keep: > > import foo.bar.(MyModule); I think it's very unfortunate to have a module with the same name of an almost built-in type. Maybe the module can be renamed to std.str; or we can live with: import str = std.string; Another possibility is, if bug 3503 gets implemented, is to leave static import untouched. I think that's even a good idea for backwards compatibility. static import std.string; import std.algorithm; std.string.foo(); algorithm.sort();
Comment #3 by code — 2012-02-13T10:44:03Z
It seems that renamed imports are sufficient for this given how much code it would break.
Comment #4 by leandro.lucarella — 2012-02-13T11:10:27Z
(In reply to comment #3) > It seems that renamed imports are sufficient for this given how much code it > would break. You might want to close bug 3503 and bug 3504 then too, because they were part of the same proposal to rethink the module system. This also was before D2 was considered frozen and there was some place to make breaking changes, now I don't think it will happen until a very major update, which doesn't seems to be very close either.
Comment #5 by code — 2012-02-13T15:36:09Z
I have to say though that I fully agree with your proposals. Only it's a controversial thing and has way too much impact to be still considered.