www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - contracts + nested functions + derived types = poo

reply Buchan <kbuchan xtra.co.nz> writes:
Me again:

<code>
int main(){
	return foo(1);
}

struct a {int b;}

int foo(int i) {
	a bar()
	// uncomment for error
	/*out (result) {
		// out body
	}
	body */{
		a r;
		r.b = 1;
		return r;
	}
	
	return bar().b;
}
</code>

you probably need to specify -debug to get it.
Any derived type (structures, arrays, functions
(can you return a function?)) as a return type for
a nested function with any in/out/body block (even just body)
causes this.

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 09 2004
parent reply "Walter" <newshound digitalmars.com> writes:
I don't know what in specific you mean, but there are several syntactical
errors here.

"Buchan" <kbuchan xtra.co.nz> wrote in message
news:opsg68fuvz44buww simon.mshome.net...
 Me again:

 <code>
 int main(){
 return foo(1);
 }

 struct a {int b;}

 int foo(int i) {
 a bar()
 // uncomment for error
 /*out (result) {
 // out body
 }
 body */{
 a r;
 r.b = 1;
 return r;
 }

 return bar().b;
 }
 </code>

 you probably need to specify -debug to get it.
 Any derived type (structures, arrays, functions
 (can you return a function?)) as a return type for
 a nested function with any in/out/body block (even just body)
 causes this.

 -- 
 Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 11 2004
parent reply Buchan <kbuchan xtra.co.nz> writes:
On Thu, 11 Nov 2004 01:12:01 -0800, Walter <newshound digitalmars.com>  
wrote:

 I don't know what in specific you mean, but there are several syntactical
 errors here.

 "Buchan" <kbuchan xtra.co.nz> wrote in message
 news:opsg68fuvz44buww simon.mshome.net...
 Me again:

 <code>
 int main(){
 return foo(1);
 }

 struct a {int b;}

 int foo(int i) {
 a bar()
 // uncomment for error
 /*out (result) {
 // out body
 }
 body */{
 a r;
 r.b = 1;
 return r;
 }

 return bar().b;
 }
 </code>
 <snip>
Specificly? It compiles fine with it commented, and complains when uncommented. Is there any reason that a nested function that returns a non-basic type cannot have in/out contracts? Or am I being really stupid again? -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 11 2004
parent reply "Walter" <newshound digitalmars.com> writes:
"Buchan" <kbuchan xtra.co.nz> wrote in message
news:opshaqkvgr44buww simon.mshome.net...
 On Thu, 11 Nov 2004 01:12:01 -0800, Walter <newshound digitalmars.com>
 wrote:

 I don't know what in specific you mean, but there are several
syntactical
 errors here.

 "Buchan" <kbuchan xtra.co.nz> wrote in message
 news:opsg68fuvz44buww simon.mshome.net...
 Me again:

 <code>
 int main(){
 return foo(1);
 }

 struct a {int b;}

 int foo(int i) {
 a bar()
 // uncomment for error
You need an in{} preceding the out{}.
 /*out (result) {
 // out body
 }
 body */{
 a r;
 r.b = 1;
 return r;
 }

 return bar().b;
 }
 </code>
 <snip>
Specificly? It compiles fine with it commented, and complains when uncommented. Is there any reason that a nested function that returns a non-basic type cannot have in/out contracts? Or am I being really stupid again? -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 11 2004
next sibling parent reply Thomas =?UTF-8?B?S8O8aG5l?= <thomas-dloop kuehne.cn> writes:
Walter schrieb am Donnerstag, 11. November 2004 19:53:
 You need an in{} preceding the out{}.
Nested functions require a full set of in&out&body whereas "normal" functions require one of the combinations: body, in&body, out&body or in&out&body. Is this a bug or a language feature that I missed while reading the documentation? In addition I might have missed the sequence requirements for in/out/body. e.g. out/in/body compiles, but in/body/out fails Thomas
Nov 11 2004
parent "Walter" <newshound digitalmars.com> writes:
I'll review it again and straighten it out.

"Thomas Kühne" <thomas-dloop kuehne.cn> wrote in message
news:cn0llv$10u5$1 digitaldaemon.com...
 Walter schrieb am Donnerstag, 11. November 2004 19:53:
 You need an in{} preceding the out{}.
Nested functions require a full set of in&out&body whereas "normal" functions require one of the combinations: body, in&body, out&body or in&out&body. Is this a bug or a language feature that I missed while reading the documentation? In addition I might have missed the sequence requirements for in/out/body. e.g. out/in/body compiles, but in/body/out fails Thomas
Nov 11 2004
prev sibling parent reply Buchan <kbuchan xtra.co.nz> writes:
On Thu, 11 Nov 2004 10:53:48 -0800, Walter <newshound digitalmars.com>  
wrote:

 "Buchan" <kbuchan xtra.co.nz> wrote in message
 news:opshaqkvgr44buww simon.mshome.net...
 On Thu, 11 Nov 2004 01:12:01 -0800, Walter <newshound digitalmars.com>
 wrote:
<snip>
 You need an in{} preceding the out{}.
<snip> Oh? I didnt see that in the documentation... but it does the same even with both. int main(){ return foo(); } struct a {int b;} int foo() { a bar() /* in { assert(1); } out (result) { assert(result.b); } body*/ { a r; r.b = 1; return r; } a r2 = bar(); return r2.b; } If you rewrite this to return a basic type like int, it's fine. (Of course, I've made an idiot of myself before... ;) -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 13 2004
parent reply Thomas =?UTF-8?B?S8O8aG5l?= <thomas-dloop kuehne.cn> writes:
added to DStress as
http://svn.kuehne.cn/dstress/run/in_out_body_01.d
...
http://svn.kuehne.cn/dstress/run/in_out_body_04.d

Thomas

Buchan schrieb am Sonntag, 14. November 2004 07:50:
 Oh? I didnt see that in the documentation... but it does the same even
 with both.
 
 int main(){
 return foo();
 }
 
 struct a {int b;}
 
 int foo() {
 a bar()
 /*    in
 {
 assert(1);
 }
 out (result)
 {
 assert(result.b);
 }
 body*/
 {
 a r;
 r.b = 1;
 return r;
 }
 
 a r2 = bar();
 return r2.b;
 }
 
 If you rewrite this to return a basic type like int, it's fine.
 (Of course, I've made an idiot of myself before... ;) 
Nov 14 2004
parent "Simon Buchan" <currently no.where> writes:
Looking at the code, I see I accidently left my old e-mail in my account...

BTW, I really should use better names for my variables, nice clean (I think
I wrote that after reading some of the DMD frontend code though ]:D)

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 14 2004