D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7336 - Sometimes OUT-Block dont have correct acces to method-parameter
Summary: Sometimes OUT-Block dont have correct acces to method-parameter
Status: RESOLVED DUPLICATE of issue 7335
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 critical
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-21 10:02 UTC by devbai
Modified: 2012-01-24 21:46 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description devbai 2012-01-21 10:02:07 UTC
Hello,

It's possible, that a method-OUT-block dont, have access
tho the correct value of its method-parameter

this Programm:

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

class ClassA 
{
  private int mValue=0;
    
  @property
  {  
    public int value() const 
    { return mValue;
    }
      
    public void value(int newValue)
    in
    { int dummy = newValue; // senseless use from newValue
    }
    out 
    { int a = newValue;
      writeln("checking OUT ClassA.@property value (mValue == newValue: ",
              mValue,  " == " , newValue, ")");
      assert(mValue==newValue); // <= assert will pass; 
                                // because the use newValue in the in-block
      writeln("  ... passed");
    } 
    body
    { mValue = newValue;
    }
  }
}

class ClassB
{
  private int mValue=0;
  
  @property
  {  
    public int value() const 
    { return mValue;
    }
      
    public void value(int newValue)
    out
    { int a = newValue;
      writeln("checking OUT ClassB.@property value (mValue == newValue: ",
               mValue,  " == " , newValue, ")");
      assert(mValue==newValue); // <= assert will (mostly) not pass;
                                // because newValue has here an undedined
                                // value but shoud be defined! 
      writeln("  ... passed");
    } 
    body
    { mValue = newValue;
    }
  }
}

   
   
   
public static void main ()
{
  writeln("***  START  ***");
  
  writeln("\nClassA:");
  ClassA aObject = new ClassA();
  aObject.value = 12;
  
  writeln("\nClassB:");
  ClassB bObject = new ClassB();
  bObject.value = 12;
  
  writeln("\n***  END  ***");
}
**************

compiled with DMD64 D Compiler v2.057

wil after running show following output:
**************
core.exception.AssertError@TestAppBugNoParamaterInOutBlock(46): Assertion failure
----------------
./(_d_assertm+0x2a) [0x44830a]
./() [0x4450c2]
./(@property void TestAppBugNoParamaterInOutBlock.ClassB.value(int).void __ensure()+0x58) [0x444fc0]
./(@property void TestAppBugNoParamaterInOutBlock.ClassB.value(int)+0x26) [0x444f66]
./(_Dmain+0x7f) [0x445057]
./(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) [0x7f72f9f71d8e]
----------------
***  START  ***

ClassA:
checking OUT ClassA.@property value (mValue == newValue: 12 == 12)
  ... passed

ClassB:
checking OUT ClassB.@property value (mValue == newValue: 12 == -772278112)
**************

the access in the IN-Block have influence to the correct/incorrect behavore
of the OUT-Block.
Comment 1 Walter Bright 2012-01-24 21:46:28 UTC
Same fix as for 7335.

*** This issue has been marked as a duplicate of issue 7335 ***