Skip to content

@SVector & @MVector fail when their inputs use non global scope variables #1014

@dpinol

Description

@dpinol

This works

       tmp=[1,2]
       @SVector [1 for i in 1:length(tmp)]

but this does not work

function g()
       tmp2=[1,2]
       @SVector [1 for i in 1:length(tmp2)]
end
g()

ERROR: LoadError: UndefVarError: tmp2 not defined
Stacktrace:
 [1] top-level scope
   @ none:1
 [2] eval(m::Module, e::Any)
   @ Core ./boot.jl:368
 [3] var"@SVector"(__source__::LineNumberNode, __module__::Module, ex::Any)
   @ StaticArrays ~/.julia/packages/StaticArrays/0bweZ/src/SVector.jl:60
in expression starting at REPL[2]:3

The problem is the following line in the macros will not access non global scope variables.

rng = Core.eval(__module__, ex.args[2].args[2])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions