Thread overview | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 09, 2014 [Issue 12724] Error: return statements cannot be in contracts | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12724 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrej.mitrovich@gmail.com --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> --- Test-case? -- |
May 09, 2014 [Issue 12724] Error: return statements cannot be in contracts | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12724 --- Comment #2 from monarchdodra@gmail.com --- (In reply to Andrej Mitrovic from comment #1) > Test-case? //---- void foo(int i) in { if (i == 0) return; assert(10/i > 1); } body { } //---- -- |
May 09, 2014 [Issue 12724] Error: return statements cannot be in contracts | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12724 --- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> --- Yeah it seems like an arbitrary limitation since invariants allow return statements. -- |
May 11, 2014 [Issue 12724] Error: return statements cannot be in contracts | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12724 bearophile_hugs@eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs@eml.cc --- Comment #4 from bearophile_hugs@eml.cc --- I am strongly against this and I suggest to close this issue down as soon as possible. My vote is -2. Please don't turn D contracts programming into a semantic soup. (In reply to Andrej Mitrovic from comment #3) > Yeah it seems like an arbitrary limitation since invariants allow return statements. I didn't know this, let's remove returns from invariants ASAP. I'll open an ER to ask them to be removed. -- |
May 11, 2014 [Issue 12724] Error: return statements cannot be in contracts | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12724 --- Comment #5 from bearophile_hugs@eml.cc --- (In reply to Andrej Mitrovic from comment #3) > Yeah it seems like an arbitrary limitation since invariants allow return statements. That limitation is very far from being arbitrary. -- |
May 11, 2014 [Issue 12724] Error: return statements cannot be in contracts | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12724 --- Comment #6 from monarchdodra@gmail.com --- (In reply to bearophile_hugs from comment #4) > I am strongly against this... Why though? What's your arguments? It's pretty arbitrary. If you don't *need* to use a return, then don't use one. If you *do* need a return, why would we want to restrain it? -- |
May 11, 2014 [Issue 12724] Error: return statements cannot be in contracts | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12724 --- Comment #7 from bearophile_hugs@eml.cc --- (In reply to monarchdodra from comment #6) > What's your arguments? Is return from contract present in the DbC of Eiffel/Ada/C#/Racket? What does it means returning from a test that verifies if a contract is holding? I think allowing returns goes against the meaning of contracts. They are not meant to change the flow of the code, all they have to do is to verify the input or outputs or invariants are correct. -- |
May 11, 2014 [Issue 12724] Error: return statements cannot be in contracts | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12724 --- Comment #8 from monarchdodra@gmail.com --- (In reply to bearophile_hugs from comment #7) > (In reply to monarchdodra from comment #6) > > > What's your arguments? > > What does it means returning from a test that > verifies if a contract is holding? It means you've tested what needs to be tested, and the input given need to proceed with the rest of the code. Actual example in phobos: auto assumeSorted(Range)(Range r) in { if (range.length <= 1) return; //more than 1 element, do actual tests ... } body > I think allowing returns goes against the meaning of contracts. They are not meant to change the flow of the code, all they have to do is to verify the input or outputs or invariants are correct. "Flow of code" does not mean the code actual "does" anything, and I see nothing wrong with having control structures in a contract. Not being able to return in the middle of the contract is basically *forcing* the "single point of exit" paradigm. And we know how that ends... In any case, it's completely inconsistent with the rest of the language. Besides, it can be just as easily worked around with: in { void doTest(){...} doTest(); } or in {{ if (...) goto end; }end:} Long story short: If you *do* need to prematurely end the function, you are forced to write crap. -- |
May 11, 2014 [Issue 12724] Error: return statements cannot be in contracts | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12724 --- Comment #9 from bearophile_hugs@eml.cc --- (In reply to monarchdodra from comment #8) > It means you've tested what needs to be tested, and the input given need to proceed with the rest of the code. So the return ends just the contract. I misunderstood this, sorry. -- |
May 12, 2014 [Issue 12724] Error: return statements cannot be in contracts | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12724 --- Comment #10 from monarchdodra@gmail.com --- (In reply to bearophile_hugs from comment #9) > (In reply to monarchdodra from comment #8) > > > It means you've tested what needs to be tested, and the input given need to proceed with the rest of the code. > > So the return ends just the contract. I misunderstood this, sorry. I understand why you are against this now. Seems like a misunderstanding on what the return would actually do. -- |
Copyright © 1999-2021 by the D Language Foundation