digitalmars.D.bugs - [Issue 15346] New: Calling interface methods on out contracts causes
- via Digitalmars-d-bugs (56/56) Nov 16 2015 https://issues.dlang.org/show_bug.cgi?id=15346
https://issues.dlang.org/show_bug.cgi?id=15346 Issue ID: 15346 Summary: Calling interface methods on out contracts causes segfaults Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: major Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: initrd.gz gmail.com One of my projects started mysteriously throwing segfaults. I managed to narrow it down to a line in one of my interface's out contracts that compared the result with a value returned by a property method defined on the interface. Even doing `debug stderr.writeln(this);` threw a segfault; GDB says its from the `_d_interface_cast` function. The full code is too big to post here, but I think I narrowed it down: import std.stdio; interface A { int* aField() property pure; int foo() out(v) { debug stderr.writeln(this.aField); } } class F : A{ this() {} int myField; int* aField() property pure { return &myField; } int foo() { debug stderr.writeln(this.aField); return 0; } } void main() { auto f = new F(); f.foo(); } I expect that this function would print the same address twice; it prints out `aField`, a simple function that returns a pointer to a class member, once in a function body and once in the interface's out contract. Running it with `rdmd -debug test.d` results in the following output: 7F21F379F010 6 The first address differs with each run (as expected with memory addresses) but the second line is consistently a 6. Moving the out contract to the implementation of foo method in class F results in the correct output (the same address printed twice). I suspect that the pointer adjustment that happens with `this` in an out contract is being done incorrectly, but I don't have the skills to diagnose it further. Using dmd v2.069.1 on x64 XUbuntu --
Nov 16 2015