Bug 4936 – Better error when type inference fails due to incorrect template parameter type

Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-09-24T16:37:19Z
Last change time
2023-02-02T11:24:16Z
Assigned to
No Owner
Creator
Jesse Phillips

Comments

Comment #0 by Jesse.K.Phillips+D — 2010-09-24T16:37:19Z
Basically two string[] fail to mach the completeSort signature. This worked with 2.048 import std.algorithm; void main() { auto foo = ["a the way home", "can I say"]; auto bar = ["be it here or there", "you may"]; completeSort(foo, bar); } test.d(7): Error: template std.algorithm.completeSort(alias less = "a < b",SwapStrategy ss = SwapStrategy.unstable,Range1,Range2) if (hasLength!(Range2) && hasSlicing!(Range2)) does not match any function template declaration test.d(7): Error: template std.algorithm.completeSort(alias less = "a < b",SwapStrategy ss = SwapStrategy.unstable,Range1,Range2) if (hasLength!(Range2) && hasSlicing!(Range2)) cannot deduce template function from argument types !()(string[],string[])
Comment #1 by Jesse.K.Phillips+D — 2010-10-26T12:20:41Z
completeSort no longer takes arbitrary ranges, it takes a SortedRange as the first parameter, and that is causing the error. I guess the easiest would be to include the parameter list, but maybe that would make it too cluttered?
Comment #2 by Jesse.K.Phillips+D — 2010-10-26T12:51:39Z
Looks like the example code doesn't actually work either. import std.algorithm; import std.range; void main() { int[] a = [ 1, 2, 3 ]; int[] b = [ 4, 0, 6, 5 ]; completeSort(assumeSorted(a), b); assert(a == [ 0, 1, 2 ]); assert(b == [ 3, 4, 5, 6 ]); }
Comment #3 by b.helyer — 2012-07-02T02:54:58Z
Really? This has been broken since _049_ and no one has commented on it? Clearly, no one is using completeSort at all.
Comment #4 by greensunny12 — 2018-02-11T00:15:39Z
This works: --- import std.stdio, std.algorithm, std.range; void main() { auto foo = ["a the way home", "can I say"]; auto bar = ["be it here or there", "you may"]; completeSort(foo.assumeSorted, bar.assumeSorted); } --- https://run.dlang.io/is/aeO4fp > Clearly, no one is using completeSort at all Yeah if it's open for eight years, that's a very good sign no one uses it... I'm closing this as it's too old for an regression and assumeSorted works.
Comment #5 by Jesse.K.Phillips+D — 2018-02-12T01:12:13Z
Seb, this is specifically about the error message poorly directing the user to provide a SortedRange. This was more confusing to me since I hit the issue after the library change, rather than when initially writing the code. As I don't know exact changes to improve the error message I'll leave it closed, but it is a larger issue using templates and type inference which could be improved.
Comment #6 by greensunny12 — 2018-02-12T04:20:57Z
Argh sorry - I was too busy working myself through old issues. Thanks for the reminder. -> REOPENED
Comment #7 by razvan.nitu1305 — 2023-02-02T11:24:16Z
Right now the error is: Error: none of the overloads of template `std.algorithm.sorting.completeSort` are callable using argument types `!()(string[], string[])` Candidate is: `completeSort(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable, Lhs, Rhs)(SortedRange!(Lhs, less) lhs, Rhs rhs)` So it is pointing the declaration and it can be observed that `foo` is not SortedRange.