Bug 264 – No selective static imports

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-07-22T07:57:00Z
Last change time
2014-02-15T13:22:21Z
Keywords
accepts-invalid, spec
Assigned to
bugzilla
Creator
matti.niemenmaa+dbugzilla

Comments

Comment #0 by matti.niemenmaa+dbugzilla — 2006-07-22T07:57:38Z
I'm not sure if this should be allowed, but it seems to me that the specification doesn't disallow it: -- static import std.stdio : writefln; void main() { std.stdio.writefln("bar"); } -- Currently this doesn't compile, as the import works the same way as it would without the "static". This is, in a way, understandable, as normal selective imports leave the imported module's name undefined. I nevertheless feel that this is a small loss in functionality. Allowing this might introduce a new issue, however. Consider the following: -- static import std.stdio : foo = writefln; void main() { std.stdio.foo("bar"); } -- The above might make it seem as though there is something called foo in the std.stdio package.
Comment #1 by bugzilla — 2006-07-22T13:39:02Z
The code is not allowed. std.stdio is not imported; only std.stdio.writefln is and is bound to a *local* name in the current namespace. Hence, std.stdio.writefln is rejected because std is undefined.
Comment #2 by matti.niemenmaa+dbugzilla — 2006-07-22T13:57:42Z
(In reply to comment #1) > The code is not allowed. std.stdio is not imported; only std.stdio.writefln is > and is bound to a *local* name in the current namespace. Hence, > std.stdio.writefln is rejected because std is undefined. > I realise that this is the current behaviour. If you believe this is how it should work, fine. But in that case, I think this should be rejected by the compiler: it's equivalent to the import statement without the "static" qualifier, and it's easy to misunderstand what's actually going on. Remove the "accepts-invalid" tag if you feel I'm wrong. In general, if the different types of imports should only work by themselves, it should IMHO be mentioned in the specification. The way I read the definition of ImportDeclaration, all work together --- and the compiler does accept them, but the behaviour doesn't seem logical (see also Issue 265). If static imports are actually static only when there're no ImportBindings, it should be mentioned, or the other form disallowed. Either way, the spec needs amending.
Comment #3 by bugzilla — 2006-08-11T19:15:43Z
Fixed DMD 0.164 (made static import with bind list illegal)