Thread overview
[Issue 247] New: Cannot return from nested functions in contracts
Jul 09, 2006
d-bugmail
Jul 18, 2006
d-bugmail
Aug 15, 2006
Thomas Kuehne
July 09, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=247

           Summary: Cannot return from nested functions in contracts
           Product: D
           Version: 0.162
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: deewiant@gmail.com


void foo()
in {
        static void checkParameters() {
                return;
        }

        checkParameters();
} body {
}
--
The above fails, because "return statements cannot be in contracts" --- which makes sense, but the return statement in this case is not returning from the contract, but from a function within the contract. The D documentation says that "[a]ny other D statement or expression [than assert] is allowed in the [contract] bodies", so I see no reason for this not to work.

In the case of a void-returning function such as the above, it is naturally simple to sidestep the issue, but with a more complex function, such as a recursive one with many possible execution paths, this can be a real problem.


-- 

July 18, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=247


jpelcis@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #1 from jpelcis@gmail.com  2006-07-18 16:40 -------
Fixed DMD 0.163.


-- 

August 15, 2006
d-bugmail@puremagic.com schrieb am 2006-07-09:
> http://d.puremagic.com/issues/show_bug.cgi?id=247

> void foo()
> in {
>         static void checkParameters() {
>                 return;
>         }
>
>         checkParameters();
> } body {
> }
> --
> The above fails, because "return statements cannot be in contracts" --- which makes sense, but the return statement in this case is not returning from the contract, but from a function within the contract. The D documentation says that "[a]ny other D statement or expression [than assert] is allowed in the [contract] bodies", so I see no reason for this not to work.
>
> In the case of a void-returning function such as the above, it is naturally simple to sidestep the issue, but with a more complex function, such as a recursive one with many possible execution paths, this can be a real problem.

Added to DStress as http://dstress.kuehne.cn/run/i/in_out_body_12_A.d http://dstress.kuehne.cn/run/i/in_out_body_12_B.d http://dstress.kuehne.cn/run/i/in_out_body_12_C.d

Thomas