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

Syntax error when using @NamedTuple types inside resumable function #104

Open
lgoettgens opened this issue Sep 13, 2024 · 4 comments
Open

Comments

@lgoettgens
Copy link

Describe the problem

One cannot use the @NamedTuple syntax (introduced in julia 1.5) inside a @resumable function, if one of the keys of the named tuple is also present as a local variable of that function.
I expect the @NamedTuple{foo::Int64} syntax in the mwe below to be equivalent to replacing it by Base.NamedTuple{(:foo,), Base.Tuple{Int64}}. However, the latter works as expected, but the former throws ERROR: syntax: invalid named tuple field name "_fsmi.foo" around REPL[26]:2.

Minimal Working Example

@resumable function bar()
   vec = (foo = 3,)::@NamedTuple{foo::Int64}
  foo = "unused"
  @yield vec
end
@resumable function bar2()
  vec = @NamedTuple{foo::Int64}((foo = 3,))
  foo = "unused"
  @yield vec
end

Package versions

Please provide the versions you use. To do this, run the code:

julia> Pkg.status(["ResumableFunctions"]; mode = PKGMODE_MANIFEST)
Status `/tmp/jl_MokoyF/Manifest.toml`
  [c5292f4c] ResumableFunctions v0.6.10
@thofma
Copy link
Collaborator

thofma commented Sep 13, 2024

Can you try with #100?

@lgoettgens

This comment was marked as outdated.

@lgoettgens
Copy link
Author

Correcting my previous message:
The mwe from the initial message works with #100.
But if one reorders the lines (the local var foo gets now created before using foo as a key in @NamedTuple), there is an error when trying to execute the function (see below).

julia> @resumable function bar()
  foo = "unused"
  vec = (foo = 3,)::@NamedTuple{foo::Int64}
  @yield vec
end

julia> @resumable function bar2()
  foo = "unused"
  vec = @NamedTuple{foo::Int64}((foo = 3,))
  @yield vec
end

julia> collect(bar())
ERROR: TypeError: in Type, in parameter, expected Type, got a value of type Tuple{Expr}
Stacktrace:
 [1] ##bar_FSMI#230
   @ ~/.julia/packages/ResumableFunctions/IOa5O/src/macro.jl:3 [inlined]
 [2] ##bar_FSMI#230
   @ ~/.julia/packages/ResumableFunctions/IOa5O/src/macro.jl:166 [inlined]
 [3] iterate (repeats 2 times)
   @ ~/.julia/packages/ResumableFunctions/IOa5O/src/types.jl:24 [inlined]
 [4] _collect(cont::UnitRange{Int64}, itr::var"##bar_FSMI#230"{Union{}, String}, ::Base.HasEltype, isz::Base.SizeUnknown)
   @ Base ./array.jl:770
 [5] collect(itr::var"##bar_FSMI#230"{Union{}, String})
   @ Base ./array.jl:759
 [6] top-level scope
   @ REPL[8]:1

@thofma
Copy link
Collaborator

thofma commented Sep 13, 2024

It is basically the same as #54. I have some local branch for better macro support, but it requires #100.

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

2 participants