www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 247] New: Cannot return from nested functions in contracts

reply d-bugmail puremagic.com writes:
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.


-- 
Jul 09 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=247


jpelcis gmail.com changed:

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





Fixed DMD 0.163.


-- 
Jul 18 2006
prev sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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 -----BEGIN PGP SIGNATURE----- iD8DBQFE4aGaLK5blCcjpWoRAgZRAJ0WShcQqmGExp/zXYR33E2w60S0mACeIxpb xO5MG6ppSYP7j2YHVer7JMc= =5OBw -----END PGP SIGNATURE-----
Aug 15 2006