www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7330] New: Local imports are order sensitive

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7330

           Summary: Local imports are order sensitive
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: peter.alexander.au gmail.com



12:54:07 PST ---
According to the language reference: "The order in which ImportDeclarations
occur has no significance."

This is true for module scope imports in DMD (2.057 tested), but not for
function scope imports.

---
import std.stdio;
void main() {
  writeln("foo"); //ok
}
---
void main() {
  writeln("foo"); //ok
}
import std.stdio;
---
void main() {
  import std.stdio;
  writeln("foo"); // ok
}
---
void main() {
  writeln("foo"); // error, writeln undefined
  import std.stdio;
}
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 20 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7330


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr gmx.ch



I think what is meant in the reference is that the relative order of multiple
ImportDeclarations is insignificant.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7330




16:51:52 PST ---

 I think what is meant in the reference is that the relative order of multiple
 ImportDeclarations is insignificant.
True, it could be interpreted that way. My understanding with D (in general) is that the ordering of all declarations is supposed to be inconsequential. If this isn't the case and the code is in error by design then it should be clarified, especially since it is inconsistent with import declarations at module scope. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7330


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PST ---
Yeah. I don't think that this is a bug, but then again, I wouldn't have been
surprised if it didn't work to put imports at module scope after the line where
you use what you're importing. It would just be so bizarre to put the imports
anywhere but at the top that I've never thought about it.

But consider that the order of declarations of module variables doesn't
normally matter (it can with static if), but it matters a great deal at local
scope. So, for imports to work the same makes sense.

I'm not quite sure how the language spec would be updated though. I don't know
how you could have interpreted it to mean that you could put them after the
line where you used what you're importing within a function. I would have
thought that it was crystal clear as it is.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7330




Also see issue 7329.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7330


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec
                 CC|                            |bugzilla digitalmars.com



03:51:22 PST ---

 I'm not quite sure how the language spec would be updated though. I don't know
 how you could have interpreted it to mean that you could put them after the
 line where you used what you're importing within a function. I would have
 thought that it was crystal clear as it is.
Well, it can't be crystal clear because you were unaware that you could put imports at module scope after the use of the imported symbols :-) One way would be to add a statement to the effect of: "At module scope, import declarations may appear after the use of imported symbols. However, in local scopes, import declarations must appear before the use of any symbols introduced by the import." -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 24 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7330


dawg dawgfoto.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |dawg dawgfoto.de
         Resolution|                            |INVALID



This is according to specs.
https://github.com/D-Programming-Language/d-programming-language.org/blob/master/module.dd#L366

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 14 2012