> It's been my understanding that it's always been illegal to provide a definition for a function that was declared previously unless it was declared in a .di file
Compiler has always allowed that: ``` void fun(); void fun(){} ``` (but see details in bug report) > It's useful with stuff like version(Ddoc). I guess you mean `version(StdDdoc)` ? On that note, I see things like this, which are not DRY: ``` version(StdDdoc) string readLink(R)(R link) if (isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R) || isConvertibleToString!R); else version(Posix) string readLink(R)(R link) if (isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R) || isConvertibleToString!R) ``` Is this pattern used because we want to build DDoc on a not-necessarily Posix system (ie to get a DDoc regardless of which environment)? If so, it seems like an anti-pattern; better options could be: * build platform specific documentation (which actually makes sense, eg a windows user may not want to see Posix-only functions) * add a special compiler flag that overrides predefined builtins (eg Posix) On Wed, Feb 7, 2018 at 11:21 PM, Jonathan M Davis via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote: > On Wednesday, February 07, 2018 13:39:55 Timothee Cour via Digitalmars-d- > learn wrote: >> ``` >> void fun_bad3(T)(T a); // declaration [1] >> void fun_bad3(T)(T a){}; // definition [2] >> void test(){ >> fun_bad3(1); >> } >> ``` >> Error: test_all.fun_bad3 called with argument types (int) matches both: >> main.d(11): test_all.fun_bad3!int.fun_bad3(int a) >> and: >> main.d(12): test_all.fun_bad3!int.fun_bad3(int a) >> >> should [1] be allowed? > > It's useful with stuff like version(Ddoc). > >> compler doens't allow defining it afterwards in >> [2] (unlike function definitions, and, well, modulo this regression >> https://issues.dlang.org/show_bug.cgi?id=18393) > > It's been my understanding that it's always been illegal to provide a > definition for a function that was declared previously unless it was > declared in a .di file, in which case, you're not really both declaring and > defining it, but the .d file is used when the module is compiled, and the > .di file is used by other modules which use that module, so the declaration > and definition are not seen by the same run of the compiler. > > - Jonathan M Davis >