Skip to content

Commit

Permalink
fix #45171, keyword sorter location should just be definition line
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 5, 2022
1 parent 902a5c1 commit 810cb8c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@
,(method-def-expr-
name positional-sparams pargl-all
`(block
,@(without-generated prologue)
,@(keep-first linenum? (without-generated prologue))
,(let (;; call mangled(vals..., [rest_kw,] pargs..., [vararg]...)
(ret `(return (call ,mangled
,@(if ordered-defaults keynames vals)
Expand All @@ -562,7 +562,7 @@
,(if (any kwarg? pargl) (gensy) UNUSED)
(call (core kwftype) ,ftype)) ,kw ,@pargl ,@vararg)
`(block
,@(filter linenum? prologue)
,@(keep-first linenum? prologue)
;; nospecialize meta for just positional args
,@(map (lambda (m)
`(meta ,(cadr m) ,@(filter (lambda (v) (not (memq v keynames)))
Expand Down
8 changes: 8 additions & 0 deletions src/utils.scm
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,11 @@
(begin (put! tbl (car xs) i)
(loop (cdr xs) (+ i 1)))))
tbl))

;; keep at most the first element matching a given predicate
(define (keep-first pred lst)
(cond ((null? lst) lst)
((pred (car lst))
(cons (car lst) (filter (lambda (x) (not (pred x))) (cdr lst))))
(else
(cons (car lst) (keep-first pred (cdr lst))))))
13 changes: 13 additions & 0 deletions test/backtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ let trace = try
@test trace[1].line == 2
end

# issue #45171
linenum = @__LINE__; function f45171(;kwarg = true)
1
error()
end
let trace = try
f45171()
catch
stacktrace(catch_backtrace())
end
@test trace[3].line == linenum
end

# issue #29695 (see also test for #28442)
let code = """
f29695(c) = g29695(c)
Expand Down

0 comments on commit 810cb8c

Please sign in to comment.