Skip to content

fix #44239, regression in keyword args in getindex #44246

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

Merged
merged 1 commit into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
;; inside ref only replace within the first argument
(list* 'ref (replace-beginend (cadr ex) a n tuples last)
(cddr ex)))
;; TODO: this probably should not be allowed since keyword args aren't
;; positional, but in this context we have just used their positions anyway
((eq? (car ex) 'kw)
(list 'kw (cadr ex) (replace-beginend (caddr ex) a n tuples last)))
(else
(cons (car ex)
(map (lambda (x) (replace-beginend x a n tuples last))
Expand All @@ -142,16 +146,20 @@
(idx (if (vararg? idx0) (cadr idx0) idx0))
(last (null? (cdr lst)))
(replaced (replace-beginend idx a n tuples last))
(idx (if (or (not has-va?) (simple-atom? replaced)) replaced (make-ssavalue))))
(val (if (kwarg? replaced) (caddr replaced) replaced))
(idx (if (or (not has-va?) (simple-atom? val))
val (make-ssavalue))))
(loop (cdr lst) (+ n 1)
(if (eq? idx replaced)
(if (eq? idx val)
stmts
(cons `(= ,idx ,replaced)
(cons `(= ,idx ,val)
stmts))
(if (vararg? idx0) (cons idx tuples) tuples)
(cons (if (vararg? idx0)
`(... ,idx)
idx)
(if (eq? val replaced)
idx
(list 'kw (cadr replaced) idx)))
ret)))))))

;; GF method does not need to keep decl expressions on lambda args
Expand Down
11 changes: 11 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,17 @@ let a = [], b = [4,3,2,1]
@test a == [1,2]
end

# issue #44239
struct KWGetindex end
Base.getindex(::KWGetindex, args...; kws...) = (args, NamedTuple(kws))
let A = KWGetindex(), a = [], b = [4,3,2,1]
f() = (push!(a, 1); 2)
g() = (push!(a, 2); ())
@test A[f(), g()..., k = f()] === ((2,), (k = 2,))
@test a == [1, 2, 1]
@test A[var"end"=1] === ((), (var"end" = 1,))
end

@testset "raw_str macro" begin
@test raw"$" == "\$"
@test raw"\n" == "\\n"
Expand Down