Bug 6108 – Crash on inherited contract using overridden method in unittest
Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2011-06-05T08:29:00Z
Last change time
2012-01-25T13:41:45Z
Keywords
wrong-code
Assigned to
nobody
Creator
code
Comments
Comment #0 by code — 2011-06-05T08:29:41Z
Consider the following piece of code:
---
class A {
bool isOpen() {
return false;
}
void read() in {
assert(isOpen);
} body {}
}
class B : A {
override bool isOpen() {
return foo_;
}
override void read() {}
bool foo_ = true;
}
void main() {}
unittest {
auto b = new B;
b.read();
}
---
Running the unittest with latest DMD (0ba8f0d) on OS X gives:
---
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000008
0x00000008 in ?? ()
(gdb) bt
#0 0x00000008 in ?? ()
Cannot access memory at address 0x8
#1 0x00001a0a in D4test1B4readMFZv ()
#2 0x00001a36 in D4test11__unittest1FZv ()
#3 0x00001973 in _D4test9__modtestFZv ()
#4 0x00008be9 in D4core7runtime18runModuleUnitTestsUZb16__foreachbody255MFKPS6object10ModuleInfoZi ()
#5 0x00003f9b in D6object10ModuleInfo7opApplyFMDFKPS6object10ModuleInfoZiZi ()
#6 0x00008ada in runModuleUnitTests ()
#7 0x0001232e in D2rt6dmain24mainUiPPaZi6runAllMFZv ()
#8 0x00011ea5 in D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv ()
#9 0x00011e3f in main ()
---
Some observations:
- The segfault occurs in the read() in contract.
- It only occurs if the code is run in an unittest block.
- The problem seems to be accessing foo_ – if I change B.isOpen to »return true;«, it works fine.
Comment #1 by bugzilla — 2012-01-25T13:41:45Z
*** This issue has been marked as a duplicate of issue 7335 ***