Thread overview
[Issue 6549] New: Implement contracts without implementation.
Aug 24, 2011
timon.gehr@gmx.ch
Jan 28, 2012
Shahid
Jan 28, 2012
timon.gehr@gmx.ch
Feb 12, 2012
Stewart Gordon
Feb 29, 2012
Stewart Gordon
Jun 30, 2013
Henning Pohl
August 24, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6549

           Summary: Implement contracts without implementation.
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: timon.gehr@gmx.ch


--- Comment #0 from timon.gehr@gmx.ch 2011-08-24 11:23:34 PDT ---
currently, code like the following is rejected:

abstract class C{
    int foo(int x)
      in{assert(x<0);}
      out(result){assert(result>0);}
}

tt.d(10): Error: function tt.C.foo in and out contracts require function body.

Which does not make sense, because contracts logically belong to the method declaration.

Such code should be accepted and the contracts should be subject to contract inheritance. This will require a tiny grammar change.

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


Shahid <govellius@gmail.com> changed:

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


--- Comment #1 from Shahid <govellius@gmail.com> 2012-01-28 03:46:36 PST ---
I would like a clarification about abstract class/methods with contracts. Should the bottom two examples be valid D code?

----
// Works ( and documented TDPL/website )
interface I {
        int func( int x )
        in { assert(x == 0); }
}
class C : I {
        int func( int x ) { return x; }
}

// Does not work ( undocumented )
abstract class A
{
        int func( int x )
        in { assert(x == 0); }
}
// ditto
class A2 {
        abstract int func( int x )
        in { assert(x == 0); }
}

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



--- Comment #2 from timon.gehr@gmx.ch 2012-01-28 07:46:14 PST ---
Yes, that is the plan.

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


Alex Rønne Petersen <xtzgzorex@gmail.com> changed:

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


--- Comment #3 from Alex Rønne Petersen <xtzgzorex@gmail.com> 2012-02-12 09:17:40 PST ---
Is there any news on this? Design-by-contract in D is seriously crippled due to this bug.

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


Stewart Gordon <smjg@iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com
           Severity|normal                      |enhancement


--- Comment #4 from Stewart Gordon <smjg@iname.com> 2012-02-12 10:07:15 PST ---
(In reply to comment #3)
> Is there any news on this? Design-by-contract in D is seriously crippled due to this bug.

It's an arbitrary restriction, not a bug.

http://www.dlang.org/declaration.html
Decl:
    StorageClasses Decl
    BasicType Declarators ;
    BasicType Declarator FunctionBody
    AutoDeclaration

http://www.dlang.org/function.html
FunctionBody:
    BlockStatement
    BodyStatement
    InStatement BodyStatement
    OutStatement BodyStatement
    InStatement OutStatement BodyStatement
    OutStatement InStatement BodyStatement

InStatement and OutStatement are part of FunctionBody, so if the function has no body then it can't have in and out contracts.

But I entirely agree that it should be allowed.  Contracts are part of the API, not the implementation.  As such, they are equally applicable to abstract/interface methods.  It could also improve contract checking in closed-source libraries.

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



--- Comment #5 from Stewart Gordon <smjg@iname.com> 2012-02-29 06:05:03 PST ---
Possible grammar rewrite:

Decl:
    StorageClasses Decl
    BasicType Declarators ;
    BasicType Declarator BlockStatement
    BasicType Declarator BodyStatement
    BasicType Declarator Contracts ;
    BasicType Declarator Contracts BodyStatement
    AutoDeclaration

Contracts:
    InStatement
    OutStatement
    InStatement OutStatement
    OutStatement InStatement

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


Henning Pohl <henning@still-hidden.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
                 CC|                            |henning@still-hidden.de


--- Comment #6 from Henning Pohl <henning@still-hidden.de> 2013-06-30 08:26:15 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2281

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