[Issue 7335] New: sometimes the OUT - block have undefined class members-acces

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jan 21 09:21:38 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7335

           Summary: sometimes the OUT - block have undefined class
                    members-acces
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: devbai at mnet-mail.de


--- Comment #0 from Devbai <devbai at mnet-mail.de> 2012-01-21 09:21:35 PST ---
Hallo,

there are possible situations, that the OUT-Block of a methode
have not the 'exact' value of a member. With other words the members
seem to be undefiend.

The following programm show to situations. One them the OUT-block
have correct acces to the member - onother withot the correct
values.


here the programm:

**************
import std.stdio;

class BasisClass
{
  protected int mValue = 10;

  public void setValue( int newValue)
    in
    { writeln("checking IN BasisClass.setValue (do Nothing)");
    }       
    out
    { writeln("checking OUT BasisClass.setValue (value : " , mValue, ")");
      assert(mValue < 100 && mValue > -100); // <= assert will pass; because
the use newValue in the in-block
      writeln("  ... passed");
    } 
    body
    { mValue = newValue;
    }
}



class SubClassA : BasisClass 
{
  override
  public void setValue( int newValue)
   in
   { // will not checked because super.IN-check will pass  
     writeln("checking IN SubClassA.setValue (do Nothing)");
   }
   out
   { writeln("checking OUT SubClassA.setValue (value : " , mValue, ")");
   }
   body
   { mValue = newValue;
   }
}



class SubClassB : BasisClass 
{
  override
  public void setValue( int newValue)
    in
    { // will not checked because super.IN-check will pass  
      writeln("checking IN SubClassB.setValue (do Nothing)");
      int a = newValue;   //<<<<<<<<<<<<   The only diffrence to SubClassA
    }
    out
    { writeln("checking OUT SubClassB.setValue (mValue : " , mValue, ")"); 
    }
    body
    { mValue = newValue;
    }
}



public static void main ()
{
  writeln("***  START  ***");


  writeln("\nSubClass A:");
  BasisClass aObject = new SubClassA();
  aObject.setValue(3); 

  writeln("\nSubClass B:");
  BasisClass bObject = new SubClassB(); 
  bObject.setValue(3);    // <<<<<  will crash because undefinet mValue in the
                          // BasisClass.setValue().out-block.  

  writeln("\n***  END  ***");
}
**************

compilee with DMD64 D Compiler v2.057

will show this output:
**************
core.exception.AssertError at TestAppBugNoMembersInOutBlock(13): Assertion failure
----------------
./(_d_assertm+0x2a) [0x44830a]
./() [0x444e3a]
./(void TestAppBugNoMembersInOutBlock.BasisClass.setValue(int).void
__ensure()+0x4d) [0x444c0d]
./(void TestAppBugNoMembersInOutBlock.SubClassB.setValue(int)+0x48) [0x444d14]
./(_Dmain+0x7f) [0x444e07]
./(extern (C) int rt.dmain2.main(int, char**).void runMain()+0x17) [0x44893f]
./(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
delegate())+0x2a) [0x4484e6]
./(extern (C) int rt.dmain2.main(int, char**).void runAll()+0x42) [0x448992]
./(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
delegate())+0x2a) [0x4484e6]
./(main+0xd3) [0x448477]
/lib/libc.so.6(__libc_start_main+0xfe) [0x7f85995ecd8e]
----------------
***  START  ***

SubClass A:
checking IN BasisClass.setValue (do Nothing)
checking OUT BasisClass.setValue (value : 3)
  ... passed
checking OUT SubClassA.setValue (value : 3)

SubClass B:
checking IN BasisClass.setValue (do Nothing)
checking OUT BasisClass.setValue (value : 1074641200)

**************

as seen the ClassB-Out don't  have correct acces to the member

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list