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

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • OOP & Testbench Puzzles25
    • Handle and Copy Puzzles
    • Virtual Method Puzzles
    • Parameterized Class Puzzles
      • Global Static vs Per-Specialization Static
      • Same Specialization via typedef Alias
      • Integral Parameter Specializations Split Statics
      • Invariance of Parameterized Type Assignment
      • 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
  • Interview Prep: Puzzle Rounds5
  • DV Puzzle Cheatsheet
Loading lesson

‹Parameterized Class Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. OOP & Testbench Puzzles
  4. Parameterized Class Puzzles
  5. Invariance of Parameterized Type Assignment

VLSI DV Interview Puzzles · All levels

Invariance of Parameterized Type Assignment

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

On this page

    Puzzle

    Difficulty: Hard · 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`?

    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

    Parameterized classes are invariant in type parameters unless language/library defines covariance.

    Step-by-step solution

    Diagram
    1) `agent#(req_ext)` and `agent#(req_base)` are different unrelated specialization types.
    2) Subtyping of `req_ext` does not imply subtyping of enclosing parameterized class.
    3) Assignment is type-incompatible and should fail compile-time type checking.

    Answer

    Answer: Assignment fails because specialization types are invariant; `agent#(req_ext)` is not a subtype of `agent#(req_base)`.

    Why candidates get it wrong

    Candidates transfer container covariance expectations from other languages into SV/UVM.

    Interviewer follow-up

    What wrapper/interface pattern would you use if you need heterogeneous specialization storage?

    Related topics

    • Back to Parameterized Class Puzzles

    • OOP & Testbench Puzzles section

    Previous

    45 / 210

    Next: Static Function Counters Per Specialization

    Up next

    Up nextStatic Function Counters Per Specialization

    Sign in to save progress

    Practice this lessonReport an error

    See also

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