Can I constrain a sum/function of array element sizes?

Hi I am trying to constraint a sum of array without using a.sum() method. But code is not working.

Do you have any suggestion?

class c;
  rand logic [7:0] a [];
  constraint array_size {a.size() == 10;  }
    constraint array_items { 
      foreach(a[i]) a[i] < 10;
        
    }
 
  constraint sum_array_c {a_sum() == 10; }
  
    function int a_sum();
      a_sum = 0;
      foreach(a[i]) 
        a_sum += a[i] ;
 
    endfunction 
  
 
endclass
 
module test;
   initial begin
      c c1 = new();
 
      void'(c1.randomize());
 
     foreach(c1.a[i])
        $display("%0d ", c1.a[i]);
 
   end // initial begin
endmodule // test

I see below error

# testbench.sv(25): randomize() failed due to conflicts between the following constraints:
# 	testbench.sv(9): sum_array_c { (this.a_sum() == 10); }
# Where:
# 	this.a_sum() = 0