Thread overview
[Issue 4648] New: "In" contracts in interfaces missbehaving
Aug 15, 2010
Andrej Mitrovic
Jun 05, 2011
Mike Shulman
Jun 05, 2011
Denis Karabaza
Jan 25, 2012
Walter Bright
August 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4648

           Summary: "In" contracts in interfaces missbehaving
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-08-15 12:59:13 PDT ---
Code:

interface I
{
    int foo(int i)
      in { writeln(i); assert(i == 4); }
}

class Base : I
{
    int foo(int i)
    {
        return i;
    }
}

import std.stdio;

void main()
{
    auto b = new Base;
    b.foo(4);
}

The writeln will output garbage, ex:
1630368629
core.exception.AssertError@test(83): Assertion failure

You can remove the writeln, but the assert still fails. I'm using the same syntax as defined in the docs: http://www.digitalmars.com/d/2.0/interface.html

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4648


Mike Shulman <viritrilbia+d@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |viritrilbia+d@gmail.com


--- Comment #1 from Mike Shulman <viritrilbia+d@gmail.com> 2011-06-04 20:37:50 PDT ---
'Out' contracts in interfaces seem to have the same problem: the arguments passed to the function get replaced by garbage.

On my system (DMD v2.053 on Ubuntu) the precise value of the garbage appears to depend on what data members exist in the class which implements the interface. E.g. Andrej's code writeln outputs "0" for me, but if I add "int x;" to the definition of Base, it outputs instead "135115244".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4648


Denis Karabaza <truesmiler@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |truesmiler@gmail.com


--- Comment #2 from Denis Karabaza <truesmiler@gmail.com> 2011-06-05 09:02:54 PDT ---
Same problem, when overriding contracted function (D 2.053, windows and
ubutnu).
So, it seems to be about all the contract inheritance.

class A {
  void f(int a)
  in { writeln(a); }
  out { writeln(a); }
  body {}
}

class B: A {
  override void f(int a) { writeln(a); }
}

void main() {
  A a = new B;
  a.f(42); // prints <garbage>, 42, <garbage>
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=4648


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |DUPLICATE


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2012-01-25 12:41:12 PST ---
*** This issue has been marked as a duplicate of issue 7335 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------