265 – Selective import from renamed import behaves strangely

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 265 - Selective import from renamed import behaves strangely
Summary: Selective import from renamed import behaves strangely
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P3 minor
Assignee: Walter Bright
URL:
Keywords: spec
Depends on:
Blocks: 677
Show dependency tree / graph
Reported: 2006年07月22日 08:11 UTC by Matti Niemenmaa
Modified: 2014年02月15日 13:21 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Matti Niemenmaa 2006年07月22日 08:11:29 UTC
import io = std.stdio : foo = writefln;
void main() {
	//writefln("bar"); // doesn't work, good
	//std.stdio.foo("bar"); // doesn't work, good
	//std.stdio.writefln("bar"); // doesn't work, good
	foo("bar"); // works fine, but a renamed import should require a FQN according to the spec
	io.writefln("bar"); // works fine, but there shouldn't be a writefln in io, just a foo
	//io.foo("bar"); // doesn't work: undefined identifier module stdio.foo
}
--
The inline comments hopefully explain my view of the situation well enough. Essentially: the behaviour of the first three lines in main() is correct and that of the last three is incorrect. Only the last call, io.foo("bar"), should, in my opinion, compile.
Or then the specification needs correcting. Issue 264 and this are both about combining different import methods in ways that apparently haven't been considered, and probably need to be explicitly allowed and shown in examples or disallowed.
In addition, I feel that the last error message is somewhat strange: "module stdio.foo"? As I understand it there should be nothing but a module io, which contains only one function, foo.
Comment 1 Walter Bright 2006年07月26日 21:07:05 UTC
import io = std.stdio : foo = writefln;
void main() {
 //writefln("bar"); // doesn't work, good
 //std.stdio.foo("bar"); // doesn't work, good
 //std.stdio.writefln("bar"); // doesn't work, good
 foo("bar"); // works fine, but a renamed import should
 // require a FQN according to the spec
**> The "foo = writefln" binds writefln to the name foo in the current namespace, hence it does not require a FQN. Not a bug.
 io.writefln("bar"); // works fine, but there shouldn't be a
 // writefln in io, just a foo
**> Yes there is a writefln in io, because io=std.stdio bound the name io in the current namespace to refer to the entire module. Not a bug.
 //io.foo("bar"); // doesn't work: undefined identifier
 // module stdio.foo
**> That's because foo is put into the current namespace, not the module namespace. foo is not a member of io. Not a bug.
}
Comment 2 Matti Niemenmaa 2006年07月28日 08:38:11 UTC
(In reply to comment #1)
So essentially, the statement "import mymodule = module : myname = name;" is equivalent to the two statements "import mymodule = module; import module : myname = name;". Once again, this is worth noting in the documentation: the way I figured it, the two import methods would combine, as I indicated in the comments.
Reopening with the "spec" keyword and a lower severity.
Comment 3 Matti Niemenmaa 2006年12月24日 03:47:36 UTC
Fixed in DMD 0.178, but the code snippet under "Renamed and Selective Imports" in module.html is missing an ending brace, so this shouldn't be resolved yet.
Comment 4 Walter Bright 2006年12月27日 01:58:36 UTC
Fixed DMD 0.178


AltStyle によって変換されたページ (->オリジナル) /