SystemVerilog OOP Mastery · All levels
Virtual vs Nonvirtual Traps: Concept Explained
Concept Explained for Virtual vs Nonvirtual Traps.
Concept
In short: Forgetting virtual in base classes silently disables dynamic dispatch through base handles, so framework code executes base behavior instead of protocol-specific overrides.
This bug is painful because unit tests on concrete classes pass. Failure appears only when the framework stores everything as base handles and calls hook methods that were intended to be polymorphic.\n\nThe fix is contractual: mark extension points virtual in the base class, keep signatures identical, and use override checks where possible. Treat nonvirtual methods as intentionally final utility methods, not callbacks.