Thread overview
[Issue 7337] subclasses without invariants don't check basisclass invariant after method
Apr 13, 2014
Adrien Pensart
Jul 29, 2014
yebblies
Jul 29, 2014
Adrien Pensart
Jul 29, 2014
Adrien Pensart
Jul 30, 2014
yebblies
Jul 14, 2022
Dlang Bot
April 13, 2014
https://issues.dlang.org/show_bug.cgi?id=7337

Adrien Pensart <crunchengine@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |crunchengine@gmail.com

--- Comment #2 from Adrien Pensart <crunchengine@gmail.com> ---
(In reply to yebblies from comment #1)
> This is currently disabled in FuncDeclaration::addPostInvariant, and enabling it causes a lot of error bugs in druntime and phobos, presumably due to issue 5039.  Once that bug is closed this will hopefully be a quick fix.

I just tried to re-enable it, everything seems ok after the issue 5039 resolution, no error in druntime or phobos appeared in a simple build.

Can I create a mini pull request ?

--
July 29, 2014
https://issues.dlang.org/show_bug.cgi?id=7337

--- Comment #3 from yebblies <yebblies@gmail.com> ---
(In reply to Adrien Pensart from comment #2)
> (In reply to yebblies from comment #1)
> > This is currently disabled in FuncDeclaration::addPostInvariant, and enabling it causes a lot of error bugs in druntime and phobos, presumably due to issue 5039.  Once that bug is closed this will hopefully be a quick fix.
> 
> I just tried to re-enable it, everything seems ok after the issue 5039 resolution, no error in druntime or phobos appeared in a simple build.
> 
> Can I create a mini pull request ?

Yes, please do.

--
July 29, 2014
https://issues.dlang.org/show_bug.cgi?id=7337

--- Comment #4 from Adrien Pensart <crunchengine@gmail.com> ---
I retried to fix this some month ago in days, but i'm not comfortable at all with dmd internals and i didn't succeed...

it could take weeks for me to resolve this...

i started writing a testcase into runnable/testinvariant.d :

/***************************************************/
// 7337
void test7337()
{
    class A
    {
        static uint invariantStatus;

        public void foo()
        in
        {
            assert(invariantStatus == 0);
        }
        out
        {
            assert(invariantStatus == 2);
        }
        body
        {
            printf("in A.foo : %d\n", invariantStatus);
            assert(invariantStatus == 1);
        }

        invariant()
        {
            printf("in A invariant\n");
            invariantStatus++;
        }
    }

    class B : A
    {
        override public void foo()
        {
            printf("in B.foo : %d\n", invariantStatus);
        }
    }

    A a = new A();
    a.foo();
    A.invariantStatus = 0;

    B b = new B();
    b.foo();
}

--
July 29, 2014
https://issues.dlang.org/show_bug.cgi?id=7337

--- Comment #5 from Adrien Pensart <crunchengine@gmail.com> ---
diff --git a/src/func.c b/src/func.c
index 93ca8fd..395cb51 100644
--- a/src/func.c
+++ b/src/func.c
@@ -3933,7 +3933,7 @@ bool FuncDeclaration::addPostInvariant()
     AggregateDeclaration *ad = isThis();
     ClassDeclaration *cd = ad ? ad->isClassDeclaration() : NULL;
     return (ad && !(cd && cd->isCPPclass()) &&
-            ad->inv &&
+            //ad->inv &&
             global.params.useInvariants &&
             (protection == PROTprotected || protection == PROTpublic ||
protection == PROTexport) &&
             !naked &&

There is multiple problems, i'll try to give you what i tested but phobos is ok.

A trivial error in druntime, it does not compile the first time, but it works if we replay the exact command, i don't know why (MODEL=64 make -j4 -f posix.mak install) :

src/core/sync/semaphore.d(182): Error: function
core.sync.semaphore.Semaphore.wait no return exp; or assert(0); at end of
function
src/core/sync/semaphore.d(298): Error: function
core.sync.semaphore.Semaphore.tryWait no return exp; or assert(0); at end of
function

some test failed in dmd suite :

* compilable/interpret3.d :

../src/dmd -m64 -Icompilable   -odtest_results/compilable
-oftest_results/compilable/interpret3_0.o -c compilable/interpret3.d
compilable/interpret3.d(143): Error: assert(w.r.x == 4) failed
compilable/interpret3.d(181):        called from here: retRefTest2()
compilable/interpret3.d(181):        while evaluating: static
assert(retRefTest2() == 2)
dmd: interpret.c:180: void CtfeStack::setValue(VarDeclaration*, Expression*):
Assertion `v->ctfeAdrOnStack >= 0 && v->ctfeAdrOnStack < stackPointer()'
failed.
Aborted

==============================
Test failed: expected rc == 0, exited with rc == 134

Makefile:163: recipe for target 'test_results/compilable/interpret3.d.out' failed

* runnable/sdtor.d :

Test failed.  The logged output:
../src/dmd -m64 -Irunnable   -odtest_results/runnable
-oftest_results/runnable/sdtor_0 runnable/sdtor.d
S7353
test_results/runnable/sdtor_0
core.exception.AssertError@runnable/sdtor.d(859): Assertion failure
----------------
test_results/runnable/sdtor_0() [0x445679]
test_results/runnable/sdtor_0(void sdtor.test33()+0x8e) [0x437c36]
test_results/runnable/sdtor_0(_Dmain+0xa9) [0x443841]
test_results/runnable/sdtor_0(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv+0x1f)
[0x44963b]
test_results/runnable/sdtor_0(void rt.dmain2._d_run_main(int, char**, extern
(C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x44958e]
test_results/runnable/sdtor_0(void rt.dmain2._d_run_main(int, char**, extern
(C) int function(char[][])*).runAll()+0x30) [0x4495f4]
test_results/runnable/sdtor_0(void rt.dmain2._d_run_main(int, char**, extern
(C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x44958e]
test_results/runnable/sdtor_0(_d_run_main+0x193) [0x44950f]
test_results/runnable/sdtor_0(main+0x17) [0x4456c7]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f475382fb45]

[...output...]

==============================
Test failed: expected rc == 0, exited with rc == 1

--
July 30, 2014
https://issues.dlang.org/show_bug.cgi?id=7337

--- Comment #6 from yebblies <yebblies@gmail.com> ---
I guess it wasn't so quick after all.

--
July 14, 2022
https://issues.dlang.org/show_bug.cgi?id=7337

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
@RazvanN7 created dlang/dmd pull request #14304 "Fix Issue 7337 - subclasses without invariants don't check baseclass …" fixing this issue:

- Fix Issue 7337 - subclasses without invariants don't check baseclass invariant after method

https://github.com/dlang/dmd/pull/14304

--