Bug 247 – Cannot return from nested functions in contracts

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-07-09T06:16:00Z
Last change time
2014-02-15T13:19:05Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
matti.niemenmaa+dbugzilla

Comments

Comment #0 by matti.niemenmaa+dbugzilla — 2006-07-09T06:16:29Z
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.
Comment #1 by jpelcis — 2006-07-18T16:40:33Z
Fixed DMD 0.163.
Comment #2 by thomas-dloop — 2006-08-15T04:58:19Z
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [email protected] 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-----