D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6108 - Crash on inherited contract using overridden method in unittest
Summary: Crash on inherited contract using overridden method in unittest
Status: RESOLVED DUPLICATE of issue 7335
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Mac OS X
: P2 major
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-06-05 08:29 UTC by David Nadlinger
Modified: 2012-01-25 13:41 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 David Nadlinger 2011-06-05 08:29:41 UTC
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 Walter Bright 2012-01-25 13:41:45 UTC

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