www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2026] New: Misleading error message when passing non-existent symbol to template

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2026

           Summary: Misleading error message when passing non-existent
                    symbol to template
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: andrei metalanguage.com


Prompted by a post by Bryan Myers:

import std.string;
import std.algorithm;

void main(char[][] args)
{
    string[] words = ["c", "ab", "bb"];
    sort!("a < b", SortStrategy.stable)(words);
    assert(words == ["ab", "bb", "c"]);
}

The code uses the non-existent symbol SortStrategy.stable instead of the
correct SwapStrategy.stable. However, the error message implies that the symbol
does exist and has type int:

/home/andrei/test.d(8): template std.algorithm.sort(alias less,SwapStrategy ss
= SwapStrategy.unstable,alias iterSwap = .iterSwap,Range) does not match any
function template declaration
/home/andrei/test.d(8): template std.algorithm.sort(alias less,SwapStrategy ss
= SwapStrategy.unstable,alias iterSwap = .iterSwap,Range) cannot deduce
template function from argument types !("a < b",int)(invariant(char)[][])


-- 
Apr 23 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2026


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Keywords|                            |diagnostic




------- Comment #1 from smjg iname.com  2008-11-22 10:07 -------
This looks like a case of an old issue (which ought to be reported, but I can't
seem to find it) where any expression found invalid by semantic analysis is
treated as int, except that this kind of error normally follows an error
explaining that the expression is invalid.


-- 
Nov 22 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2026


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |FIXED


--- Comment #2 from yebblies <yebblies gmail.com> 2011-06-10 05:45:28 PDT ---
The test case now prints:

testx.d(7): Error: undefined identifier SortStrategy.stable
testx.d(7): Error: template std.algorithm.sort(alias less = "a <
b",SwapStrategy
 ss = SwapStrategy.unstable,Range) does not match any function template
declarat
ion
testx.d(7): Error: template std.algorithm.sort(alias less = "a <
b",SwapStrategy
 ss = SwapStrategy.unstable,Range) cannot deduce template function from
argument
 types !("a < b",_error_)(string[])
testx.d(7): Error: template instance errors instantiating template


(dmd 2.053)
Which correctly identifies the cause of the error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 10 2011