Bug 7336 – Sometimes OUT-Block dont have correct acces to method-parameter
Status
RESOLVED
Resolution
DUPLICATE
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2012-01-21T10:02:00Z
Last change time
2012-01-24T21:46:28Z
Assigned to
nobody
Creator
devbai
Comments
Comment #0 by devbai — 2012-01-21T10:02:07Z
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 by bugzilla — 2012-01-24T21:46:28Z
Same fix as for 7335.
*** This issue has been marked as a duplicate of issue 7335 ***