Jump to page: 1 2
Thread overview
Re: How do I create a module-local immutable class object?
Sep 09, 2011
Andrej Mitrovic
Sep 09, 2011
Timon Gehr
Sep 09, 2011
Andrej Mitrovic
Sep 10, 2011
bearophile
Sep 10, 2011
bearophile
Sep 10, 2011
Jonathan M Davis
Sep 10, 2011
Andrej Mitrovic
Sep 10, 2011
Andrej Mitrovic
Sep 10, 2011
bearophile
Sep 10, 2011
Andrej Mitrovic
September 09, 2011
Ok it seems using const works, so I can use that instead. Still I'm wondering why I can't initialize foo inside a module ctor.
September 09, 2011
Wait a minute, I've just realized private on a class definition has no effect. Why is that?
September 09, 2011
On 09/09/2011 11:36 PM, Andrej Mitrovic wrote:
> Ok it seems using const works, so I can use that instead. Still I'm
> wondering why I can't initialize foo inside a module ctor.

It works for const because mutable is implicitly convertible to const, but not to immutable. You have to allocate an immutable class instance to make it work.

foo = new immutable(Foo);
September 10, 2011
Andrej Mitrovic Wrote:

> Wait a minute, I've just realized private on a class definition has no effect. Why is that?

Try to import that class from another module...

Bye,
bearophile
September 10, 2011
> Try to import that class from another module...

I fear this is a D design mistake/corner case. If you add tags to a class/struct definition it usually gets applied to all its methods, but here it works on the class/struct name itself.

Bye,
bearophile
September 10, 2011
On Saturday, September 10, 2011 05:20:51 bearophile wrote:
> > Try to import that class from another module...
> 
> I fear this is a D design mistake/corner case. If you add tags to a class/struct definition it usually gets applied to all its methods, but here it works on the class/struct name itself.

Personally, I think that marking a class with an attribute should only apply to the class and _nothing_ in it, but it doesn't always seem to work that way.

- Jonathan M Davis
September 10, 2011
On 9/10/11, bearophile <bearophileHUGS@lycos.com> wrote:
> Andrej Mitrovic Wrote:
>
>> Wait a minute, I've just realized private on a class definition has no effect. Why is that?
>
> Try to import that class from another module...

It doesn't stop imports, that's what I'm saying. I can import and instantiate the class from another module even though it's a private class definition.
September 10, 2011
On 9/10/11, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
> Personally, I think that marking a class with an attribute should only apply to the class and _nothing_ in it.

Agreed. But this doesn't seem to work currently unless I'm doing something wrong..
September 10, 2011
Andrej Mitrovic:

> It doesn't stop imports, that's what I'm saying. I can import and instantiate the class from another module even though it's a private class definition.

I didn't know it. If it's all like you say, then it's a bug.

Bye,
bearophile
September 10, 2011
foo\bar.d:
module foo.bar;
private class Foo {}

main.d:
import foo.bar : Foo;
void main()
{
	auto foo = new Foo();
}

This should be a compile error, no?
« First   ‹ Prev
1 2