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

@set expression parsing issue with Unicode operators in compound assignment #184

Closed
DaniGlez opened this issue Dec 17, 2024 · 1 comment
Closed

Comments

@DaniGlez
Copy link

Hi, I think this is supposed to work but errors out instead on 0.1.39

julia> using Accessors

julia> foo(x) = (@set x[1] ⊻= x[2])
ERROR: LoadError: StringIndexError: invalid index [3], valid nearby indices [1]=>'⊻', [4]=>'='
Stacktrace:
 [1] string_index_err(s::String, i::Int64)
   @ Base ./strings/string.jl:12
 [2] getindex
   @ ./strings/string.jl:502 [inlined]
 [3] get_update_op(sym::Symbol)
   @ Accessors ~/.julia/packages/Accessors/p8I9Z/src/sugar.jl:283
 [4] setmacro(optictransform::Function, ex::Expr; overwrite::Bool)
   @ Accessors ~/.julia/packages/Accessors/p8I9Z/src/sugar.jl:318
 [5] var"@set"(__source__::LineNumberNode, __module__::Module, ex::Any)
   @ Accessors ~/.julia/packages/Accessors/p8I9Z/src/sugar.jl:33
in expression starting at REPL[37]:1

whereas these seem to work flawlessly:

julia> foo(x) = (@set x[1] += x[2])
foo (generic function with 1 method)

julia> foo(x) = (@set x[1] = x[1]  x[2])
foo (generic function with 1 method)
@aplavin
Copy link
Member

aplavin commented Dec 17, 2024

Nice catch! This line

Symbol(s[1:end-1])

should probably use chop() instead of end-1 indexing.

@jw3126 jw3126 closed this as completed in a51071a Dec 22, 2024
jw3126 added a commit that referenced this issue Dec 22, 2024
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