Ticket #243 (assigned defect)
Invariants called too many times and in wrong order
Reported by: | nevdelap | Owned by: | Chuck |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | Cobra Compiler | Version: | 0.8.0 |
Keywords: | Cc: |
Description
class A cue init base.init print 'inside init of A' def m1 as bool print 'inside invariant of A' return true invariant .m1 class B inherits A cue init base.init print 'inside init of B' def m2 as bool print 'inside invariant of B' return true invariant .m2 class P def main is shared B()
Actual result
inside init of A (1) inside invariant of A (2) inside init of B inside invariant of A inside invariant of A (3) inside invariant of B
(1) At the end of the base class constructor the object is not yet constructed and it's invariant need not hold and shouldn't be called.
(2) Additionally if the invariant is called at that point and includes calls to any methods overridden in the derived class they can fail because it hasn't constructed yet and its state is not ready to be used.
(3) Extra test of A's invariant just not needed. I guess it's because I've used calls to methods to show when it's in the invariants, but again, the object is not finished constructing so it need not call the invariant on the exit of that method. (It's finished constructing after the invariant check at the end of the most derived init, not before, so at any time before that, method calls, or whatever used in the init, the invariant shouldn't be called yet.)
Expected result
inside init of A inside init of B inside invariant of A inside invariant of B
BTW: you can hit me up in chat to discuss, instead of us bouncing replies back and forth here. More productive, yeah? Cheers.
nevdelap(at)gmail(dot)com for *both* gmail chat & MSN, or nevdelap in yahoo.