Jump to page: 1 2
Thread overview
Is anything private by default when declared in a module?
Dec 02, 2013
Gary Willoughby
Dec 02, 2013
Adam D. Ruppe
Dec 02, 2013
Namespace
Dec 02, 2013
H. S. Teoh
Dec 02, 2013
Gary Willoughby
Dec 02, 2013
Namespace
Dec 02, 2013
Namespace
Dec 02, 2013
lomereiter
Dec 03, 2013
eles
Dec 03, 2013
Jonathan M Davis
Dec 03, 2013
Adam D. Ruppe
Dec 03, 2013
H. S. Teoh
December 02, 2013
Is anything private by default when declared in a module?

I'm declaring functions, classes, structs, enums, aliases, etc.. I'm assuming all these are public by default when declared in a module to allow them to be imported into another. Is there anything private by default when declared in a module?
December 02, 2013
On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby wrote:
> Is anything private by default when declared in a module?

I believe imports only. "import foo;" is private, so you write "public import foo;" to expose outside. But other than that, I'm pretty sure everything is public unless you say otherwise.
December 02, 2013
On Monday, 2 December 2013 at 20:46:58 UTC, Adam D. Ruppe wrote:
> On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby wrote:
>> Is anything private by default when declared in a module?
>
> I believe imports only. "import foo;" is private, so you write "public import foo;" to expose outside. But other than that, I'm pretty sure everything is public unless you say otherwise.

But sadly named imports aren't private...

/// module foo
private import std.stdio: writeln;

writeln can be used in any module which imports foo. :/
December 02, 2013
On Mon, Dec 02, 2013 at 09:53:09PM +0100, Namespace wrote:
> On Monday, 2 December 2013 at 20:46:58 UTC, Adam D. Ruppe wrote:
> >On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby wrote:
> >>Is anything private by default when declared in a module?
> >
> >I believe imports only. "import foo;" is private, so you write "public import foo;" to expose outside. But other than that, I'm pretty sure everything is public unless you say otherwise.
> 
> But sadly named imports aren't private...
> 
> /// module foo
> private import std.stdio: writeln;
> 
> writeln can be used in any module which imports foo. :/

WAT?

That's messed up. Is there a bug for that?


T

-- 
Why waste time learning, when ignorance is instantaneous? -- Hobbes, from Calvin & Hobbes
December 02, 2013
On Monday, 2 December 2013 at 21:10:44 UTC, H. S. Teoh wrote:
> On Mon, Dec 02, 2013 at 09:53:09PM +0100, Namespace wrote:
>> On Monday, 2 December 2013 at 20:46:58 UTC, Adam D. Ruppe wrote:
>> >On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby wrote:
>> >>Is anything private by default when declared in a module?
>> >
>> >I believe imports only. "import foo;" is private, so you write
>> >"public import foo;" to expose outside. But other than that, I'm
>> >pretty sure everything is public unless you say otherwise.
>> 
>> But sadly named imports aren't private...
>> 
>> /// module foo
>> private import std.stdio: writeln;
>> 
>> writeln can be used in any module which imports foo. :/
>
> WAT?
>
> That's messed up. Is there a bug for that?
>
>
> T

WAT?++
December 02, 2013
On Monday, 2 December 2013 at 20:53:10 UTC, Namespace wrote:
>
> But sadly named imports aren't private...
>

OMG now I get it why in 2.064 importing std.regex makes visible std.uni.isWhite all of a sudden.

December 02, 2013
On Monday, 2 December 2013 at 21:10:44 UTC, H. S. Teoh wrote:
> On Mon, Dec 02, 2013 at 09:53:09PM +0100, Namespace wrote:
>> On Monday, 2 December 2013 at 20:46:58 UTC, Adam D. Ruppe wrote:
>> >On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby wrote:
>> >>Is anything private by default when declared in a module?
>> >
>> >I believe imports only. "import foo;" is private, so you write
>> >"public import foo;" to expose outside. But other than that, I'm
>> >pretty sure everything is public unless you say otherwise.
>> 
>> But sadly named imports aren't private...
>> 
>> /// module foo
>> private import std.stdio: writeln;
>> 
>> writeln can be used in any module which imports foo. :/
>
> WAT?
>
> That's messed up. Is there a bug for that?
>
>
> T
I mean yes, but I find nothing.

Short example:

io.d
----
private import std.stdio : writeln;
----

io_use.d
----
import io;

void main() {
	writeln("Hello");
}
----
December 02, 2013
On Monday, 2 December 2013 at 21:30:08 UTC, Namespace wrote:
> On Monday, 2 December 2013 at 21:10:44 UTC, H. S. Teoh wrote:
>> On Mon, Dec 02, 2013 at 09:53:09PM +0100, Namespace wrote:
>>> On Monday, 2 December 2013 at 20:46:58 UTC, Adam D. Ruppe wrote:
>>> >On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby wrote:
>>> >>Is anything private by default when declared in a module?
>>> >
>>> >I believe imports only. "import foo;" is private, so you write
>>> >"public import foo;" to expose outside. But other than that, I'm
>>> >pretty sure everything is public unless you say otherwise.
>>> 
>>> But sadly named imports aren't private...
>>> 
>>> /// module foo
>>> private import std.stdio: writeln;
>>> 
>>> writeln can be used in any module which imports foo. :/
>>
>> WAT?
>>
>> That's messed up. Is there a bug for that?
>>
>>
>> T
> I mean yes, but I find nothing.
>
> Short example:
>
> io.d
> ----
> private import std.stdio : writeln;
> ----
>
> io_use.d
> ----
> import io;
>
> void main() {
> 	writeln("Hello");
> }
> ----

I have found it
https://github.com/D-Programming-Language/dmd/pull/2256
December 03, 2013
On Monday, December 02, 2013 13:09:06 H. S. Teoh wrote:
> On Mon, Dec 02, 2013 at 09:53:09PM +0100, Namespace wrote:
> > On Monday, 2 December 2013 at 20:46:58 UTC, Adam D. Ruppe wrote:
> > >On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby wrote:
> > >>Is anything private by default when declared in a module?
> > >
> > >I believe imports only. "import foo;" is private, so you write "public import foo;" to expose outside. But other than that, I'm pretty sure everything is public unless you say otherwise.
> > 
> > But sadly named imports aren't private...
> > 
> > /// module foo
> > private import std.stdio: writeln;
> > 
> > writeln can be used in any module which imports foo. :/
> 
> WAT?
> 
> That's messed up. Is there a bug for that?

Yes. It's a longstanding bug with regards to selective imports. They create a conflicting symbol in the importing module's scope. That's why you should never use them at this point.

https://d.puremagic.com/issues/show_bug.cgi?id=314

- Jonathan M Davis
December 03, 2013
On Tuesday, 3 December 2013 at 07:34:37 UTC, Jonathan M Davis wrote:
> They create a conflicting symbol in the importing module's scope.
> That's why you should never use them at this point.

Well, that's sometimes useful, it helps get rid of conflict errors quickly, easily, and explicitly.

It should just be a private name in the new scope unless the import was public.

BTW private names should be outright invisible outside the module. At least private things at module scope. I get really annoyed with "public symbol foo from module bar conflicts with private symbol foo from module baz". Gee, I wonder which one I wanted to use???

But that's a separate issue.

> https://d.puremagic.com/issues/show_bug.cgi?id=314

wait, I thought Kenji fixed that? The comments don't say why it was reopened... did it just break too much Phobos code or was the fix wrong in some other way?
« First   ‹ Prev
1 2