Bug 2026 – Misleading error message when passing non-existent symbol to template
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2008-04-23T15:42:00Z
Last change time
2015-06-09T05:15:10Z
Keywords
diagnostic
Assigned to
nobody
Creator
andrei
Comments
Comment #0 by andrei — 2008-04-23T15:42:17Z
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)[][])
Comment #1 by smjg — 2008-11-22T10:07:27Z
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.
Comment #2 by yebblies — 2011-06-10T05:45:28Z
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.