Hi,

I have a class representing a symmetric matrix declared as 

class SymmMatrix
 {
        var size : int;
        var datadom : domain(1);

        var data : [datadom] real(64);
 }

I have an operator overloading for the whole array assignment

proc =(ref left : SymmMatrix, right : real(64))
{
        if left.size == 0 then return;
        left.data = right;
}

And the following code is compiling and running as expected:

var test = new SymmMatrix();
test.setSize(5);
test = 1.0; 

But, when I use this SymmMatrix class as the superclass of a FockMatrix class

class FockMatrix : SymmMatrix
{
      //…
} 

And try to do a whole array assignment then it produces the following warnings 
and running the program will results in a segmentation fault:

In file included from <internal>:49:
DIISEngine.chpl:151:22: warning: incompatible pointer types passing 
'FockMatrix_chpl' (aka 'struct chpl_FockMatrix_chpl_s *') to parameter of type 
'_ref_SymmMatrix'
      (aka 'struct chpl_SymmMatrix_chpl_s **') [-Wincompatible-pointer-types]
    chpl___ASSIGN_15(coerce_tmp_chpl69, 0.0);
                     ^~~~~~~~~~~~~~~~~
/var/folders/lj/gk8vvtcj57x6dx5_m424x91c0000gn/T//chpl-olouant-6778.deleteme/chpl__header.h:2960:46:
 note: passing argument to parameter 'left_chpl' here
static void chpl___ASSIGN_15(_ref_SymmMatrix left_chpl, _real64 right_chpl);

The origin of the problem seems to be that the compiler expect a SymmMatrix not 
a FockMatrix (even if SymmMatrix is the superclass). But then I don’t 
understand why I have a double pointer structure (struct chpl_SymmMatrix_chpl_s 
**) vs a single pointer structure (struct chpl_FockMatrix_chpl_s *).

By removing the ref intent in the operator overloading the problem is solved 
(run as expected) except for a warning at compile time "The left operand of '=' 
and '<op>=' should have 'ref' intent.”:

proc =(left : SymmMatrix, right : real(64))
{
        if left.size == 0 then return;
        left.data = right;
}

I am assuming that the overloaded operators of the superclass are valid for the 
child classes. 
Am I right? 
Do I miss something? 
Do I have to overload operator for the child classes?

Thanks for your help.

Orian
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to