Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] register does not work with the module being used as alias #654

Open
kunzaatko opened this issue Jun 3, 2023 · 0 comments
Open

[bug] register does not work with the module being used as alias #654

kunzaatko opened this issue Jun 3, 2023 · 0 comments

Comments

@kunzaatko
Copy link

When using

Unitful.register(@__MODULE__)

the registered units, are linked to the module instead of the identifier. For this reason, the @u_str macro does not work when the module is imported with as.

MWE

With the module

module MM
using Unitful

function __init__()
    Unitful.register(@__MODULE__)
end

@unit px "px" Pixel 36u"nm" false
end

and in the REPL

In [1]: using MM: MM as M

In [2]: using Unitful

In [3]: u"px"
ERROR: LoadError: ArgumentError: Symbol `px` was found in the globally registered unit module MM
but was not in the provided list of unit modules Unitful.

(Consider `using MM` in your module if you are using `@u_str`?)
Stacktrace:
 [1] lookup_units(unitmods::Vector{Module}, sym::Symbol)
   @ Unitful ~/.julia/packages/Unitful/orvol/src/user.jl:701
 [2] var"@u_str"(__source__::LineNumberNode, __module__::Module, unit::Any)
   @ Unitful ~/.julia/packages/Unitful/orvol/src/user.jl:639
in expression starting at REPL[3]:1

but when you import it using the name where it is registered, it works as normal

 In [4]: using MM

 In [5]: u"px"
 > px
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant