Having trouble using types defined in extension modules?

My setup is on Julia 1.9 I have a package Foo, it has an extension module FooBarExt, and in that I define a type MyFooBarType.

Then from another module I want to do:

using Foo, Bar
foo(::MyFooBarType) = ...

But I can’t figure out how to access MyFooBarType in a method definition in a compiled module. I’ve tried these

foo(::Base.get_extension(Foo,:FooBarExt).MyFooBarType) = ...
@init @eval foo(::Base.get_extension(Foo,:FooBarExt).MyFooBarType) = ...

but in both cases Base.get_extension(Foo,:FooBarExt) returns nothing, I guess extension modules are loaded later? If this were a function intead of a type, I could just create a stub function foo end in Foo and use it anywhere, but I don’t know how to do this with a type. Any suggestions?

I guess move the type definition from FooBarExt into Foo?

technically because your last package depends on both Foo and Bar Julia should somehow know for sure FooBarExt will be loaded but it doesn’t due to either design or implementation flaw? I think there may be some lazy or eager loading going on

1 Like

Yea I thought about this but the type definition needs types from Bar so I can’t do that.

1 Like

Presumably you’d want this type to be accessible in a module which uses both Foo and Bar, but if so where would the definition come from? It would be strange for a definition from some package you didn’t actually import in any way to appear in your module. You could potentially make a parametric type.

I don’t need it to look exactly like foo(::MyFooBarType) sorry if that was confusing. I just can’t figure out any way to get at that type, including using Base.get_extension.

I think this should be fixed by Revert "delay loading of extensions as much as possible (#48674)" by KristofferC · Pull Request #49257 · JuliaLang/julia · GitHub (see the added tests).