[Issue 247] New: Cannot return from nested functions in contracts
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jul 9 04:16:30 PDT 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 at digitalmars.com
ReportedBy: deewiant at 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.
--
More information about the Digitalmars-d-bugs
mailing list