- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.7k
 
Description
Running into some #17057 complexity on latest master, where depending on the position in the source file / precompilation is on or off, a generated function selects a different method to call.
Foo/src/Foo.jl:
__precompile__()
module Foo
type Original end
endBar/src/Bar.jl:
__precompile__()
module Bar
using Foo
transform{T}(::Type{T}) = T
@generated function test()
    return transform(Foo.Original)
end
immutable Transformed end
transform(::Type{Foo.Original}) = Transformed
endtest.jl:
using Bar
@show Bar.test()If I run this code as-is, I get the expected (to me) behaviour of the Original type getting transformed to Transformed:
$ JULIA_LOAD_PATH=. JULIA_PKGDIR=. julia test.jl
Bar.test() = Bar.TransformedHowever, if I disable precompilation, it matches the first definition of transform:
$ JULIA_LOAD_PATH=. JULIA_PKGDIR=. julia --compilecache=no test.jl
Bar.test() = Foo.OriginalThis is further exemplified by removing the first transform definition:
$ JULIA_LOAD_PATH=. JULIA_PKGDIR=. julia --compilecache=no test.jl
ERROR: LoadError: MethodError: no method matching transform(::Type{Foo.Original})
The applicable method may be too new: running in world age 20564, while current world is 20566.
Closest candidates are:
  transform(::Type{Foo.Original}) at Bar/src/Bar.jl:14 (method too new to be called from this world context.)
Stacktrace:
 [1] test(...) at Bar/src/Bar.jl:10
 [2] include_from_node1(::String) at ./loading.jl:532
 [3] include(::String) at ./sysimg.jl:14
 [4] process_options(::Base.JLOptions) at ./client.jl:308
 [5] _start() at ./client.jl:374
while loading test.jl, in expression starting on line 229This error does not show if I run with precompilation enabled. Furthermore, if I move the @generated function test below the additional definition of transform the issue disappears.
Also, on 0.5 everything works 'as expected' (ie. Transformed is returned in all cases, without errors)