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

::Type{T}=Float64 argument breaks hygiene? #42220

Closed
phipsgabler opened this issue Sep 12, 2021 · 0 comments
Closed

::Type{T}=Float64 argument breaks hygiene? #42220

phipsgabler opened this issue Sep 12, 2021 · 0 comments

Comments

@phipsgabler
Copy link
Contributor

phipsgabler commented Sep 12, 2021

If this is not a misinterpretation on my side, I find the following a bit shocking:

julia> macro test1()
           return quote
               function foo(::Type{T}=Float64) where {T}
                   return Vector{T}(undef, 10)
               end
           end
       end
@test1 (macro with 1 method)

julia> @test1()
ERROR: syntax: malformed expression
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

julia> function foo(::Type{T}=Float64) where {T}
           return Vector{T}(undef, 10)
       end
foo (generic function with 2 methods)

julia> foo()
10-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0

julia> versioninfo()
Julia Version 1.6.2
Commit 1b93d53fc4 (2021-07-14 15:36 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)

Over on Zulip, someone suggested to uncomment some debug printing in jlfrontend.scm -- the top of the Lisp stack trace you get is (for a different example macro with variable TV, though):

(type-error car cons ())
unexpected error: #0 (caddr (:: (curly Type TV)))
#1 (resolve-expansion-vars-
 (kw (:: (curly Type TV)) (curly Vector Float64))
 ((n . |#118#n|) (|#unused#| . |#119##unused#|) (TV . |#120#TV|))
 #<julia: DynamicPPL> () #t)

But I'm unable to interpret that. (Here's the full example, run on the phg/unescape branch of Turing.jl.)

KristofferC pushed a commit that referenced this issue Sep 15, 2021
KristofferC pushed a commit that referenced this issue Oct 29, 2021
KristofferC pushed a commit that referenced this issue Nov 11, 2021
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Feb 22, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Mar 8, 2022
staticfloat pushed a commit that referenced this issue Dec 23, 2022
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