D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7768 - More readable template error messages
Summary: More readable template error messages
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 minor
Assignee: No Owner
URL:
Keywords: diagnostic, pull
: 2696 (view as issue list)
Depends on:
Blocks:
 
Reported: 2012-03-24 23:23 UTC by Kenji Hara
Modified: 2012-03-26 20:56 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2012-03-24 23:23:43 UTC
This code has bad usage of std.conv.parse template function.
But raised error message is less readable.

import std.conv;
void test1()
{
    int value;
    parse(value);
    // Error: template std.conv.parse(Target,Source)
    //   if (isSomeChar!(ElementType!(Source)) && isIntegral!(Target))
    //   does not match any function template declaration
    // Error: template std.conv.parse(Target,Source)
    //   if (isSomeChar!(ElementType!(Source)) && isIntegral!(Target))
    //   cannot deduce template function from argument types !()(int)
}

parse template function is overloaded, so printing template parameter and constraint is much confusing.
It should print like follows:

    // Error: template std.conv.parse does not match any
    //   function template declaration
    // Error: template std.conv.parse cannot deduce template function
    //   from argument types !()(int)
}

"matches more than one template declaration" error message has same problem.

void foo(T)(T val) if (is(T : int)) {}
void foo(T)(T val) if (is(T : long)) {}
void test2()
{
    foo(10);
    // Error: template test.foo(T) if (is(T : int)) foo(T) if (is(T : int))
    //   matches more than one template declaration,
    //   test.d(29):foo(T) if (is(T : int)) and
    //   test.d(30):foo(T) if (is(T : long))

should print:
    // Error: template test.foo matches more than one template declaration,
    //   test.d(29):foo(T) if (is(T : int)) and
    //   test.d(30):foo(T) if (is(T : long))
}

If there is only one template function, keeping specialized error message is better.

void bar(T)(T val) if (is(T : int)) {}
void test3()
{
    bar("abc");
    // Error: test.bar does not match any function template declaration
    // Error: template test.bar(T) if (is(T : int)) cannot deduce
    //   template function from argument types !()(string)
}
Comment 2 Kenji Hara 2012-03-25 01:16:57 UTC
*** Issue 2696 has been marked as a duplicate of this issue. ***
Comment 3 github-bugzilla 2012-03-26 18:42:04 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/28c0da04f3640f3313b1229161232fee53ca1cd2
Merge pull request #839 from 9rnsr/fix7768

Issue 7768 - More readable template error messages