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

UndefVarError: .+ not defined on @code_lowered 1 .+ 1 #45889

Closed
goretkin opened this issue Jul 1, 2022 · 1 comment · Fixed by #45894
Closed

UndefVarError: .+ not defined on @code_lowered 1 .+ 1 #45889

goretkin opened this issue Jul 1, 2022 · 1 comment · Fixed by #45894

Comments

@goretkin
Copy link
Contributor

goretkin commented Jul 1, 2022

julia> versioninfo()
Julia Version 1.6.2
Commit 1b93d53fc4 (2021-07-14 15:36 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = vscode

julia> @code_lowered sin.(3)
CodeInfo(
1%1 = Base.broadcasted(Main.sin, x1)
│   %2 = Base.materialize(%1)
└──      return %2
)

julia> @code_lowered 1 .+ 1
ERROR: UndefVarError: .+ not defined
Stacktrace:
 [1] top-level scope
   @ /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/InteractiveUtils/src/macros.jl:230

It also happens on Julia v1.6

By the way,

julia> @macroexpand (@code_lowered 1 .+ 1)
quote
    #= /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/InteractiveUtils/src/macros.jl:230 =#
    local var"#30#results" = InteractiveUtils.code_lowered(.+, (Base.typesof)(1, 1))
    #= /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/InteractiveUtils/src/macros.jl:231 =#
    if InteractiveUtils.length(var"#30#results") == 1
        var"#30#results"[1]
    else
        var"#30#results"
    end
end

I don't understand how the error arises. InteractiveUtils.code_lowered(.+, (Base.typesof)(1, 1)) evaluates correctly in the scope of the macro invocation.

@Liozou
Copy link
Member

Liozou commented Jul 1, 2022

Sorry about that, it was overlooked in #35522 because the issue only occurs when using a dot symbol on arguments that are not lowered to Expr, which I did not think of. Fix is up at #45894.

The reason why the error arises while the explicit call works is that, in the macro, .+ is lowered to a symbol, i.e. Symbol(".+") while in the explicit call you tried, it is transformed into Expr(:., :+). You can see it by comparing dump(@macroexpand @code_warntype 1 .+ 3) to dump(:(InteractiveUtils.code_warntype(.+, (Base.typesof)(1, 3)))).

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

Successfully merging a pull request may close this issue.

2 participants