Class handle copy

class opconst;
rand int ii;
/*
rand int oper[$];

constraint cc { oper.size() inside {10,12} ;
		foreach (oper[j]) oper[j] dist {[1:2] :/ 1, [3:4] :/ 8};} // {"add", "sub", "mul", "nop"};}
*/
endclass

class opconstcpy extends opconst;
rand int a;
endclass

module tb_top();

initial begin
	opconst opconsti;
	opconstcpy opconstcpyi;
	//*E: assignment operator type check failed (expecting datatype compatible with 'class $unit::opconstcpy' but found 'class $unit::opconst' instead). below 2 lines
	//opconsti = new();
	//opconstcpyi = opconsti;  //Compile error

	//No compile error ; Results in runtime error. NULL pointer dereference. below 2 lines
	//opconsti = new();
	//opconsti = opconstcpyi;

	//Same error as line #20- type check failed. below 2 lines
	//opconstcpyi = new();
	//opconstcpyi = opconsti;  //Compile error
	
	//NO error in handle copy ; both prints @1_1. below 2 lines
	//opconstcpyi = new();
	//opconsti = opconstcpyi; 

	$display(opconsti);
	$display(opconstcpyi);

	/*
	for(int i=0; i<5; i++) begin
		opconsti.randomize();
	end
	//$display(opconstcpyi.a);
	//$display("opconsti.oper = %p", opconsti.oper);
	//$display("opconstcpyi.oper = %p", opconstcpyi.oper);
	*/
end

endmodule

Question:

  1. What happens when the a child class handle is copied to base class or vice versa?
  2. In the above code: constructing the child class and then copying child class onto parent class is the only way of allocating/sharing memory between the two classes. Constructing the base class and assigning child class to base class should have a similar effect in terms of sharing memory. If the assignment merely is to share the memory location between parent and child class, why should this method not work?
  3. Also, copying base class onto child class results in type check error. What does it mean by type check mismatch? - Given both are defined as class and class is a datatype.

In reply to natasv:

https://verificationacademy.com/forums/systemverilog/why-downcasting-not-allowed-systemverilog#reply-58636