View mode: basic / threaded / horizontal-split · Log in · Help
July 23, 2011
How do I call super or object.opAssign for classes?
class Foo
{
   void opAssign(int bar)
   {
   }
}

void main()
{
   auto foo = new Foo;
   foo = null;
}

test.d(17): Error: function test.Foo.opAssign (int bar) is not
callable using argument types (void*)
test.d(17): Error: cannot implicitly convert expression (null) of type
void* to int

I just wanted to implement one opAssign method for assigning a
specific type, but now I've ran into the issue that assigning class
objects to null doesn't work anymore.. :/
July 25, 2011
Re: How do I call super or object.opAssign for classes?
On Sat, 23 Jul 2011 12:23:07 -0400, Andrej Mitrovic  
<andrej.mitrovich@gmail.com> wrote:

> class Foo
> {
>     void opAssign(int bar)
>     {
>     }
> }
>
> void main()
> {
>     auto foo = new Foo;
>     foo = null;
> }
>
> test.d(17): Error: function test.Foo.opAssign (int bar) is not
> callable using argument types (void*)
> test.d(17): Error: cannot implicitly convert expression (null) of type
> void* to int
>
> I just wanted to implement one opAssign method for assigning a
> specific type, but now I've ran into the issue that assigning class
> objects to null doesn't work anymore.. :/

That's a bug, please file.

-Steve
July 25, 2011
Re: How do I call super or object.opAssign for classes?
http://d.puremagic.com/issues/show_bug.cgi?id=6378

On 7/25/11, Steven Schveighoffer <schveiguy@yahoo.com> wrote:
> On Sat, 23 Jul 2011 12:23:07 -0400, Andrej Mitrovic
> <andrej.mitrovich@gmail.com> wrote:
>
>> class Foo
>> {
>>     void opAssign(int bar)
>>     {
>>     }
>> }
>>
>> void main()
>> {
>>     auto foo = new Foo;
>>     foo = null;
>> }
>>
>> test.d(17): Error: function test.Foo.opAssign (int bar) is not
>> callable using argument types (void*)
>> test.d(17): Error: cannot implicitly convert expression (null) of type
>> void* to int
>>
>> I just wanted to implement one opAssign method for assigning a
>> specific type, but now I've ran into the issue that assigning class
>> objects to null doesn't work anymore.. :/
>
> That's a bug, please file.
>
> -Steve
>
July 26, 2011
Re: How do I call super or object.opAssign for classes?
Hi,
isn't that the way it's supposed to work? I mean

void show(int a) { writeln(a); }

void main() { show(null); }

won't compile either.
Shouldn't bar be some kind of pointer?

btw, today I read "opAssign can no longer be overloaded for class objects"
here:

http://www.d-programming-language.org/features2.html

is that no longer valid?
July 26, 2011
Re: How do I call super or object.opAssign for classes?
On Tue, 26 Jul 2011 07:54:54 -0400, Diego Canuhé <canuhedc@gmail.com>  
wrote:

> Hi,
> isn't that the way it's supposed to work? I mean
>
> void show(int a) { writeln(a); }
>
> void main() { show(null); }
>
> won't compile either.
> Shouldn't bar be some kind of pointer?

null should be considered as the type of the class, not void *.  You  
should not be able to override the behavior of opAssign as it pertains to  
assigning to a class instance.  In other words, you should *never* be able  
to override x = null where x is a class instance.

>
> btw, today I read "opAssign can no longer be overloaded for class  
> objects"
> here:
>
> http://www.d-programming-language.org/features2.html
>
> is that no longer valid?

Here is the spec.  I would not trust that features2, it's probably out of  
date.

http://www.d-programming-language.org/operatoroverloading.html#Assignment

-Steve
Top | Discussion index | About this forum | D home