Bug 7904 – Template instantiation failure depending on compilation order

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-13T22:03:00Z
Last change time
2013-11-29T21:32:05Z
Keywords
rejects-valid
Assigned to
nobody
Creator
dlang-bugzilla

Comments

Comment #0 by dlang-bugzilla — 2012-04-13T22:03:50Z
=== a.d === import std_algorithm; === b.d === import std_algorithm; void f() { startsWith("", ""); } === std_algorithm.d === dchar front(A)(A) { } uint startsWith()() { } bool startsWith(R1, R2)(R1 doesThisStart, R2) if (is(typeof(doesThisStart.front))) { return true; } === compiler command line === dmd -o- a.d b.d === compiler output === b.d(5): Error: template std_algorithm.startsWith does not match any function template declaration b.d(5): Error: template std_algorithm.startsWith cannot deduce template function from argument types !()(string,string) Changing the order of files on the command line unbreaks compilation.
Comment #1 by lovelydear — 2012-04-21T11:36:46Z
This looks like a duplicate of issue 7852, although the error messages are different.
Comment #2 by k.hara.pg — 2013-11-24T04:18:38Z
This is invalid issue. in std_algorithm.d: > dchar front(A)(A) { } > uint startsWith()() { } should be: dchar front(A)(A) { return 'a'; } uint startsWith()() { return 1; } After the fix, the sample code compiles normally.
Comment #3 by dlang-bugzilla — 2013-11-29T21:32:05Z
My apologies, this was a bad reduction - an obvious fact I should have noticed. Here is a working test case for DMD 2.059: === a.d === import std_algorithm; string longPath(string s) { s.startsWith(""); assert(0); } === b.d === import std_algorithm; void handleABC() { replace() ; } void dumpScriptTrait() { a; } === std_algorithm.d === template binaryFun(alias fun) { } R find(alias pred = "a == b", R, E)(R , E ) if (is(typeof(binaryFun!pred()) )) { } R1 find(R1, R2)(R1 , R2 ) { assert(false); } bool startsWith()(){} bool startsWith(alias pred = "a == b", R1, R2)(R1 , R2 ) if (is(typeof(binaryFun!pred))) { return false; } char[] replace()() { find("", ""); assert(0); } However, this bug was fixed in 2.064.2.