Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous import form introduces names into the global namespace #17813

Open
dlangBugzillaToGithub opened this issue Aug 16, 2017 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

dlang reported this on 2017-08-16T11:31:38Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=17756

Description

I was testing an import as written at [1], which is not a documented form[2], and discovered that such imports introduce names into the global namespace:

```
void main() {
    //import io = std.stdio; // Error.
    import io = std.stdio : writeln; // Executes.
    writeln("test");
}
```

It appears that `import io = std.stdio : writeln;` is being interpreted as `import io = std.stdio : writeln=writeln;`. If this is the case, should an implicit `name=name` be allowed?


```
void main() {
    import io = std.stdio : writeln; // This builds and runs.

    writeln("test"); // Executes.
    //write("test"); // Error.
    io.writeln("test"); // Executes.
    io.write("test"); // Executes.
}
```

[1]: http://forum.dlang.org/post/hzfvmkrkguqbltmocfeo@forum.dlang.org
[2]: Sections 4.6 - 4.8: https://dlang.org/spec/module.html#renamed_imports
@dlangBugzillaToGithub
Copy link
Author

dlang (@Vild) commented on 2017-08-16T11:35:19Z

"Ambiguous" may be the wrong term; the compiler knows exactly what it's doing. It may be ambiguous to the programmer reading and writing it. In that same forum thread, we read that one person (two including myself) expected this to work differently[1] (e.g., did not expect symbols to be introduced into the global namespace).

[1]: http://forum.dlang.org/post/opmhuacamwsqgorpgxrf@forum.dlang.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant