Functional coverage: Can we sample struct type variable used in design in the functional coverage model?

Hello,

In the design a type defined struct is created and used.
Can I sample the fields of this struct variable in my functional coverage model?

For Example:

Design =>
typedef struct packed {
logic [31:0] addr;
logic [3:0] amid;
:
:
} pkt_t;

pkt_t pkt;


In my functional coverage model, I would like to sample the following in my coverpoint =>

cp_abc: coverpoint pkt.addr {
}

I am declaring this in my func coverage module list =>

module dut_cov (
:
:
pkt_t pkt,
:
:
)

Is this allowed? Am I doing it the right way?
At present I get an error when I try the above.

Regards, Ali

You should be able to do this, but you are not showing enough code to analyze what might be wrong. It would also help to show us the actual error you are getting. This example worked for me:

module top;
   typedef struct {bit A,B;} AB_t;
   AB_t AB;
   covergroup cg;
      a: coverpoint AB.A;
   endgroup // cg

   initial begin
      cg c;
      c = new;
      c.sample;
   end
endmodule