www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - struct opCall error messages

reply Rory Mcguire <rjmcguire gm_no_ail.com> writes:
Hi,

I'm not sure this is in bugzilla, I tried finding something mentioning it 
but coudn't.

Compiling the below code results in the dmd compiler printing:
struct_bad_error.d(8): Error: 'this' is only defined in non-static member 
functions, not inner

====================
struct S {
	S opCall() {S s; return s;}
}
void main() {
	S s;
	//s = S(); // decent error message: "struct_bad_error.d(6):
		// Error: need 'this' to access member opCall"
	void inner() {
		s = S();
	}
}
=====================

What to do? Also found that having an empty () after the struct name is not 
the best error message: "struct_bad_error.d(5): Error: struct 
struct_bad_error.S() is used as a type"

Surely it could tell me I need to put an Identifier in the ()

-Rory
Jul 26 2010
parent reply Jacob Carlborg <doob me.com> writes:
On 2010-07-26 14:27, Rory Mcguire wrote:
 Hi,

 I'm not sure this is in bugzilla, I tried finding something mentioning it
 but coudn't.

 Compiling the below code results in the dmd compiler printing:
 struct_bad_error.d(8): Error: 'this' is only defined in non-static member
 functions, not inner

 ====================
 struct S {
 	S opCall() {S s; return s;}
 }
 void main() {
 	S s;
 	//s = S(); // decent error message: "struct_bad_error.d(6):
 		// Error: need 'this' to access member opCall"
 	void inner() {
 		s = S();
 	}
 }
 =====================

 What to do? Also found that having an empty () after the struct name is not
 the best error message: "struct_bad_error.d(5): Error: struct
 struct_bad_error.S() is used as a type"

 Surely it could tell me I need to put an Identifier in the ()

 -Rory
Perhaps you want a static opCall ? S foo; foo(); // calls opCall S(); // calls static opCall -- /Jacob Carlborg
Jul 27 2010
parent Rory Mcguire <rjmcguire gm_no_ail.com> writes:
Jacob Carlborg wrote:

 On 2010-07-26 14:27, Rory Mcguire wrote:
 Hi,

 I'm not sure this is in bugzilla, I tried finding something mentioning it
 but coudn't.

 Compiling the below code results in the dmd compiler printing:
 struct_bad_error.d(8): Error: 'this' is only defined in non-static member
 functions, not inner

 ====================
 struct S {
 S opCall() {S s; return s;}
 }
 void main() {
 S s;
 //s = S(); // decent error message: "struct_bad_error.d(6):
 // Error: need 'this' to access member opCall"
 void inner() {
 s = S();
 }
 }
 =====================

 What to do? Also found that having an empty () after the struct name is
 not the best error message: "struct_bad_error.d(5): Error: struct
 struct_bad_error.S() is used as a type"

 Surely it could tell me I need to put an Identifier in the ()

 -Rory
Perhaps you want a static opCall ? S foo; foo(); // calls opCall S(); // calls static opCall
doh! [slaps head] Thanks
Jul 28 2010