Cast parameterizable class whose parameter is extended from the other

Hi all,

I am trying to make a kind of reusable UVM scoreboard but I have an issue to connect my analysis ports from my monitor to my scoreboard. This connection attempt is made in my environment. Here below you may find a sample of my code. Please anyone could help me, I cannot find any answer anywhere.

The errors I am getting:
UVM_ERROR …/env/my_env.svh(61) @ 0: uvm_test_top.env [connect_phase] Scoreboard analysis port IN cast failed
UVM_ERROR @ 0: uvm_test_top.env.agt.mon.mon_ap [Connection Error] Cannot connect to null port handle

Thanks in advance,
Martin

Scoreboard


class my_scoreboard #(type seq_item = uvm_sequence_item) extends uvm_scoreboard;
  ...
  uvm_analysis_export #(seq_item) axp_in;
  ...

Monitor


class my_monitor extends uvm_monitor;
  uvm_analysis_port #(my_transaction) mon_ap;
  ...

Env


class my_env extends uvm_env;
  ...
  my_scoreboard sb;
  ...
  uvm_analysis_export #(my_transaction) sb_ap;
  ...
  function void build_phase(uvm_phase phase);
    sb = my_scoreboard #(my_transaction)::type_id::create("sb", this);
  endfunction: build_phase
  ...
  function void connect_phase(uvm_phase phase);
    uvm_analysis_export #(my_transaction) sb_ap_in;
    if (!$cast(sb_ap_in, sb.axp_in)) begin
      `uvm_error("connect_phase", "Scoreboard analysis port IN cast failed")
    end
    agt.mon.mon_ap.connect(sb_ap_in);
  ...

In reply to Martin Velay:
sb should be declared as

my_scoreboard #(my_transaction) sb;

Also, it is a good idea not to provide a default type so your original code would have been a compiler error.

class my_scoreboard #(type seq_item) extends uvm_scoreboard;