Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
    • Handle and Copy Puzzles
    • Virtual Method Puzzles
    • Parameterized Class Puzzles
      • Global Static vs Per-Specialization Static
      • Same Specialization via typedef Alias
      • $cast Between Specializations via a Common Base
      • Unrelated Specializations Cannot Be Assigned
      • Static Function Counters Per Specialization
      • Wrong UVM Macro for Parameterized Object
    • Factory Override Puzzles
    • OOP & Testbench Puzzles: Tricky Q&A
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Parameterized Class Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. OOP & Testbench Puzzles
  4. Parameterized Class Puzzles
  5. Unrelated Specializations Cannot Be Assigned
On this page

    VLSI DV Interview PuzzlesAll levels

    Unrelated Specializations Cannot Be Assigned

    Why does assigning `agent#(req_ext)` to `agent#(req_base)` fail even though `req_ext extends req_base`? Name the fix.

    Puzzle

    Difficulty: Medium · Puzzle 4 of 6 · Topic: Parameterized Class Puzzles

    Why does assigning `agent#(req_ext)` to `agent#(req_base)` fail even though `req_ext extends req_base`? Name the fix.

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    class req_base; endclass
    class req_ext extends req_base; endclass
    
    class agent #(type REQ_T = req_base);
      REQ_T last_req;
    endclass
    
    initial begin
      agent#(req_ext)  a_ext = new();
      agent#(req_base) a_base;
      a_base = a_ext;
    end

    Hint

    Each specialization is its own class. Inheritance between the parameter values says nothing about the specializations.

    Step-by-step solution

    Diagram
    1) `agent#(req_ext)` and `agent#(req_base)` are two distinct, unrelated classes; neither extends the other.
    2) Subtyping of `req_ext` does not imply subtyping of the enclosing parameterized class (SystemVerilog has no covariance of type parameters).
    3) The assignment is type-incompatible and fails at compile time; even `$cast` between them fails because they are unrelated.
    4) Fix: give `agent` a non-parameterized base (`class agent_base; endclass`, `agent#(T) extends agent_base`) and store `agent_base` handles, or use the same specialization.

    Answer

    Answer: Assignment fails at compile time because `agent#(req_ext)` and `agent#(req_base)` are unrelated classes; the parameter relationship does not carry over. Use a common non-parameterized base class.

    How this was checked

    Not run here: The expected result is a compile-time error, and the harness treats a failed compile as a failed run. Checked by hand: Verilator 5.048 rejects the assignment (an agent#(req_base) handle expects a CLASSREFDTYPE, got a different specialization).. The answer follows the language rules and the solution steps above.

    Why candidates get it wrong

    Candidates transfer container covariance expectations from Java or C++ templates into SV/UVM. `$cast` cannot rescue it either, since neither class derives from the other.

    Interviewer follow-up

    What wrapper/interface pattern would you use if you need heterogeneous specialization storage? Model answer: a non-parameterized abstract base class (or interface class) exposing the operations as virtual methods; keep `agent_base` handles in the collection and `$cast` down to a specific `agent#(T)` only where the type is known.

    Say it out loud

    The assignment fails at compile time. The two agent specializations are distinct, unrelated classes, and SystemVerilog has no covariance across type parameters, so extending the parameter does not make the agent a subtype. The trap is assuming the parameter relationship carries over. I would give agent a non-parameterized base and store handles of that base type.

    Related topics

    • Parameterized Classes

    • Casting with $cast

    • Back to Parameterized Class Puzzles

    • OOP & Testbench Puzzles section

    Previous

    51 / 293

    Next: Static Function Counters Per Specialization

    Up next

    Up nextStatic Function Counters Per Specialization

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Global Static vs Per-Specialization Static
    • Same Specialization via typedef Alias
    • Wrong UVM Macro for Parameterized Object