| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
February 28, 2009 Need clear error msg. (template instantiating) | ||||
|---|---|---|---|---|
| ||||
I need clear error-messages of compiling.
See this code.
// example.d
import std.conv: to;
void main( ){
S s;
to!( int )( s ); // 'to' does not support struct-argument.
}
struct S{
}
'to' cannot convert 'S' to 'int', so that this is error. Then I got mysterious messages.
"src\phobos\std\conv.d(344): Error: cannot implicitly convert expression (value) of type S to int"
"src\phobos\std\conv.d(206): template instance std.conv.toImpl!(S,int) error instantiating"
"src\phobos\std\conv.d(4): template instance std.conv.to!(int).to!(S) error instantiating"
We know 'std.conv.d' has no error, and assume 'example.d' has some. The problem is 'std.conv.d' seems to have errors.
The message should be as follows.
"example.d(5): template instance to!(S)(int,S) does not match template declaration."
Thank you for your reading.
| ||||
February 28, 2009 Re: Need clear error msg. (template instantiating) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to CLXX | On Sat, 28 Feb 2009 13:36:25 -0500, CLXX wrote:
> I need clear error-messages of compiling. See this code.
>
> // example.d
> import std.conv: to;
> void main( ){
> S s;
> to!( int )( s ); // 'to' does not support struct-argument.
> }
> struct S{
> }
>
> 'to' cannot convert 'S' to 'int', so that this is error. Then I got mysterious messages.
>
> "src\phobos\std\conv.d(344): Error: cannot implicitly convert expression
> (value) of type S to int" "src\phobos\std\conv.d(206): template instance
> std.conv.toImpl!(S,int) error instantiating" "src\phobos\std\conv.d(4):
> template instance std.conv.to!(int).to!(S) error instantiating"
>
> We know 'std.conv.d' has no error, and assume 'example.d' has some. The problem is 'std.conv.d' seems to have errors.
>
> The message should be as follows.
>
> "example.d(5): template instance to!(S)(int,S) does not match template
> declaration."
>
> Thank you for your reading.
What do you expect the integer from such a struct to be?
What you are trying to do makes no sense to me.
The compiler tells you the same.
| |||
February 28, 2009 Re: Need clear error msg. (template instantiating) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to CLXX | CLXX wrote: > I need clear error-messages of compiling. > See this code. > > // example.d > import std.conv: to; > void main( ){ > S s; > to!( int )( s ); // 'to' does not support struct-argument. > } > struct S{ > } > > 'to' cannot convert 'S' to 'int', so that this is error. > Then I got mysterious messages. > > "src\phobos\std\conv.d(344): Error: cannot implicitly convert expression (value) of type S to int" > "src\phobos\std\conv.d(206): template instance std.conv.toImpl!(S,int) error instantiating" > "src\phobos\std\conv.d(4): template instance std.conv.to!(int).to!(S) error instantiating" > > We know 'std.conv.d' has no error, and assume 'example.d' has some. > The problem is 'std.conv.d' seems to have errors. > > The message should be as follows. > > "example.d(5): template instance to!(S)(int,S) does not match template declaration." > > Thank you for your reading. Thanks, that's a good point. We need to make a few changes to the way the compiler and static assert work to get to that point. Phobos in my tree (i.e., as of two releases from now) already points at your file and line, however with not such a clear message: ./example.d(5): template std.conv.to(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) && isSomeString!(S)) does not match any function template declaration ./example.d(5): template std.conv.to(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) && isSomeString!(S)) cannot deduce template function from argument types!(int)(S) Showing the if clause is completely superfluous (I just filed a bug report about that, see http://d.puremagic.com/issues/show_bug.cgi?id=2696) so at least you'll see something like: ./example.d(5): template std.conv.to(T,S) does not match any function template declaration ./example.d(5): template std.conv.to(T,S) cannot deduce template function from argument types!(int)(S) which is rather passable. Andrei | |||
February 28, 2009 Re: Need clear error msg. (template instantiating) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Moritz Warning | On Sat, 28 Feb 2009 19:41:59 +0000, Moritz Warning wrote:
> On Sat, 28 Feb 2009 13:36:25 -0500, CLXX wrote:
>
>> I need clear error-messages of compiling. See this code.
>>
>> // example.d
>> import std.conv: to;
>> void main( ){
>> S s;
>> to!( int )( s ); // 'to' does not support struct-argument.
>> }
>> struct S{
>> }
>>
>> 'to' cannot convert 'S' to 'int', so that this is error. Then I got mysterious messages.
>>
>> "src\phobos\std\conv.d(344): Error: cannot implicitly convert
>> expression (value) of type S to int" "src\phobos\std\conv.d(206):
>> template instance std.conv.toImpl!(S,int) error instantiating"
>> "src\phobos\std\conv.d(4): template instance std.conv.to!(int).to!(S)
>> error instantiating"
>>
>> We know 'std.conv.d' has no error, and assume 'example.d' has some. The problem is 'std.conv.d' seems to have errors.
>>
>> The message should be as follows.
>>
>> "example.d(5): template instance to!(S)(int,S) does not match template
>> declaration."
>>
>> Thank you for your reading.
>
> What do you expect the integer from such a struct to be? What you are trying to do makes no sense to me. The compiler tells you the same.
Nvm, I'm too tired today.
| |||
March 01, 2009 Re: Need clear error msg. (template instantiating) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Moritz Warning | Moritz Warning Wrote:
> What do you expect the integer from such a struct to be?
> What you are trying to do makes no sense to me.
> The compiler tells you the same.
What is important is, compilier should show correct messages when we wrote illegal code.
Thank you.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply