This is intended as a feature. If you are using module A for your code, and it didn't export `f`, but then you (or one of your users) upgraded `module A`, they would not be happy if it broke their code for a function they didn't care about that got added to the export list of A. So instead, julia adds a requirement that you must `import A.f` if you want to extend `f`. Then, to help the library author catch mistakes, when the method is first used, it is marked as having come from an external library, so that the identity of that lookup can't change later.
On Sat, May 2, 2015 at 12:13 PM Tom Breloff <[email protected]> wrote: > I'm trying to understand if this is a feature or a bug. After "using A", > if I immediately define "f(x::Float64)" then it silently masks the exported > method A.f(x). However if I call f(0) before trying to redefine it, then I > get a nice error. I feel like either: > > 1. The error is incorrect and f(x::Float64) should mask A.f(x) > 2. Implicitly masking A.f(x) with f(x::Float64) should *always* produce > an error > > If #1 is true and it's correct to mask A's definition, then it would be > nice to have a warning like: "WARN: A.f is now masked by Main.f. Call A.f > explicitly to access it." > > Thoughts? > > > _ > _ _ _(_)_ | A fresh approach to technical computing > (_) | (_) (_) | Documentation: http://docs.julialang.org > _ _ _| |_ __ _ | Type "help()" for help. > | | | | | | |/ _` | | > | | |_| | | | (_| | | Version 0.4.0-dev+4311 (2015-04-17 03:14 UTC) > _/ |\__'_|_|_|\__'_| | Commit 58cef56 (15 days old master) > |__/ | x86_64-redhat-linux > > julia> module A > export f > f(x) = 999 > end > > julia> using A > > julia> f(0) > 999 > > julia> f(x::Float64) = 0 > ERROR: error in method definition: function A.f must be explicitly > imported to be extended > > > _ > _ _ _(_)_ | A fresh approach to technical computing > (_) | (_) (_) | Documentation: http://docs.julialang.org > _ _ _| |_ __ _ | Type "help()" for help. > | | | | | | |/ _` | | > | | |_| | | | (_| | | Version 0.4.0-dev+4311 (2015-04-17 03:14 UTC) > _/ |\__'_|_|_|\__'_| | Commit 58cef56 (15 days old master) > |__/ | x86_64-redhat-linux > > julia> module A > export f > f(x) = 999 > end > > julia> using A > > julia> f(x::Float64) = 0 > f (generic function with 1 method) > > > >
