Calling subroutines on match of a sequence

In reply to Have_A_Doubt:

In reply to ben@SystemVerilog.us:
Hi Ben,
I was trying a variation of the code


initial forever #10 clk = ~clk;
bit [3:0] a ;
always@( posedge clk) a <= a + 1;
property p1;
@(posedge clk) (1,$display("a is %d",a));
endproperty
assert property( p1 ) $display("pass");

Considering that $display() executes in reactive region, why do we observe “a is 0” instead of “a is 1” ?( at 1st posedge of clk )
By reactive region wouldn’t the NBA update ( to 1 ) would have been done ?

[Ben] “a is 0” because “a” is within the property in the sequence_match_item (1,$display(“a is %d”,a)); Therefore, “a” is its sampled value.

If I were to re-write to


function void disp();
$display("a is %d",a);
endfunction
property p2;
@(posedge clk) (1,disp() );
endproperty
assert property( p2 ) $display("pass");

Now I do observe “a is 1” i.e NBA updated value is observed

[Ben] @(posedge clk) (1,disp() ); does not reference the “a”, thus, the function that executes in the Observed or maybe Reactive region (tool dependent per my observation) sees the updated value of “a”; updated as you know in the NBA region.