Identifier resolution, the great implementation defined mess.

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 21 06:53:13 PDT 2014


On Sun, Sep 21, 2014 at 02:55:47PM +0200, Timon Gehr via Digitalmars-d wrote:
> On 09/21/2014 07:29 AM, deadalnix wrote:
> >
> >Free goodie: when you import, all symbol are resolved via the
> >expected import resolution mechanism. All ? No, the root package is
> >imported in the local scope.
> >
> >foo(int a) {
> >   import a.b.c;
> >   // a is now a package and not the parameter a anymore.
> >}
> 
> For local imports, DMD imports _all_ symbols into the local scope,
> shadowing anything that was there, which is plain broken (as SÓ§nke's
> example shows).  BTW: how do you suggest to treat the root package? I
> think importing into the local scope is fine, but the above example
> should emit an error because the parameter and the package conflict.
> 
> (The following code does not compile either:
> int std;
> import std.conv;)

I also think it's OK to import symbols into the local scope, but I don't
think conflicts should cause errors immediately, only when you actually
try to reference an ambiguous symbol. I.e., this should work:

	string foo(string text) {
		import std.conv; // includes std.conv.text
		return "";	// but `text` is never referenced
	}

but this should emit an error:

	string foo(string text) {
		import std.conv; // includes std.conv.text
		return text;	// error: parameter `text` conflicts with std.conv.text
	}


T

-- 
In order to understand recursion you must first understand recursion.


More information about the Digitalmars-d mailing list