digitalmars.D.learn - Function overloading between modules
- JN (20/20) Feb 22 2018 Is this expected behaviour?
- ketmar (7/27) Feb 22 2018 yes. this is done so unqualified won't silently "steal" your functions.
- JN (19/26) Feb 22 2018 I see, how about this one:
- ketmar (3/4) Feb 22 2018 absolutely the same. non-qualified imports (be it template, or function)...
- bauss (2/22) Feb 23 2018 https://dlang.org/articles/hijack.html
Is this expected behaviour? bar.d --- void foo(string s) { } app.d --- import std.stdio; import bar; void foo(int x) { } void main() { foo("hi"); }; === Error: function app.foo (int x) is not callable using argument types (string)
Feb 22 2018
JN wrote:Is this expected behaviour? bar.d --- void foo(string s) { } app.d --- import std.stdio; import bar; void foo(int x) { } void main() { foo("hi"); }; === Error: function app.foo (int x) is not callable using argument types (string)yes. this is done so unqualified won't silently "steal" your functions. this can cause some unexpected (and hard to find) bugs. if you want it to work, you can either do qualified import import bar : foo; or manuall bring overloads from `bar` with alias foo = bar.foo;
Feb 22 2018
On Thursday, 22 February 2018 at 21:19:12 UTC, ketmar wrote:yes. this is done so unqualified won't silently "steal" your functions. this can cause some unexpected (and hard to find) bugs. if you want it to work, you can either do qualified import import bar : foo; or manuall bring overloads from `bar` with alias foo = bar.foo;I see, how about this one: bar.d --- void foo(T)(T t) { } app.d --- import std.stdio; import bar; void foo(T : string)(T t) { } void main() { foo(123); }; same idea?
Feb 22 2018
JN wrote:same idea?absolutely the same. non-qualified imports (be it template, or function) won't take part in overload resoultion.
Feb 22 2018
On Thursday, 22 February 2018 at 21:12:45 UTC, JN wrote:Is this expected behaviour? bar.d --- void foo(string s) { } app.d --- import std.stdio; import bar; void foo(int x) { } void main() { foo("hi"); }; === Error: function app.foo (int x) is not callable using argument types (string)https://dlang.org/articles/hijack.html
Feb 23 2018